Linux Input/HID development
 help / color / mirror / Atom feed
* Re: [PATCH] Input: wacom - cleanup multitouch code when touch_max is 2
From: Jason Gerecke @ 2014-06-04 21:44 UTC (permalink / raw)
  To: Ping Cheng; +Cc: Linux Input, Dmitry Torokhov, Ping Cheng
In-Reply-To: <1401393791-15614-1-git-send-email-pingc@wacom.com>

On Thu, May 29, 2014 at 1:03 PM, Ping Cheng <pinglinux@gmail.com> wrote:
> Historically we dealt with touch_max equals to 2 differently from
> other MT devices. Now we use input_mt_*() to process all MT events,
> as long as touch_max is greater than 1. So, there is no need to
> take (touch_max == 2) as a special case any more.
>
> Signed-off-by: Ping Cheng <pingc@wacom.com>
> ---
>  drivers/input/tablet/wacom_wac.c | 26 ++++++--------------------
>  1 file changed, 6 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
> index 977d05c..964db47 100644
> --- a/drivers/input/tablet/wacom_wac.c
> +++ b/drivers/input/tablet/wacom_wac.c
> @@ -1217,8 +1217,8 @@ static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
>                          * a=(pi*r^2)/C.
>                          */
>                         int a = data[5];
> -                       int x_res  = input_abs_get_res(input, ABS_X);
> -                       int y_res  = input_abs_get_res(input, ABS_Y);
> +                       int x_res  = input_abs_get_res(input, ABS_MT_POSITION_X);
> +                       int y_res  = input_abs_get_res(input, ABS_MT_POSITION_Y);
>                         width  = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
>                         height = width * y_res / x_res;
>                 }
> @@ -1587,7 +1587,7 @@ static void wacom_abs_set_axis(struct input_dev *input_dev,
>                 input_abs_set_res(input_dev, ABS_X, features->x_resolution);
>                 input_abs_set_res(input_dev, ABS_Y, features->y_resolution);
>         } else {
> -               if (features->touch_max <= 2) {
> +               if (features->touch_max == 1) {
>                         input_set_abs_params(input_dev, ABS_X, 0,
>                                 features->x_max, features->x_fuzz, 0);
>                         input_set_abs_params(input_dev, ABS_Y, 0,
> @@ -1815,14 +1815,8 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
>         case MTTPC:
>         case MTTPC_B:
>         case TABLETPC2FG:
> -               if (features->device_type == BTN_TOOL_FINGER) {
> -                       unsigned int flags = INPUT_MT_DIRECT;
> -
> -                       if (wacom_wac->features.type == TABLETPC2FG)
> -                               flags = 0;
> -
> -                       input_mt_init_slots(input_dev, features->touch_max, flags);
> -               }
> +               if ((features->device_type == BTN_TOOL_FINGER) && features->touch_max > 1)
> +                       input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_DIRECT);
>                 /* fall through */
>
>         case TABLETPC:
> @@ -1883,10 +1877,6 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
>                         __set_bit(BTN_RIGHT, input_dev->keybit);
>
>                         if (features->touch_max) {
> -                               /* touch interface */
> -                               unsigned int flags = INPUT_MT_POINTER;
> -
> -                               __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
>                                 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
>                                         input_set_abs_params(input_dev,
>                                                      ABS_MT_TOUCH_MAJOR,
> @@ -1894,12 +1884,8 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
>                                         input_set_abs_params(input_dev,
>                                                      ABS_MT_TOUCH_MINOR,
>                                                      0, features->y_max, 0, 0);
> -                               } else {
> -                                       __set_bit(BTN_TOOL_FINGER, input_dev->keybit);
> -                                       __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
> -                                       flags = 0;
>                                 }
> -                               input_mt_init_slots(input_dev, features->touch_max, flags);
> +                               input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);

I think you want to use 'input_mt_init_slots(input_dev,
features->touch_max + 1, INPUT_MT_POINTER)' instead. This is one more
slot than necessary, but the number of slots is used in deciding which
of the BTN_TOOL_*TAP buttons the kernel will advertise. Our protocol
has the driver sending one more TAP than expected to differentiate
touch and pad (e.g. single-touch device needs DOUBLETAP and two-finger
touch needs TRIPLETAP). Adding one to the number of slots ensures a
high enough TAP is advertised.

Aside from that... Reviewed-by: Jason Gerecke <killertofu@gmail.com>

Jason
---
Now instead of four in the eights place /
you’ve got three, ‘Cause you added one  /
(That is to say, eight) to the two,     /
But you can’t take seven from three,    /
So you look at the sixty-fours....

>                         } else {
>                                 /* buttons/keys only interface */
>                                 __clear_bit(ABS_X, input_dev->absbit);
> --
> 1.9.1
>
> --
> 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
--
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: wacom - cleanup multitouch code when touch_max is 2
From: Jason Gerecke @ 2014-06-04 22:59 UTC (permalink / raw)
  To: Ping Cheng; +Cc: Linux Input, Dmitry Torokhov, Ping Cheng
In-Reply-To: <CANRwn3Rdp-tf4j6OTmKys1Cb+eo8MbELpSmw8dZyn7NGEE0EEA@mail.gmail.com>

On Wed, Jun 4, 2014 at 2:44 PM, Jason Gerecke <killertofu@gmail.com> wrote:
> On Thu, May 29, 2014 at 1:03 PM, Ping Cheng <pinglinux@gmail.com> wrote:
>> Historically we dealt with touch_max equals to 2 differently from
>> other MT devices. Now we use input_mt_*() to process all MT events,
>> as long as touch_max is greater than 1. So, there is no need to
>> take (touch_max == 2) as a special case any more.
>>
>> Signed-off-by: Ping Cheng <pingc@wacom.com>
>> ---
>>  drivers/input/tablet/wacom_wac.c | 26 ++++++--------------------
>>  1 file changed, 6 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
>> index 977d05c..964db47 100644
>> --- a/drivers/input/tablet/wacom_wac.c
>> +++ b/drivers/input/tablet/wacom_wac.c
>> @@ -1217,8 +1217,8 @@ static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
>>                          * a=(pi*r^2)/C.
>>                          */
>>                         int a = data[5];
>> -                       int x_res  = input_abs_get_res(input, ABS_X);
>> -                       int y_res  = input_abs_get_res(input, ABS_Y);
>> +                       int x_res  = input_abs_get_res(input, ABS_MT_POSITION_X);
>> +                       int y_res  = input_abs_get_res(input, ABS_MT_POSITION_Y);
>>                         width  = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
>>                         height = width * y_res / x_res;
>>                 }
>> @@ -1587,7 +1587,7 @@ static void wacom_abs_set_axis(struct input_dev *input_dev,
>>                 input_abs_set_res(input_dev, ABS_X, features->x_resolution);
>>                 input_abs_set_res(input_dev, ABS_Y, features->y_resolution);
>>         } else {
>> -               if (features->touch_max <= 2) {
>> +               if (features->touch_max == 1) {
>>                         input_set_abs_params(input_dev, ABS_X, 0,
>>                                 features->x_max, features->x_fuzz, 0);
>>                         input_set_abs_params(input_dev, ABS_Y, 0,
>> @@ -1815,14 +1815,8 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
>>         case MTTPC:
>>         case MTTPC_B:
>>         case TABLETPC2FG:
>> -               if (features->device_type == BTN_TOOL_FINGER) {
>> -                       unsigned int flags = INPUT_MT_DIRECT;
>> -
>> -                       if (wacom_wac->features.type == TABLETPC2FG)
>> -                               flags = 0;
>> -
>> -                       input_mt_init_slots(input_dev, features->touch_max, flags);
>> -               }
>> +               if ((features->device_type == BTN_TOOL_FINGER) && features->touch_max > 1)
>> +                       input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_DIRECT);
>>                 /* fall through */
>>
>>         case TABLETPC:
>> @@ -1883,10 +1877,6 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
>>                         __set_bit(BTN_RIGHT, input_dev->keybit);
>>
>>                         if (features->touch_max) {
>> -                               /* touch interface */
>> -                               unsigned int flags = INPUT_MT_POINTER;
>> -
>> -                               __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
>>                                 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
>>                                         input_set_abs_params(input_dev,
>>                                                      ABS_MT_TOUCH_MAJOR,
>> @@ -1894,12 +1884,8 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
>>                                         input_set_abs_params(input_dev,
>>                                                      ABS_MT_TOUCH_MINOR,
>>                                                      0, features->y_max, 0, 0);
>> -                               } else {
>> -                                       __set_bit(BTN_TOOL_FINGER, input_dev->keybit);
>> -                                       __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
>> -                                       flags = 0;
>>                                 }
>> -                               input_mt_init_slots(input_dev, features->touch_max, flags);
>> +                               input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
>
> I think you want to use 'input_mt_init_slots(input_dev,
> features->touch_max + 1, INPUT_MT_POINTER)' instead. This is one more
> slot than necessary, but the number of slots is used in deciding which
> of the BTN_TOOL_*TAP buttons the kernel will advertise. Our protocol
> has the driver sending one more TAP than expected to differentiate
> touch and pad (e.g. single-touch device needs DOUBLETAP and two-finger
> touch needs TRIPLETAP). Adding one to the number of slots ensures a
> high enough TAP is advertised.
>
> Aside from that... Reviewed-by: Jason Gerecke <killertofu@gmail.com>
>
> Jason
> ---
> Now instead of four in the eights place /
> you’ve got three, ‘Cause you added one  /
> (That is to say, eight) to the two,     /
> But you can’t take seven from three,    /
> So you look at the sixty-fours....
>
>>                         } else {
>>                                 /* buttons/keys only interface */
>>                                 __clear_bit(ABS_X, input_dev->absbit);
>> --
>> 1.9.1
>>

Ping has explained things to me in a bit more detail, and my
reservations have been calmed. We used to use TAP+1 hack to
differentiate PAD and touch in the days before the MT protocol. We
don't rely on that behavior at all when ABS_MT_* events are used,
which is the case with the BAMBOO_PT and INTUOS_HT devices that this
would effect. Therefore, without qualification...

Reviewed-by: Jason Gerecke <killertofu@gmail.com>

Jason
---
Now instead of four in the eights place /
you’ve got three, ‘Cause you added one  /
(That is to say, eight) to the two,     /
But you can’t take seven from three,    /
So you look at the sixty-fours....
--
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

* ThinkPad X300 touchpad
From: Bitai Tamás @ 2014-06-05 13:36 UTC (permalink / raw)
  To: linux-input

Dear kernel Developers,

I am trying to get working the touchpad of my ThinkPad X300. Googling
for "thinkpad x300 touchpad alps" gives a number of results from
forums.lenovo.com where people state it is an ALPS touchpad.

I use Arch Linux, kernel version 3.14.4-1, and it is recognized as
PS/2 Generic Mouse.

I have tried everything I found on forums with a reasonable research
effort, without success.

Interestingly, however, at some point (unfortunately, I don't remember
which setup it was with, but I am pretty sure it was when I tried the
patch available at https://github.com/he1per/psmouse-dkms-alpsv7) I
managed to recognize the touchpad as PS/2 ALPS DualPoint Touchpad, or
something similar (unfortunately I didn't take a note of it), then I
changed things in my 50-synaptics.conf, rebooted, and the touchpad was
detected as PS/2 Generic Mouse again! As far as I understand things,
this shouldn't happen!

I saw others reporting that the touchpad works for them under Linux --
for example, here:

https://github.com/tsgates/arch-wiki-markdown/blob/master/wiki/Lenovo_Thinkpad_X300.md

So, I guess there must be a solution, and I would be so happy if you
guys could help me finding it.

Thank you in advance,

Tamás
--
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

* [PATCH] HID: usbhid: remove unneeded initialization of quirks_param[]
From: Mathias Krause @ 2014-06-05 19:20 UTC (permalink / raw)
  To: Jiri Kosina; +Cc: linux-usb, linux-input, Mathias Krause

The quirks_param array is located in the BSS, no need to explicitly
initialize it with NULL.

Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 drivers/hid/usbhid/hid-core.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 7b88f4cb99..37d2a95c5a 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -58,7 +58,7 @@ module_param_named(ignoreled, ignoreled, uint, 0644);
 MODULE_PARM_DESC(ignoreled, "Autosuspend with active leds");
 
 /* Quirks specified at module load time */
-static char *quirks_param[MAX_USBHID_BOOT_QUIRKS] = { [ 0 ... (MAX_USBHID_BOOT_QUIRKS - 1) ] = NULL };
+static char *quirks_param[MAX_USBHID_BOOT_QUIRKS];
 module_param_array_named(quirks, quirks_param, charp, NULL, 0444);
 MODULE_PARM_DESC(quirks, "Add/modify USB HID quirks by specifying "
 		" quirks=vendorID:productID:quirks"
-- 
1.7.10.4


^ permalink raw reply related

* (unknown)
From: 孟经理 @ 2014-06-05 19:52 UTC (permalink / raw)
  To: secolo

      
      
      
      
      

	      С¶ÀͶ¯ºÏͬ·¨¡·¡¢¡¶Éç»á±£ÏÕ·¨¡·¡¢¡¶¹¤É˱£ÏÕ
ÌõÀý¡·Êµ²ÙÓ¦¶Ô²ßÂÔÓëÓÐЧµ÷¸Úµ÷н¡¢

                      ²ÃÔ±½â¹Í¼°
Î¥¼ÍÎÊÌâÔ±¹¤´¦Àí¼¼ÇÉ¡·===¡¾Ö÷½²£ºÖÓÓÀ馡¿

		

	  ±¨ÃûÏêÇé >	

	¡¾Åàѵʱ¼ä¡¿ 2014Äê6ÔÂ07-08·ðɽ£¨Bµ¥Ôª£©    6ÔÂ13-14±±¾©£¨Aµ¥Ôª£©    6ÔÂ18-19ÉîÛÚ£¨Aµ¥Ôª£©	
   	                  7ÔÂ11-12¹ãÖÝ£¨Bµ¥Ôª£©    7ÔÂ18-19ÉϺ££¨Bµ¥Ôª£©    7ÔÂ25-26±±¾©£¨Bµ¥Ôª£©	
	                  8ÔÂ1-2ÉîÛÚ£¨Bµ¥Ôª£©      8ÔÂ8-9-¹ãÖÝ£¨Aµ¥Ôª£©     8ÔÂ15-16ÉϺ££¨Aµ¥Ôª£©	
	                  8ÔÂ22-23±±¾©£¨Aµ¥Ôª£©    8ÔÂ29-30ÉîÛÚ£¨Aµ¥Ôª£©
	
	 ×¢Ã÷£º¸Ã¿Î³Ì2ÌìΪһ¸öµ¥Ôª£¬Aµ¥ÔªÓëBµ¥ÔªÄÚÈÝÊÇÍêÈ«¶ÀÁ¢µÄ²»·ÖÏȺó˳Ðò£¬¿Í»§¿É¸ù¾Ý×Ô¼ºÐèÇóÑ¡
	
	 Ôñ²Î¼ÓAµ¥Ôª»òÕßBµ¥Ôª£¬»òABµ¥Ôª¾ù²Î¼Ó£¬¿ÉÒԲμÓÍêAµ¥ÔªÔٲμÓBµ¥Ôª»òÕßÏȲμÓBµ¥ÔªÔٲμÓAµ¥Ôª
	
	 ¾ù¿É£¬Aµ¥ÔªÓëBµ¥ÔªÄÚÈÝÇë¿´ÏÂÃæµÄ¿Î³Ì´ó¸Ù£¡£¡£¡	
		
	¡¾Åàѵ¶ÔÏó¡¿ ¶­Ê³¤¡¢×ܾ­Àí¡¢¸±×ܾ­Àí¡¢ÈËÁ¦×ÊÔ´×ܼà/¾­Àí/רԱ¼°ÈËÊÂÐÐÕþ¹ÜÀíÈËÔ±¡¢¹¤»á¸É²¿¡¢
	
	 ·¨ÎñÈËÔ±¼°Ïà¹Ø¹ÜÀíÈËÔ±¡¢Ïà¹ØÂÉʦµÈ¡£	

	¡¾Êڿη½Ê½¡¿ ½²Ê¦½²ÊÚ + ÊÓÆµÑÝÒï + °¸ÀýÑÐÌÖ +½ÇÉ«°çÑÝ + ½²Ê¦µãÆÀ	

	¡¾Åàѵ·ÑÓá¿ ²Î¼ÓAµ¥Ôª£º2800Ôª/1ÈË£¬5000Ôª/2ÈË£»²Î¼ÓBµ¥Ôª£º2800Ôª/1ÈË£¬5000Ôª/2ÈË£¬
	
	            ²Î¼ÓABµ¥Ôª£º5000Ôª/ÈË£¨º¬Ñ§Ï°·Ñ¡¢×ÊÁÏ·Ñ¡¢Îç²Í¡¢²èµã¡¢·¢Æ±£©	

	¡¾³Ð°ìµ¥Î»¡¿Óî  ½ÜÆó ¹Ü	

	¡¾±¨ÃûÈÈÏß¡¿ÉîÛÚ£º0755-61282360 ÉϺ£: 021-51602030 ±±¾©£º010-51669310	

	¡¾QQÔÚÏß¡¿511798337	

	  ¿Î³Ì¼ò½é >	

	¡¾¿Î³Ì±³¾°¡¿	

	¡¡¡¡2008Ä꣬¹ú¼Ò³ǫ̈ÁË¡¶ÀͶ¯ºÏͬ·¨¡·¡¢¡¶ÀͶ¯ºÏͬ·¨ÊµÊ©ÌõÀý¡·¡¢¡¶ÀͶ¯ÕùÒéµ÷½âÖٲ÷¨¡·¡¢¡¶Ö°	
	¹¤´øÐ½ÄêÐݼÙÌõÀý¡·¡¢¡¶ÆóÒµÖ°¹¤´øÐ½ÄêÐݼÙʵʩ°ì·¨¡·£»2009Ä꣬¹ú¼Ò³ǫ̈ÁË¡¶ÀͶ¯ÈËÊÂÕùÒéÖٲðì	
	°¸¹æÔò¡·£»2010Ä꣬¹ú¼Ò³ǫ̈ÁË¡¶ÀͶ¯ÕùÒé˾·¨½âÊÍ£¨Èý£©¡·¼°ÐÞ¸ÄÁË¡¶¹¤É˱£ÏÕÌõÀý¡·£»2011Ä꣬¹ú	
	¼Ò³ǫ̈ÁË¡¶Éç»á±£ÏÕ·¨¡·¼°¡¶ÊµÊ©<Éç»á±£ÏÕ·¨>Èô¸É¹æ¶¨¡·£»2012Ä꣬¹ú¼Ò³ǫ̈ÁË¡¶ÆóÒµÃñÖ÷¹ÜÀí¹æ	
	¶¨¡·¡¢¡¶Å®Ö°¹¤ÀͶ¯±£»¤ÌØ±ð¹æ¶¨¡·¼°ÐÞ¸ÄÁË¡¶Ö°Òµ²¡·ÀÖη¨¡·£»2013Ä꣬¹ú¼Ò³ǫ̈ÁË¡¶ÀͶ¯ÕùÒé˾·¨	
	½âÊÍ£¨ËÄ£©¡·¡¢¡¶ÀÍÎñÅÉDzÈô¸É¹æ¶¨¡·£»2014Äê¡­¡­	
	¡¡¡¡ÉÏÊö·¨ÂÉ·¨¹æÕþ²ßµÄ³ÖÐøÊµÊ©£¬¿Í¹ÛÉÏÒªÇóÆóÒµ¾«´òϸË㣬·ñÔòÎÞ·¨³ÐÊÜÓëÈÕ¾ãÔöµÄÓù¤³É±¾£»¿Í	
	¹ÛÉÏÒªÇóÓÃÈ˵¥Î»×öµ½¡°¾«Ï¸»¯¡±¹ÜÀí£¬·ñÔòÄÑÒÔÖ¤Ã÷ÀͶ¯Õß¡°²»ºÏ¸ñ¡¢²»Ê¤ÈΡ¢ÑÏÖØÊ§Ö°¡¢ÑÏÖØÎ¥¼Í	
	Î¥¹æ¡±£¬Ò²ÄÑÒÔ½øÐкϷ¨ÓÐЧµÄ¡°µ÷¸Úµ÷н¡¢²ÃÔ±½â¹Í¡±¡£Èç¹ûÓÃÈ˵¥Î»ÒÀȻʵʩ¡°´«Í³Ê½¡¢´Ö·Åʽ¡¢	
	Ëæ±ãʽ¡±µÄ¹ÜÀí£¬ÄÇôÓÃÈ˵¥Î»±Ø½«ÃæÁÙ¾Þ´óµÄÓù¤·çÏÕºÍÅâ³¥ÔðÈΣ¬Æä¹ÜÀíȨÍþÒ²½«Êܵ½ÑϾþµÄÌôÕ½£¡	
	¡¡¡¡Îª°ïÖú¹ã´óÆóÊÂÒµµ¥Î»Á˽âÏà¹ØÕþ²ß·¨ÂÉ·¨¹æ£¬ÕÆÎÕ·À·¶Óù¤·çÏպͻ¯½âÀͶ¯ÕùÒéµÄ¼¼Äܼ¼ÇÉ£¬ÒÔ	
	ʵÏֵͷçÏÕ¡¢µÍ³É±¾¡¢¸ß¼¨Ð§µÄÈËÁ¦×ÊÔ´¹ÜÀíÄ¿±ê£¬ÌØÑûÇëÎÒ¹úÖªÃûµÄÀͶ¯·¨ÓëÔ±¹¤¹ØÏµ¹ÜÀíʵսר¼Ò	
	ÖÓÓÀé¦ÀÏʦÖ÷½²´Ë¿Î³Ì¡£»¶Ó­ÆóÊÂÒµµ¥Î»»ý¼«×éÖ¯Ïà¹ØÈËÔ±²Î¼Ó´ËÅàѵ¿Î³Ì£¡	
		
	¡¾¿Î³ÌÌØÉ«¡¿	

	ϡȱÐÔ£º´Ë¿Î³Ì½«ÀͶ¯·¨ÌåϵºÍн³ê¼¨Ð§¹ÜÀíÌåϵ½ôÃÜÏà½áºÏ£¬¹úÄÚ¼«ÉÙ³öÏÖ´ËÀà¿Î³Ì¡£	
	Õë¶ÔÐÔ£º¿Î³ÌÄÚÈݾ«Ñ¡Á˹ýÈ¥5ÄêÀ´Ö÷½²ÀÏʦÇ××Ô´¦Àí¹ýµÄÇÒÔÚ²»ÉÙÓÃÈ˵¥Î»ÄÚ²¿Ò²Ôø·¢Éú¹ýµÄ´ú±íÐÔ°¸	
	Àý£¬ÕâЩ°¸ÀýÍêÈ«·ûºÏÖйúÏֽ׶εĴ󻷾³´óÆøºò£¬¼«¾ß²Î¿¼ÐÔºÍÆô·¢ÐÔ¡£	
	ʵսÐÔ£ºÊµÕ½É³ÅÌÑÝÁ·£¬Ñ§Ô±ÉîÈë˼¿¼Óë³ä·Ö»¥¶¯£¬ÀÏʦºÁ²»±£ÁôÇãÄÒÏàÊÚ£»Ñ§Ô±°Ñ´íÎóÁôÔÚ¿ÎÌ㬰Ñ	
	ÕýÈ·µÄ¹Ûµã¡¢·½·¨¡¢¹¤¾ß¡¢¼¼ÄÜ´ø»ØÈ¥¡£	
		
	¡¾¿Î³ÌÊÕÒæ¡¿	

	1¡¢È«ÃæÁ˽âÀͶ¯Óù¤¹ý³ÌµÄ·¨ÂÉ·çÏÕ£»	
	2¡¢Àí½âÓëÀͶ¯Óù¤ÓйصÄÕþ²ß·¨ÂÉ·¨¹æ£»	
	3¡¢ÅàÑøÔ¤²â¡¢·ÖÎöÀͶ¯Óù¤·¨ÂÉ·çÏÕµÄ˼ά£»	
	4¡¢ÕÆÎÕÔ¤·ÀºÍÓ¦¶Ô·çÏÕµÄʵս¼¼Äܼ°·½·¨¹¤¾ß¡­¡­	
		
	  µ¼Ê¦¼ò½é >¡¾ÖÓÓÀ馡¿	

	×ÊÉîÀͶ¯·¨×¨¼Ò	
		
	¡¾½ÌÓý±³¾°¡¿	

	    ¹úÄÚÖøÃûÀͶ¯·¨ÓëÔ±¹¤¹ØÏµ¹ÜÀíʵսר¼Ò¡¢ÀͶ¯ÖÙ²ÃÔ±¡¢ÆóÒµÀͶ¯ÕùÒéÔ¤·ÀÓ¦¶Ôר¼Ò¡¢¸ß¼¶ÈËÁ¦×Ê	
	Ô´¹ÜÀíʦ¡¢¸ß¼¶ÀͶ¯¹ØÏµÐ­µ÷ʦ£¬¹úÄÚµÚÒ»Åú³«µ¼¡¢´«²¥¡¢ÊµÊ©¡°¹ú¼ÒÀͶ¯·¨ÓëÆóҵн³ê¼¨Ð§ÓлúÕûºÏ¡±	
	µÄÏÈÐÐÕߣ»¹úÄÚÔ­´´ÐÍ¡¢ÊµÕ½ÐÍ¡¢¹ËÎÊÐ͵ÄÅàѵʦ¡£	
	¡¡¡¡ÏÖÈΡ°ÀÍÂÉͨ(Öйú)¹ËÎÊÖÐÐÄ¡±¡¢Öлª´´ÊÀ¼ÍÅàÑµÍøÊ×ϯ¹ËÎÊ£¬ÉϺ£³ÉͨÂÉʦÊÂÎñËùͶ×ʺϻïÈË£»	
	¼æÈÎʱ´ú¹â»ª¹ÜÀíѧԺ¡¢ÉîÛÚÍâÉÌͶ×ÊÆóҵЭ»á¡¢¹ãÖÝÊÐÀͶ¯±£ÕÏѧ»á¡¢¹ãÖÝÊÐÈËÁ¦×ÊÔ´Êг¡·þÎñÖÐÐÄ¡¢	
	¹ã¶«Ê¡ÈËÁ¦×ÊÔ´¹ÜÀíЭ»á¡¢Ïã¸Û¹¤Òµ×ܻᡢÖÐɽ´óѧ¡¢Õã½­´óѧµÈ100¶à¼ÒÅàѵ¹«Ë¾¡¢ÐÐҵЭ»á¡¢ÓйØ	
	»ú¹¹µÄǩԼ½²Ê¦¡¢ÌØÆ¸¹ËÎÊ¡£	
		
	¡¾½²Ê¦É󤡿	

	    ÖÓÀÏʦ¾«Í¨ÀͶ¯Õþ²ß·¨ÂÉ·¨¹æºÍÀͶ¯Öٲá¢ËßËϳÌÐò£¬Éó¤ÀͶ¯Óù¤·çÏÕµÄÓÐЧԤ·ÀÓëÀͶ¯ÕùÒé°¸	
	¼þµÄ¾«×¼Ó¦¶Ô£¬ÉÆÓÚ°ÑÀͶ¯·¨ÂÉ·¨¹æÓëÆóÒµÈËÁ¦×ÊÔ´¹ÜÀíÓлúÕûºÏ£¬Í¨ÏþÆóÒµÀͶ¯ÕùÒé·À·¶»úÖÆµÄ¹¹½¨	
	ºÍÀͶ¯Óù¤¹ÜÀíÌåϵµÄÐÞÕýÍêÉÆ¡£ÖÓÀÏʦ¾­³£ÔÚ¿Í»§°ì¹«ÏÖ³¡¡¢ÅàѵÏÖ³¡Îª¿Í»§¡¢Ñ§Ô±¼´Ê±Æð²Ý¡¢Éó²é¡¢	
	ÐÞ¸ÄÏà¹ØÖÆ¶È¡¢ºÏͬ¡¢ÎÄÊ飬»ò·ÖÎö¾ßÌå°¸¼þµÄÓ¦¶Ô˼·£»ÖÓÀÏʦ¶Àµ½µÄÏÖ³¡µÄרҵ¹¦µ×£¬Ã¿´Î¶¼Ó®µÃ	
	¹ã´ó¿Í»§¡¢Ñ§Ô±·¢×ÔÄÚÐÄµÄºÃÆÀÓë100%µÄÐÅ·þ£¡	
		
	¡¾½²Ê¦¾­Àú¡¿	

	    ÖÓÀÏÊ¦ÔøÈÎרְÀͶ¯ÖÙ²ÃÔ±£¬Ôø»ñ¡°¹ãÖÝÊÐÓÅÐãÀͶ¯ÖÙ²ÃÔ±¡±³ÆºÅ£¬ÆÚ¼äÉó²ÃÀͶ¯ÕùÒé°¸¼þ400¶à	
	×Ú£»¶àÄêÀ´ÀÛ»ý´úÀíÀͶ¯ÕùÒé500¶à×Ú£¬²ÎÓë»òÖ÷³Öн³ê¼¨Ð§×ÉѯÏîÄ¿20¶à¸ö£¬Éó²éÍêÉÆ400¶à¼ÒÆóÒµµÄ	
	ÈËÁ¦×ÊÔ´¹ÜÀí¹æÕÂÖÆ¶È¡£¸öÈ˳¤ÆÚµ£ÈÎ30¶à¼Ò£¨ÀÛ¼Æ200¶à¼Ò£©ÆóÒµµÄÈËÁ¦×ÊÔ´¹ÜÀí·¨ÂɹËÎÊ£»ÒÔÖÓÀÏʦ	
	ÁìÏεÄר¼Ò¶ÓÎ飬³¤ÆÚΪÆóÊÂÒµµ¥Î»ÌṩÀͶ¯·¨³£Äê¹ËÎʼ°¸÷ÖÖÀÍ×ÊרÏî×Éѯ·þÎñ£¬¿Í»§ÂúÒâ¶È¸ß´ï95%¡£	
	    2004Ä꿪ʼÖÓÀÏʦȫ¹ú¸÷µØÑ²½²ÀͶ¯·¨¡¢ÀͶ¯¹ØÏµ¿Î³Ì£¬ÊÜÒæÆóÒµ´ï30000¼Ò£¬Ö±½ÓÊÜÒæÑ§Ô±70000	
	¶àÈË£¬ÅàѵµØµãÉæ¼°20¶à¸öÊ¡»á³ÇÊм°Ñغ£µØÇø´ó³ÇÊС£ÖÓÀÏʦ½«¿ÝÔïµÄÀͶ¯Õþ²ß·¨¹æÈÜÈëʵ¼Ê¹ÜÀí°¸	
	Àýµ±ÖУ¬½«ÈËÁ¦×ÊÔ´¹ÜÀíÓëÀͶ¯·¨ÓлúµØÕûºÏÔÚÒ»Æð£»¿Î³ÌÄÚÈÝ80%ÎªÕæÊµ°¸Àý¡¢20%Ϊ±Ø±¸µÄÖØµã·¨Ìõ£»	
	ѧԱ²ÎÓëÌÖÂÛ¡¢»¥¶¯£¬¿Î³ÌÉú¶¯ÓÐȤ£¬ÉîÈëdz³ö£¬ÊµÕ½Ðͳ¬Ç¿£¬ÈÃѧԱ¼´Ê±Ñ§ÒÔÖÂÓ㡿γÌÂúÒâ¶È¸ß´ï	
	95%£¬ÖÚ¶àѧԱ¾ù±íʾ£º¡°µÚÒ»´ÎÌýµ½Èç´Ëʵս¡¢ÊµÓá¢ÊµÐ§µÄÀͶ¯·¨¿Î³Ì£¡ÖÓÀÏʦ·Ç³£Îñʵ¡¢²»Ëµ½Ì¡¢	
	ûÓÐÉÌҵζµÀ£¬ÖÕÓÚÌýµ½ÁËÈÃÎÒ²»ÔÙºó»ÚµÄ¾«²Ê¿Î³Ì£¡¡±	
	    ÖÓÀÏʦÏȺóÔÚ¡¶¹ãÖÝÈÕ±¨¡·¡¢¡¶ÄÏ·½¶¼Êб¨¡·¡¢¡¶ÖйúÉç»á¿ÆÑ§±¨¡·¡¢¡¶ÈËÁ¦×ÊÔ´¡·¡¢¡¶Ïã¸Û¹¤Òµ	
	×Ü»áÔ¿¯¡·µÈ±¨¿¯¡¢ÔÓÖ¾¡¢Ã½Ìå·¢±íרҵÎÄÕ»ò²É·Ã¸å50¶àƪ¡£	
		
	¡¾Åàѵ¿Í»§¡¿	

	    ÔøÎªÒÔÏ¿ͻ§Ìṩ×Éѯ¡¢¹ËÎÊ¡¢ÄÚѵ£¨·Ç¹«¿ª¿Î£©·þÎñ£ºÖйúÈËÊÙ¡¢Ì«Æ½ÈËÊÙ¡¢»ª¿µ±£ÏÕ¡¢¹ã·¢Òø	
	ÐС¢¹â´óÒøÐС¢½¨ÉèÒøÐС¢Å©ÒµÒøÐС¢¹¤ÉÌÒøÐС¢ÖйúÓÊÕþ¡¢¹ú¼ÒµçÍø¡¢ÖйúÓÊÕþËٵݡ¢ÖйúÓÊÕþ´¢Ðî	
	ÒøÐС¢Ð¯³ÌÂÃÐÐÍø¡¢»ª¶¦µ£±£¡¢ÖÐÌú¼¯ÍÅ¡¢ÉîÛÚ»ú³¡¡¢»ÆºÓË®µç¿ª·¢¡¢ÖÐÑ̼¯ÍÅ¡¢ÄÏÔÁÎïÁ÷¡¢ÐÂÄÏ·½¼¯	
	ÍÅ¡¢ÉîÛÚ°®Ê©µÂ¹É·Ý¡¢ÉîÛڿᶯÊýÂë¡¢ºÏÉú´´Õ¹¡¢Öк£µØ²ú¡¢·½Ô²µØ²ú¡¢Öé½­¼àÀí¡¢Ö齭Ͷ×Ê¡¢ÃÉÅ£ÄÌ	
	·Û¡¢Èýеزú¡¢ÑøÉúÌÃÒ©Òµ¡¢Ò»Æ·ºìÒ©Òµ¡¢¾§Ô·¼¯ÍÅ¡¢¹ãÖݵçÐÅ¡¢¹úѶͨÐÅ¡¢Ò溣¼¯ÍÅ¡¢Íú´ó¼¯ÍÅ¡¢ÖÐ	
	Ô¶ÎïÁ÷¡¢Å·Ê±Á¦·þ×°¡¢¹ãÖÝÁëÄϼ¯ÍÅ¡¢¹ãÖÝÊß¹û¼¯ÍÅ¡¢¹ã¶«½»Í¨¼¯ÍÅ¡¢¹ãÖÝÎÞÏߵ缯ÍÅ¡¢Ö麣¿Ú°¶¹ã³¡¡¢	
	±ÈÑÇµÏÆû³µ¡¢×ݺáÌìµØÂÃÐÐÍø¡¢É߿ڴ¬ÎñÔËÊä¹É·Ý¡¢±±¾©µÃÐżѺÍÒ½ÁÆ¡¢·çÉñ¼¯ÍÅ¡¢ÖÐ×ɹ¤³Ì¼àÀí¡¢¹ã	
	Ò©¼¯ÍÅ¡¢¸ßÊ¿ÏßÒµ¡¢Àûº£¼¯ÍÅ¡¢»¯½¨¼¯ÍÅ¡¢ÉîÛÚË®Îñ¼àÀí¡¢ÉîÛÚÔË·¢¼¯ÍÅ¡¢ÉîÛÚ¶«²¿¹«½»¡¢Ð¹ã¹ú¼Ê¼¯	
	ÍÅ¡¢ÃÀµÄ¼¯ÍÅ¡¢½­ËÕ´óÈ«¼¯ÍÅ¡¢Ñغ£µØ²ú¿Ø¹É¡¢ÉîÛÚ»ªÇȳǡ¢ÐÅÔ´¼¯ÍÅ¡¢¾©³Ç¿Ø¹É¡¢¹ã¶«»ªÅ©ÎÂÊÏÐóÄÁ	
	¹É·Ý¡¢¹úÒ©ÎïÁ÷¼¯ÍŹ㶫¹«Ë¾¡¢ÔÆÄÏú»¯¹¤¼¯ÍÅ¡¢Õ㽭дó¼¯ÍÅ¡¢ÔÆÄϳۺêпÕà¹É·Ý¡¢¹ãÖݵçÁ¦ÏµÍ³¡¢	
	ÐŲý»úÆ÷¡¢ÔÆÄϺèÏèÒ©Òµ¼¯ÍÅ¡¢¹ã¶«¹ãµçÍøÂç¹É·Ý¹«Ë¾¡¢¹ãÆû²¿¼þ¡¢ÖйúÊ®ÆßÒ±¼¯ÍÅ¡¢ÖйúͨÐÅ·þÎñ¡¢	
	Å·ÆÕÕÕÃ÷¡¢ÖйãºË¼¯ÍÅ¡¢³É¶¼ÖÃÐż¯ÍÅ¡¢ÖйúÒÆ¶¯¡¢Öܴ󸣡¢É½¶«³£ÁÖ¼¯ÍÅ¡¢Ò溣¼ÎÀOÍÅ¡­¡­Ç§Óà¼Ò	
	ÆóÒµ¡£	
	    Ôø²Î¼Ó¹ýÖÓÀÏʦÅàѵ¹«¿ª¿ÎµÄ²¿·ÖÆóÒµ¿Í»§£ºÖйúÒÆ¶¯¡¢ÖйúÄÏ·½µçÍø¡¢Öйúũҵ´óѧ¡¢ÖÐɽ´óѧ¡¢	
	ÖйãºËÄÜÔ´¡¢Öé½­µçÓ°ÖÆÆ¬¡¢Íò¿ÆµØ²ú¡¢ÃÉÅ£ÈéÒµ¡¢Öé½­Æ¡¾Æ¡¢ÖйúÒøÐС¢¹ã·¢Ö¤¾í¡¢ÐËÒµÒøÐС¢ÖÐÐÅ	
	ÒøÐС¢ÖÐÐËͨѶ¡¢ÖÐʯ»¯¡¢Öк£ÓÍ¡¢°ÙÄêºýÍ¿¾ÆÒµ¡¢±£Àû·¿µØ²ú¡¢¸»Á¦µØ²ú¡¢ÑžÓÀֵزú¡¢°²Ì¤¡¢½ðµû	
	Èí¼þ¡¢³¿¹âÈéÒµ¡¢¹ãÖݵØÌú¡¢Á¢°×¼¯ÍÅ¡¢À¶ÔÂÁÁ¡¢Â·»¢Æû³µ¡¢Ö¾¸ß¿Õµ÷¡¢¹ãÖݵçÊǪ́¡¢°×ÔÆÉ½ÖÆÒ©¡¢¼Ó	
	¶à±¦¡¢»ªÎª¡¢½­ËÕÒøÐС¢¹ã¶«Ê¡µçÓ°¹«Ë¾¡¢±±¾©º½¿ÕÔº¡¢ÖйúÂÃÐÐÉç¡¢¹ã¶«Ð»ª·¢Ðм¯ÍÅ¡¢°ÙÊ£¨ÖÐ	
	¹ú£©¡¢»ªÈó½¨Öþ¡¢Ê¨Íõ¡¢ÄÚÃɹÅÎ÷À­ãåÂÙ¼¯ÍÅ¡¢Öйúº£ÑóʯÓÍ×ܹ«Ë¾¡¢Å²Íþ¹ú¼ÒʯÓ͹«Ë¾¡¢½ð巵زú¡¢	
	°²Á¸¿Ø¹É¡¢ÄϾ©Öʼà¼ìÑéÔº¡¢ÌìÕý¼¯ÍÅ¡¢ÉîÛÚ°ÍÊ¿¼¯ÍÅ¡¢NETSFIM£¨±±¾©£©Å©Òµ¿Æ¼¼¡¢ÄÚÃɹŽð¹þ´ïú	
	Ì¿»¯¹¤¡¢Öйú¿ÆÑ§Ôº¡¢¹ãÖÝÆû³µ¼¯ÍÅ¡¢¾ý»ª¼¯ÍÅ¡¢¿µ¼Ñ¼¯ÍÅ¡¢±±¾©º½¿ÕËù¡¢ÉîÛÚÓÊÕþ¾Ö¡¢¿É¿Ú¿ÉÀÖ¡¢Í¨	
	ÓÃµçÆø¡¢ËÉϵçÆ÷¡¢ÖÐÄÏ´óѧ¡¢°²°Ô°ëµ¼Ìå¡¢¾Æ¸Ö¼¯ÍÅ¡¢±¾ÌïÆû³µ¡¢Ò»àË×â³µ¡¢ÃׯäÁÖÂÖÌ¥¡¢Ë÷Äá¡¢ÊÀ	
	¼ÍÁúÐÅÏ¢ÍøÂç¡¢°¬Ä¬Éú¡¢TCL¡¢´´Î¬µçÆ÷¡¢¹úÒ©¼¯ÍÅ¡¢¼ªÁÖÑ̲ݡ¢ÂíÊ¿»ù¼¯×°Ïä¡¢ÓÃÓÑÈí¼þ¡¢½¨ÌÏ»¯¹¤	
	¼¯ÍÅ¡¢¸»Ê¿Í¨¡¢ÈýÒ»ÖØ¹¤¡­¡­¼¸Íò¼ÒÆóÒµ¡£	
		
	¿Î³Ì´ó¸Ù	

	Aµ¥ÔªÄÚÈÝ£¨¹²2Ì죬15¸öÒÔÉϾ­µä°¸Àý£©
	
	רÌâÒ»£ºÕÐÆ¸ÈëÖ°
	
	1.ÈçºÎÔ¤·ÀÀͶ¯Õߵġ°Ó¦Æ¸ÆÛÕ©¡±£¬ÈçºÎÖ¤Ã÷ÀͶ¯Õߵġ°ÆÛÕ©¡±£¿	
	2.ÕÐÊÕÓ¦½ì±ÏÒµÉú£¬Ó¦×¢ÒâÄÄЩϸ½ÚÎÊÌ⣿	
	3.ÕÐÓôﵽ·¨¶¨ÍËÐÝÄêÁäµÄÈËÔ±£¬Ó¦×¢ÒâÄÄЩϸ½ÚÎÊÌ⣿	
	4.ÕÐÓôý¸Ú¡¢ÄÚÍË¡¢Í£Ð½ÁôÖ°µÄÈËÔ±£¬Ó¦×¢ÒâÄÄЩϸ½ÚÎÊÌ⣿	
	5.ÈëÖ°Ìå¼ìÐè×¢ÒâÄÄЩϸ½ÚÎÊÌ⣿	
	6.ÈëְǰºóÓÃÈ˵¥Î»Ó¦¸æÖªÀͶ¯ÕßÄÄЩÇé¿ö£¬ÈçºÎ±£ÁôÖ¤¾Ý£¿	
	7.¡¶ÈëÖ°µÇ¼Ç±í¡·ÈçºÎÉè¼Æ£¬²ÅÄÜÆðµ½Ô¤·À·¨ÂÉ·çÏÕµÄ×÷Óã¿	
	8.ÀͶ¯ÕßÎÞ·¨Ìá½»¡¶ÀëÖ°Ö¤Ã÷¡·£¬¸ÃÔõô°ì£¿	
	9.ÆóÒµÈçºÎÊéд¡¶Â¼ÓÃ֪ͨÊé¡·£¬Æä·¨ÂÉ·çÏÕÓÐÄÄЩ£¿	
		
	רÌâ¶þ£ºÀͶ¯ºÏͬ¶©Á¢	

	1.ÓÃÈ˵¥Î»×ÔÐÐÄⶨµÄÀͶ¯ºÏͬÎı¾ÊÇ·ñÓÐЧ£¬ÊÇ·ñÐèÒª½øÐб¸°¸£¿	
	2.ÀͶ¯Õß½è¹ÊÍÏÑÓ»ò¾Ü¾øÇ©¶©ÀͶ¯ºÏͬ£¬ÓÃÈ˵¥Î»ÈçºÎÓ¦¶Ô£¿	
	3.δǩ¶©ÀͶ¯ºÏͬ£¬ÐèÖ§¸¶¶à³¤ÆÚÏÞµÄË«±¶¹¤×Ê£¿ÊÇ·ñÊܵ½ÖÙ²ÃʱЧµÄÏÞÖÆ£¿	
	4.ÀͶ¯ºÏͬÆÚÂú£¬¼ÌÐøÁôÓÃÀͶ¯Õߣ¬µ«Î´ÐøÇ©ºÏͬ£¬ÊÇ·ñÒ²ÐèÖ§¸¶Ë«±¶¹¤×Ê£¿	
	5.ʲôʱºòΪ×î¼Ñʱ¼ä£¬Ç©ÊðÀͶ¯ºÏͬ¡¢Óù¤Ð­Ò飿	
	6.·¨ÂɽûÖ¹2´ÎÔ¼¶¨ÊÔÓÃÆÚ£¬ÀͶ¯ºÏͬÆÚÏÞºÍÊÔÓÃÆÚÏÞ¸ÃÈçºÎÔ¼¶¨£¿	
	7.ÓÃÈ˵¥Î»ÊÕ¹ºÆäËû×é֯ʱ£¬ÈçºÎÓë±»½ÓÊÕµÄÔ±¹¤Ç©¶©¡¢±ä¸üÀͶ¯ºÏͬ£¿	
	8.Ó¦·ñÓëÊôÓÚÖ°Òµ¾­ÀíÈ˵ķ¨ÈË´ú±íÇ©¶©ÀͶ¯ºÏͬ£¿	
		
	רÌâÈý£ºÊÔÓÃÆÚ	

	1.¿É·ñÏÈÊÔÓúóÇ©ºÏͬ£¬¿É·ñµ¥¶ÀÇ©¶©ÊÔÓÃÆÚЭÒ飿 	
	2.Ô±¹¤Ö÷¶¯ÉêÇëÑÓ³¤ÊÔÓÃÆÚ£¬¸ÃÔõÑù²Ù×÷£¬²Å¹æ±ÜÅâ³¥·çÏÕ£¿	
	3.ÊÔÓÃÆÚÂúºó´ÇÍËÔ±¹¤£¬×îÉÙÅâ2¸öÔ¹¤×Ê£¬¸ÃÈçºÎ»¯½â£¿	
	4.ÊÔÓÃÆÚ×îºóÒ»Ìì´ÇÍËÔ±¹¤£¬Åâ³¥¸ÅÂÊΪ70%£¬ÈçºÎ»¯½â£¿	
	5.ÊÔÓÃÆÚÂúǰ¼¸Ìì´ÇÍËÔ±¹¤£¬Åâ³¥¸ÅÂÊΪ50%£¬ÈçºÎ»¯½â£¿	
	6.²»·ûºÏ¼ÓÃÌõ¼þµÄ·¶Î§°üÀ¨ÄÄЩ£¬ÈçºÎȡ֤֤Ã÷£¿	
	7.¡¶ÊÔÓÃÆÚ´ÇÍË֪ͨÊé¡·ÈçºÎÊéд£¬ÒÔ±ÜÃâÎ¥·¨½â³ýµÄÅâ³¥½ð£¿	
	8.³öÏÖ¡°¾­¼ÃÐÔ²ÃÔ±¡±Çé¿ö£¬ÓÅÏȲõôÊÔÓÃÆÚµÄÐÂÔ±¹¤£¬ºÏ·¨Âð£¿	
		
	רÌâËÄ£ºÎ޹̶¨ÆÚÏÞÀͶ¯ºÏͬ	

	1.Î޹̶¨ÆÚÏÞÀͶ¯ºÏͬµ½µ×ÊDz»ÊÇÌú·¹Í룬»á²»»áÔö¼ÓÆóÒµ³É±¾£¿	
	2.Î޹̶¨ÆÚÏÞÀͶ¯ºÏͬ½â³ýµÄÌõ¼þ¡¢ÀíÓÉÓÐÄÄЩ£¿	
	3.ÓÃÈ˵¥Î»¾Ü¾øÇ©¶©Î޹̶¨ÆÚÏÞÀͶ¯ºÏͬ£¬ÓкηçÏÕ£¿	
	4.Ç©¶©Á˹̶¨ÆÚÏÞÀͶ¯ºÏͬµÄÔ±¹¤£¬ÆÚ¼ä¹¤×÷ÀÛ¼ÆÂú10Ä꣬ÄÜ·ñÒªÇ󽫹̶¨ÆÚÏÞºÏͬ±ä¸üΪÎ޹̶¨ÆÚÏÞ	
	ºÏͬ£¿	
	5.Á¬Ðø¶©Á¢¶þ´Î¹Ì¶¨ÆÚÏÞÀͶ¯ºÏͬµ½ÆÚ£¬ÓÃÈ˵¥Î»ÄÜ·ñÖÕÖ¹ºÏͬ£»Ô±¹¤Ìá³öÇ©¶©Î޹̶¨ÆÚÏÞºÏͬ£¬ÓÃÈË	
	µ¥Î»ÄÜ·ñ¾Ü¾ø£¿	
	6.ºÏͬÆÚÂúÀͶ¯ÕßÓÉÓÚÒ½ÁÆÆÚ¡¢ÈýÆÚµÈÔ­ÒòÐøÑÓÀͶ¯ºÏͬµ¼ÖÂÀͶ¯ÕßÁ¬Ðø¹¤×÷ÂúÊ®Ä꣬ÀͶ¯ÕßÌá³ö¶©Á¢	
	Î޹̶¨ÆÚÏÞÀͶ¯ºÏͬµÄ£¬ÓÃÈ˵¥Î»ÄÜ·ñ¾Ü¾ø£¿	
		
	רÌâÎå£ºÌØÊâÓù¤Ð­Òé	

	1.Åàѵ·þÎñÆÚÓëÀͶ¯ºÏͬÆÚÏÞÓкβ»Í¬£¬ÀͶ¯ºÏͬÆÚÏÞÓë·þÎñÆÚÏÞ·¢Éú³åͻʱÈçºÎÊÊÓã¿	
	2.Åàѵ·þÎñÆÚδµ½ÆÚ£¬¶øÀͶ¯ºÏͬµ½ÆÚ£¬ÓÃÈ˵¥Î»ÖÕÖ¹ÀͶ¯ºÏͬµÄ£¬ÊÇ·ñÊôÓÚÌáǰ½â³ýÀͶ¯ºÏͬ£¬ÈçºÎ	
	¹æ±Ü£¿	
	3.ÀͶ¯ÕßÑÏÖØ¹ý´í±»½â¹Í£¬ÓÃÈ˵¥Î»ÄÜ·ñÒÀ¾Ý·þÎñÆÚÔ¼¶¨ÒªÇóÀͶ¯ÕßÖ§¸¶Î¥Ô¼½ð£¿	
	4.ÔÚʲôÇé¿öÏ£¬¿ÉÇ©Êð¾ºÒµÏÞÖÆÐ­Ò飿	
	5.ÔÚʲôʱºò£¬ÆóÒµ¸üÓÐÖ÷¶¯È¨Ç©Êð¾ºÒµÏÞÖÆÐ­Ò飿	
	6.ÎÞÔ¼¶¨¾­¼Ã²¹³¥µÄÖ§¸¶£¬¾ºÒµÏÞÖÆÊÇ·ñÓÐЧ£¿	
	7.¾ºÒµÏÞÖÆµÄ¾­¼Ã²¹³¥µÄ±ê×¼ÈçºÎ½ç¶¨£¿	
	8.ÒªÇóÔ±¹¤±£ÃÜ£¬ÆóÒµÐèÒªÖ§¸¶±£Ãܹ¤×ÊÂð£¿	
		
	רÌâÁù£ºÀͶ¯¹ØÏµ½â³ýÖÕÖ¹
	
	1.Ë«·½Ð­É̽â³ýÀͶ¯ºÏͬ²¢Ô¼¶¨Ö§¸¶Êʵ±µÄ¾­¼Ã²¹³¥£¬ÊºóÀͶ¯Õß×·ÌÖ¾­¼Ã²¹³¥µÄ²î¶î²¿·Ö£¬Öٲûú¹¹	
	ÓпÉÄÜÖ§³ÖÀͶ¯ÕßµÄËßÇ󣬯óÒµÈçºÎ±ÜÃâ°¸¼þ°ÜËߣ¿	
	2.ÄÜ·ñÓë¡°ÈýÆÚ¸¾Å®¡¢ÌØÊâ±£»¤ÆÚ¼äµÄÔ±¹¤¡±Ð­É̽â³ý£¬ÈçºÎ¹æ±Ü·çÏÕ£¿	
	3.Ô±¹¤Î´Ìáǰ30ÈÕ֪ͨÆóÒµ¼´×ÔÐÐÀëÖ°£¬ÆóÒµÄÜ·ñ¿Û¼õÆä¹¤×Ê£¿	
	4.Ô±¹¤Ìá½»´ÇÖ°ÐźóµÄ30ÌìÄÚ£¬ÆóÒµÅú×¼ÆäÀëÖ°£¬¿ÉÄÜÓзçÏÕ£¬ÈçºÎ»¯½â£¿	
	5.Ô±¹¤Ìá½»´ÇÖ°ÐźóµÄ30Ììºó£¬ÆóÒµÅú×¼ÆäÀëÖ°£¬Ò²¿ÉÄÜÓзçÏÕ£¬ÈçºÎ»¯½â£¿	
	6.¶ÔÓÚ»¼²¡Ô±¹¤£¬ÄÜ·ñ½â³ý£¬ÈçºÎ²Ù×÷²ÅÄܽµµÍ·¨ÂÉ·çÏÕ£¿	
	7.ʵÐÐĩλÌÔÌ­ÖÆ£¬ÒÔĩλÅÅÃûΪÓɽâ¹ÍÔ±¹¤£¬ÍùÍù±»È϶¨·Ç·¨½â¹Í£¬ÆóÒµ¸ÃÈçºÎ×ö£¬²Å±ÜÃâ°¸¼þ°ÜËߣ¿	
	8.ÒÔ¡°×éÖ¯¼Ü¹¹µ÷Õû£¬ÎÞºÏÊʸÚλ°²ÅÅ¡±ÎªÓɽâ¹ÍÔ±¹¤£¬¸Ð¾õ·Ç³£·ûºÏ³£Àí£¬µ«ÍùÍù±»È϶¨·Ç·¨½â¹Í£¬	
	ÆóÒµ¸ÃÈçºÎ×ö²Å±ÜÃâ·çÏÕ£¿	
	9.ÒÔ¡°¾­¼ÃÐÔ²ÃÔ±¡±ÃûÒå½â¹ÍÔ±¹¤£¬¸Ð¾õ·Ç³£·ûºÏ³£Àí£¬µ«ÍùÍù±»È϶¨·Ç·¨½â¹Í£¬ÆóÒµ¸ÃÈçºÎ²Ù×÷£¿	
	10.¡¶½â³ýÀͶ¯ºÏ֪ͬͨÊé¡·Èç¹û±íÊö²»µ±£¬ÍùÍù³ÉΪÀͶ¯Õß´òÓ®¹Ù˾µÄÓÐÁ¦Ö¤¾Ý£¬ÆóÒµ¸ÃÈçºÎÊéд£¬²Å	
	±ÜÃâ°¸¼þ°ÜËß¶ø³Ðµ£·¨ÂÉÔðÈΣ¿	
	11.½â³ýÀͶ¯ºÏͬǰδ֪ͨ¼°Õ÷Ç󹤻áµÄÒâ¼û£¬ÊÇ·ñ¹¹³É·Ç·¨½â³ý£¿	
	12.ÀͶ¯ºÏͬµ½ÆÚºó£¬¾­³£³öÏÖ¸ÃÖÕÖ¹µÄÍü¼Ç°ìÀíÖÕÖ¹ÊÖÐø£¬¸ÃÐøÇ©µÄÍü¼Ç°ìÀíÐøÇ©ÊÖÐø£¬ÆäÒý·¢µÄ·çÏÕ	
	·Ç³£´ó£»ÄÇôÆóÒµ¸ÃÈçºÎ¹æ±Ü·çÏÕ£¿	
		
	רÌâÆß£ºÉç»á±£ÏÕ·¨	

	1.ÓÃÈ˵¥Î»ÍÏÇ·Éç±£·Ñ£¬ÓÐʲô·¨ÂÉÔðÈΣ¿	
	2.ÓÃÈ˵¥Î»²»×ã¶î½ÉÄÉÉç»á±£ÏÕÈçºÎ´¦Àí£¿	
	3.Ô±¹¤²»Ô¸ÒâÂòÉç±££¬²¢Ó뵥λǩÓÐЭÒéµÄÇé¿öÏ£¬¸ÃЭÒéÊÇ·ñÓÐЧ£¿	
	4.ÊÔÓÃÆÚ¼ä£¬ÊÇ·ñ±ØÐë½ÉÄÉÉç»á±£ÏÕ£¿	
	5.Èç¹ûÎ޲α££¬ÀͶ¯ÕßÒòµÚÈý·½ÔðÈβúÉúµÄÒ½ÁÆ·ÑÓã¬ÄÜ·ñÒªÇóµ¥Î»±¨Ïú£¿	
	6.ÆóҵЭÖú´ÇÖ°Ô±¹¤Æ­È¡Ê§Òµ±£ÏÕ½ð£¬ÓÐʲô·¨ÂÉ·çÏÕ£¿	
	7.Ůְ¹¤Î´»éÏÈÔС¢Î´»éÉúÓýÕùÒéÈçºÎ´¦Àí£¿	
	8.»³ÔÐŮְ¹¤Ìá³ö³¤ÆÚÐݼٱ£Ì¥£¬Ö±ÖÁÐÞÍê²ú¼Ù£¬¸ÃÈçºÎЭµ÷´ËÎÊÌ⣿	
		
	רÌâ°Ë£ºÀͶ¯ÕùÒé´¦Àí	

	1.ÓÃÈ˵¥Î»°ÜËßµÄÔ­ÒòÖ÷ÒªÓÐÄÄЩ£¿	
	2.Öٲûò·¨ÔºÔÚ´¦Àí°¸¼þʱ£¬ÈçºÎÊÊÓ÷¨ÂÉ·¨¹æ£¿	
	3.ÈçºÎÅж¨Õþ²ß·¨ÂÉ·¨¹æµÄЧÁ¦µÈ¼¶£¿ 	
	4.¹«¿ªÉóÀíµÄ¿ªÍ¥ÐÎʽ£¬ÓкηçÏÕ£¬ÈçºÎ±ÜÃâ·çÏÕ£¿	
	5.ÉêÇëÖٲõÄʱЧÈçºÎ¼ÆË㣻ÈçºÎÀí½â¡°ÀͶ¯ÕùÒé·¢ÉúÖ®ÈÕ¡±£¿	
	6.ÈçºÎÊéд´ð±çÊ飬ÓÐÄÄЩעÒâÊÂÏ	
	7.¿ªÍ¥ÆÚ¼ä£¬ÖÊÖ¤Óë±çÂÛÐèҪעÒâÄÄЩ¹Ø¼üÎÊÌ⣿	
	8.¾ÙÖ¤ÔðÈÎÈçºÎ·ÖÅ䣬ÎÞ·¨¾ÙÖ¤µÄºó¹ûÓÐÄÄЩ£¿	
		
	Bµ¥ÔªÄÚÈÝ£¨¹²2Ì죬15¸öÒÔÉϾ­µä°¸Àý£©
	
	רÌâÒ»£º¼¨Ð§¹ÜÀíÓë¸Úλµ÷Õû	

	1.ÆóÒµµ¥·½µ÷Õû¸Úλ£¬Ô±¹¤ÍùÍù¿É±»ÆÈ½â³ýºÏͬ²¢Ë÷Åâ¾­¼Ã²¹³¥£¬ÈçºÎ¹æ±Ü£¿	
	2.µ÷¸ÚʱûÓÐÊéÃæÈ·ÈÏ£¬Ô±¹¤µ½Ð¸Úλ¹¤×÷2¸öÔºóÄÜ·ñÒªÇó»Ö¸´µ½Ô­¸Úλ£¿	
	3.¿É·ñ¶Ô¡°ÈýÆÚÄÚ¡±Å®Ö°¹¤½øÐе÷¸Ú¡¢µ÷н£¿	
	4.Ô±¹¤ÈÏͬ¼¨Ð§½á¹û£¬ÎªÊ²Ã´ÔÚ¡°²»Ê¤Èι¤×÷¡±Òý·¢µÄÕùÒéÖл¹ÊǰÜËߣ¿	
	5.ΪʲôÆóÒµ¸ù¾Ý¼¨Ð§½á¹ûÖ§¸¶Ô±¹¤¼¨Ð§½±½ð£¬×îÖÕ±»È϶¨·Ç·¨¿Ë¿Û¹¤×Ê£¿	
	6.·¨ÂÉÉÏÈçºÎÖ¤Ã÷ÀͶ¯Õß¡°²»ÄÜʤÈι¤×÷¡±£¿	
	7.¶Ô¼¨Ð§¿¼ºË²»ºÏ¸ñµÄÔ±¹¤£¬ÈçºÎºÏ·¨´ÇÍË£¿	
	8.¼¨Ð§Õý̬·Ö²¼ÍùÍùÇ¿ÖÆ»®·Ö5%µÄÔ±¹¤Îª²»ºÏ¸ñÕߣ¬ÊÇ·ñºÏ·¨£¿	
		
	רÌâ¶þ£ºÀͶ¯±¨³ê¡¢Ð½³ê¸£Àû	

	1.¹¤×Ê×ܶî°üÀ¨ÄÄЩ¹¤×ÊÃ÷ϸ£¿	
	2.нøÔ±¹¤Ð½×ʹÜÀíÎÊÌâ¼°´¦Àí¼¼ÇÉ£»	
	3.µ÷Õû¹¤×÷¸Úλºó£¬¿ÉÒÔµ÷Õûн×ʱê×¼Âð£¿	
	4.ÈçºÎͨ¹ýн³êµ÷Õû´¦ÀíÔ±¹¤Ê§Ö°¡¢Î¥¼ÍµÈÎÊÌ⣿	
	5.Öµ°àËã²»Ëã¼Ó°à£¿	
	6.¼Ó°à¼Óµã¹¤×ÊÖ§¸¶³£¼ûÎóÇø£¿	
	7.ÓÃÈ˵¥Î»ÈçºÎÉè¼Æ¹¤×ʹ¹³ÉÒÔ½µµÍ¼Ó°à·Ñ³É±¾£¿	
	8.δ¾­ÓÃÈ˵¥Î»°²ÅÅ£¬ÀͶ¯Õß×ÔÐмӰàµÄ£¬ÊÇ·ñÐèÖ§¸¶¼Ó°à¹¤×Ê£¿	
	9.ÀͶ¯ÕßÖ÷ÕÅÈëÖ°ÒÔÀ´µÄ¼Ó°à·Ñ£¬ÈçºÎÓ¦¶Ô£¿	
	10.ÀͶ¯ÕßÔÚ¹¤×÷ÈÕ\·¨¶¨½Ú¼ÙÈռӰ࣬ÄÜ·ñ°²ÅŲ¹Ðݶø²»ÓèÖ§¸¶¼Ó°à·Ñ£¿	
	11.²¡¼Ù¡¢ÄêÐݼ١¢»é¼Ù¡¢²ú¼Ù¡¢É¥¼ÙµÈµÄÏíÊÜÌõ¼þ¼°¹¤×Ê´ýÓö±ê×¼£¿	
	12.ÀëÖ°Ô±¹¤ÍùÍù»ØÍ·×·ÌÖÄêÖÕ½±£¬ÓпÉÄܵõ½Ö§³Ö£¬ÈçºÎ¹æ±Ü¸Ã·çÏÕ£¿	
		
	רÌâÈý£ºÎ¥¼ÍÎ¥¹æÎÊÌâÔ±¹¤´¦Àí	

	1.ÀͶ¯ÕßÍùÍù¾Ü¾øÇ©ÊÕ´¦·Ö¡¢½â¹Í֪ͨÊ飬ÈçºÎÓ¦¶Ô£¿	
	2.ÎÊÌâÔ±¹¤ÍùÍù¾Ü¾øÌá½»¡¶¼ìÌÖÊé¡·»ò·ñÈÏÎ¥¼ÍÎ¥¹æÊÂʵ£¬ÆóÒµ¸ÃÈçºÎÊÕ¼¯Ö¤¾Ý£¿	
	3.¶ÔÓÚÎ¥¼ÍÔ±¹¤£¬Ó¦¸ÃÔÚʲôʱ¼äÄÚ´¦Àí£¿	
	4.ÔõÑùÀí½â¡°ÑÏÖØÎ¥·´ÓÃÈ˵¥Î»µÄ¹æÕÂÖÆ¶È¡±?	
	5.ÈçºÎÔÚ¡¶³Í·£ÌõÀý¡·ÖÐÃèÊö¡°Ò»°ãÎ¥¼Í¡±¡¢¡°½ÏÖØÎ¥¼Í¡±¼°¡°ÑÏÖØÎ¥¼Í¡±£¿ 	
	6.ÔõÑùÀí½â¡°ÑÏÖØÊ§Ö°£¬ÓªË½Îè±×£¬¸øÓÃÈ˵¥Î»Ôì³ÉÖØ´óË𺦡±£¿	
	7.ÈçºÎ½ç¶¨¡°ÖØ´óË𺦡±£¬¡°ÖØ´óË𺦡±ÊÇ·ñ±ØÐëÌåÏÖΪÔì³ÉÖ±½ÓµÄ¾­¼ÃËðʧ£¿	
	8.ÈçºÎ×·¾¿¡°ÑÏÖØÊ§Ö°¡¢ÑÏÖØÎ¥¼ÍÎ¥¹æ¡±Õߵķ¨ÂÉÔðÈΣ¿	
	9.ÄÜ·ñÖ±½Ó¹æ¶¨¡°½ûÖ¹¼æÖ°£¬·ñÔòÊÓΪÑÏÖØÎ¥¼ÍÎ¥¹æ¡±£¿	
	10.Ö±Ïß²¿Ãž­ÀíÉÃ×Ô¿ÚÍ·´ÇÍËÔ±¹¤£¬Öٲûú¹¹ÍùÍùÈ϶¨ÆóÒµ·Ç·¨½â¹Í£¬ÆóÒµ¸ÃÈçºÎ×ö£¬²Å±ÜÃâ°¸¼þ°Ü	
	Ëߣ¿	
	11.ÀͶ¯Õß²»´Ç¶ø±ð¡¢Î޹ʿõ¹¤£¬È´Ö÷Õű»ÆóÒµ¿ÚÍ·½â¹Í£¬ÍùÍùµÃµ½Öٲûú¹¹µÄÖ§³Ö£¬ÆóÒµ¸ÃÈçºÎ×ö£¬²Å	
	±ÜÃâ°¸¼þ°ÜËߣ¿	
	12.¡°Â¼Òô¼Ïó¡±Ö¤¾Ý£¬ÖÙ²ÃÓë·¨ÔºÊÇ·ñ²ÉÐÅ£»ÆóÒµÄÚ²¿OAϵͳÉϵÄ×ÊÁÏÄÜ·ñ×÷Ϊ֤¾ÝʹÓ㻵ç×ÓÓʼþ¡¢	
	ÊÖ»ú¶ÌÐÅÄÜ·ñ×÷Ϊ֤¾ÝʹÓã¿ 	
		
	רÌâËÄ£º¾­¼Ã²¹³¥	

	1.ÓÃÈ˵¥Î»ÐèÏòÀͶ¯ÕßÖ§¸¶¾­¼Ã²¹³¥µÄÇéÐÎÓÐÄÄЩ£¿	
	2.ʲôÇé¿öÏÂÓÃÈ˵¥Î»ÐèÖ§¸¶Á½±¶µÄ¾­¼Ã²¹³¥£¿	
	3.ÀͶ¯Õ߿ɷñͬʱÏòÓÃÈ˵¥Î»Ö÷Õž­¼Ã²¹³¥ºÍÅâ³¥½ð£¿	
	4.¾­¼Ã²¹³¥¼ÆËãµÄ»ùÊý¼°±ê×¼ÈçºÎÈ·¶¨£¿	
	5.¾­¼Ã²¹³¥ÄêÏÞ×î¸ß²»³¬¹ýÊ®¶þÄêµÄÊÊÓ÷¶Î§£¿	
	6.ÈçºÎ¼ÆËã¡¶ÀͶ¯ºÏͬ·¨¡·ÉúЧǰºóµÄ¾­¼Ã²¹³¥ÄêÏÞ£¿	
	7.ÈçºÎÀí½â¡°Áù¸öÔÂÒÔÉϲ»ÂúÒ»ÄêµÄ£¬°´Ò»Äê¼ÆË㣻²»ÂúÁù¸öÔµģ¬ÏòÀͶ¯ÕßÖ§¸¶°ë¸öÔ¹¤×ʵľ­¼Ã²¹	
	³¥¡±£¿	
	8.ÀͶ¯ºÏͬ·¨»·¾³Ï¡°50%¶îÍâ¾­¼Ã²¹³¥½ð¡±ÊÇ·ñ¼ÌÐøÊÊÓã¿	
		
	רÌâÎ壺¹æÕÂÖÆ¶È¡¢Ô±¹¤ÊÖ²á	

	1.ÆóÒµÈËÁ¦×ÊÔ´¹ÜÀíÌåϵÖÐÄÄЩÄÚÈݸúÀͶ¯·¨ÓбØÈ»ÁªÏµ£¿	
	2.ÈËÁ¦×ÊÔ´¡¢ÀͶ¯Óù¤¹ÜÀíÖÆ¶ÈÓ¦¸Ã°üÀ¨ÄÄЩ±Ø±¸ÄÚÈÝ£¿	
	3.ÖÆ¶¨¹æÕÂÖÆ¶ÈµÄ³ÌÐòÒªÇó¸øÓÃÈ˵¥Î»´øÀ´ÄÄЩ·çÏÕ£¬ÈçºÎÓ¦¶Ô£¿	
	4.·Ç¹úÓÐÓÃÈ˵¥Î»ÈçºÎ×齨¡°Ö°¹¤´ú±í´ó»á¡±£¿	
	5.ÎÞÖ½»¯¡¢ÍøÂ绯°ì¹«ÏµĹ«Ê¾£¬´æÔÚÄÄЩ·çÏÕ£¿	
	6.ÈçºÎ¹«Ê¾»ò¸æÖª£¬¸ü·ûºÏÖٲûòËßËϵľÙÖ¤ÒªÇó£¿	
	7.¹æÕÂÖÆ¶ÈÄÜ·ñ¹æ¶¨¶ÔÔ±¹¤½øÐо­¼Ã´¦·££¿ 	
	8.¹æÕÂÖÆ¶ÈÎ¥·´·¨ÂÉ·¨¹æ£¬ÀͶ¯Õß¿ÉÒÔ±»ÆÈ½â³ý²¢Ë÷È¡¾­¼Ã²¹³¥£¬ÈçºÎ·À·¶£¿	
		
	רÌâÁù£º¹¤É˱£ÏÕÌõÀý	

	1.ÊôÓÚ¹¤ÉË·¶Î§µÄÇéÐÎÓÐÄÄЩ£¿	
	2.²»µÃÈ϶¨Îª¹¤É˵ÄÇéÐÎÓÐÄÄЩ£¿	
	3.ÔõÑùÀí½â¡°ÉÏϰà;ÖС±£¬ÔõÑù¿ØÖÆÆÚ¼äµÄ·çÏÕ£¿	
	4.·¢Éú¹¤ÉËʹʣ¬ÓÃÈ˵¥Î»Ðè³Ðµ£ÄÄЩ·ÑÓã¿	
	5.¹¤ÉËÔ±¹¤½è¹Ê¾Ü¾ø¸´¹¤£¬½è¹Ê²»¶ÏÐݼ٣¬ÈçºÎ´¦Àí£¿	
	6.¶ÔÓÚµÚÈý·½Ôì³ÉµÄ¹¤ÉËʹʣ¬ÀͶ¯ÕßÄÜ·ñÒªÇóÓÃÈ˵¥Î»Ö§¸¶¹¤ÉË´ýÓöÓÖͬʱҪÇóµÚÈý·½Ö§¸¶ÈËÉíÉ˺¦	
	Åâ³¥£¿ 	
	7.ÓÃÈ˵¥Î»ÄÜ·ñÒÔÉÌÒµ±£ÏÕÀíÅâ¿îÌæ´úÖ°¹¤¹¤ÉËÅâ³¥´ýÓö£¿	
	8.·¢Éú¹¤ÉËʹʣ¬Ë«·½Ë½Ïºͽ⣬²¹³¥Ð­Òé¸ÃÈçºÎÇ©¶©²ÅÓÐЧ£¿	
		
	רÌâÆß£ºÀÍÎñÅÉDz	

	1.ÀÍÎñÅÉDzÓù¤Ä£Ê½£¬ÓкÎÀû±×£¬Àû´ó»¹ÊDZ״ó£¿	
	2.ÀÍÎñÅÉDzºÏ×÷ЭÒ鱨Ðë×¢ÒâµÄ·çÏÕϸ½ÚÓÐÄÄЩ£¿	
	3.з¨ÏÂÀÍÎñÅÉÇ²ÃæÁÙµÄÖ÷Òª·çÏÕÓÐÄÄЩ£¿	
	4.ÅÉDz¹¤¡°µÚÈýÇ©¡±Ê±£¬ÄÜ·ñÒªÇóÇ©¶©Î޹̶¨ÆÚÏÞÀͶ¯ºÏͬ£¿	
	5.ÄÄЩ¸Úλ¿ÉÒÔʹÓÃÅÉDz¹¤£¬¸¨ÖúÐÔ¡¢ÁÙʱÐÔ¡¢Ìæ´úÐÔÈçºÎÀí½âÓë²Ù×÷£¿	
	6.й涨¶ÔÓÚͬ¹¤Í¬³êÌá³öÄÄЩÐÂÒªÇó£¬ÈçºÎ¹æ±Üͬ¹¤Í¬³ê·çÏÕ£¿	
	7.²ÉÓÃÀÍÎñÅÉDzÓù¤·½Ê½£¬ÄÜ·ñÒìµØ²Î±££¿	
	8.Óù¤µ¥Î»ÈçºÎÐÐʹ¶ÔÅÉDzԱ¹¤µÄÍË»¹»òÍË»»È¨£¿	
	9.ÈçºÎ´¦ÀíÎ¥·´Óù¤µ¥Î»¹æÕÂÖÆ¶ÈµÄÅÉDzԱ¹¤£¿	
	10.ÔõÑù¹æ¶¨ÅÉDzԱ¹¤µÄ´ÇÖ°³ÌÐòºÍÀëÖ°ÔðÈΣ¿	
	11.²¿·ÖÀÍÎñ¹«Ë¾ºÜ¿ÉÄÜÃæÁٹرÕÍ£Òµ£¬Ô­À´µÄÅÉDz¹¤µÄÀͶ¯¹ØÏµÈçºÎ´¦Àí£¿	
	12.ÒµÎñÍâ°üÓëÀÍÎñÅÉDzµÄ±¾ÖÊÇø±ðÓÐÄÄЩ£¿	
	13.ÈçºÎɸѡ³Ð°ü·½£¬Ð迼²ìÄÄЩϸ½ÚÒªµã£¿	
	14.Óù¤µ¥Î»ÈçºÎÓ¦¶ÔÅÉDzºÏ×÷ÕùÒéºÍÀͶ¯ÕùÒ飿	
		

--
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

* [PATCH v2 0/14] input: cyapa: re-architecture driver to support multi-trackpads in one driver
From: Dudley Du @ 2014-06-06  7:28 UTC (permalink / raw)
  To: Dmitry Torokhov, Rafael J. Wysocki, Alan Stern
  Cc: Benson Leung, Lily Rui, Daniel Kurtz, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 2855 bytes --]

This patch set is made based on kernel 3.15.0-rc8.
It's aimed to re-architecture the cyapa driver to support
old gen3 trackpad device and new gen5 trackpad device in one
cyapa driver for easily productions support based on
customers' requirements, and add sysfs functions and interfaces
supported that required by users and customers.
Because the earlier gen3 and the latest gen5 trackpad devies using
two different chipsets, and have different protocol and interfaces.
If supported these two trackpad devices in two different drivers, then
it will be difficult to manage productions and later firmware updates.
it will cause customer don't know which one to use and update
because these two trackpad devices have been used and integrated
in same one productions at a time, so must to support these two trackpad
devices in same on driver.

The new architecture is made of:
cyapa.c - the core of the architecture, supply interfaces and
functions to system and read trackpad devices.
cyapa_gen3.c - functions supported for gen3 trackpad devices,
cyapa_gen5.c - functions supported for gen5 trackpad devices.

Beside this introduction patch, it has 14 patches listed as below.
For these patches each one is patched based on previous one.

patch 1/14: re-architecture cyapa driver with core functions,
and applying the device detecting function in async thread to speed
up system boot time.

patch 2/14: add cyapa driver power management interfaces supported.

patch 3/14: add cyapa driver runtime power management interfaces supported.

patch 4/14: add cyapa key function interfaces in sysfs system.
Including read firmware version, get production ID, read baseline,
re-calibrate trackpad baselines and do trackpad firmware update.

patch 5/14: add read firmware image and read raw trackpad device'
sensors' raw data interface in debugfs system.

patch 6/14: add gen3 trackpad device basic functions supported.

patch 7/14: add gen3 trackpad device firmware update function supported.

patch 8/14: add gen3 trackpad device report baseline and do force
re-calibrate functions supported.

patch 9/14: add gen3 trackpad device read firmware image function supported.

patch 10/14: add gen5 trackpad device basic functions supported.

patch 11/14: add gen5 trackpad device firmware update function supported.

patch 12/14: add gen5 trackpad device report baseline and do force
re-calibrate functions supported.

patch 13/14: add gen5 trackpad device read firmware image and report
sensors' raw data values functions supported.

patch 14/14: add function to monitor LID close event to off trackpad device.
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.

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 5042 bytes --]

^ permalink raw reply

* [PATCH v2 1/14] input: cyapa: re-architecture driver to support multi-trackpads in one driver
From: Dudley Du @ 2014-06-06  7:28 UTC (permalink / raw)
  To: Dmitry Torokhov, Rafael J. Wysocki, Alan Stern
  Cc: Benson Leung, Lily Rui, Daniel Kurtz,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 55029 bytes --]

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 Chomebooks.

Signed-off-by: Du, Dudley <dudl@cypress.com>
---
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index c25efdb..d8948df 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,6 @@ 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..d5adee8 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -14,731 +14,193 @@
  * more details.
  */

+#include <linux/debugfs.h>
 #include <linux/delay.h>
 #include <linux/i2c.h>
 #include <linux/input.h>
 #include <linux/input/mt.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/slab.h>
+#include <linux/uaccess.h>
+#include <linux/pm_runtime.h>
+#include "cyapa.h"

-/* APA trackpad firmware generation */
-#define CYAPA_GEN3   0x03   /* support MT-protocol B with tracking ID. */
-
-#define CYAPA_NAME   "Cypress APA Trackpad (cyapa)"
-
-/* commands for read/write registers of Cypress trackpad */
-#define CYAPA_CMD_SOFT_RESET       0x00
-#define CYAPA_CMD_POWER_MODE       0x01
-#define CYAPA_CMD_DEV_STATUS       0x02
-#define CYAPA_CMD_GROUP_DATA       0x03
-#define CYAPA_CMD_GROUP_CMD        0x04
-#define CYAPA_CMD_GROUP_QUERY      0x05
-#define CYAPA_CMD_BL_STATUS        0x06
-#define CYAPA_CMD_BL_HEAD          0x07
-#define CYAPA_CMD_BL_CMD           0x08
-#define CYAPA_CMD_BL_DATA          0x09
-#define CYAPA_CMD_BL_ALL           0x0a
-#define CYAPA_CMD_BLK_PRODUCT_ID   0x0b
-#define CYAPA_CMD_BLK_HEAD         0x0c
-
-/* report data start reg offset address. */
-#define DATA_REG_START_OFFSET  0x0000
-
-#define BL_HEAD_OFFSET 0x00
-#define BL_DATA_OFFSET 0x10
-
-/*
- * Operational Device Status Register
- *
- * bit 7: Valid interrupt source
- * bit 6 - 4: Reserved
- * bit 3 - 2: Power status
- * bit 1 - 0: Device status
- */
-#define REG_OP_STATUS     0x00
-#define OP_STATUS_SRC     0x80
-#define OP_STATUS_POWER   0x0c
-#define OP_STATUS_DEV     0x03
-#define OP_STATUS_MASK (OP_STATUS_SRC | OP_STATUS_POWER | OP_STATUS_DEV)
-
-/*
- * Operational Finger Count/Button Flags Register
- *
- * bit 7 - 4: Number of touched finger
- * bit 3: Valid data
- * bit 2: Middle Physical Button
- * bit 1: Right Physical Button
- * bit 0: Left physical Button
- */
-#define REG_OP_DATA1       0x01
-#define OP_DATA_VALID      0x08
-#define OP_DATA_MIDDLE_BTN 0x04
-#define OP_DATA_RIGHT_BTN  0x02
-#define OP_DATA_LEFT_BTN   0x01
-#define OP_DATA_BTN_MASK (OP_DATA_MIDDLE_BTN | OP_DATA_RIGHT_BTN | \
-                         OP_DATA_LEFT_BTN)
-
-/*
- * Bootloader Status Register
- *
- * bit 7: Busy
- * bit 6 - 5: Reserved
- * bit 4: Bootloader running
- * bit 3 - 1: Reserved
- * bit 0: Checksum valid
- */
-#define REG_BL_STATUS        0x01
-#define BL_STATUS_BUSY       0x80
-#define BL_STATUS_RUNNING    0x10
-#define BL_STATUS_DATA_VALID 0x08
-#define BL_STATUS_CSUM_VALID 0x01
-
-/*
- * Bootloader Error Register
- *
- * bit 7: Invalid
- * bit 6: Invalid security key
- * bit 5: Bootloading
- * bit 4: Command checksum
- * bit 3: Flash protection error
- * bit 2: Flash checksum error
- * bit 1 - 0: Reserved
- */
-#define REG_BL_ERROR         0x02
-#define BL_ERROR_INVALID     0x80
-#define BL_ERROR_INVALID_KEY 0x40
-#define BL_ERROR_BOOTLOADING 0x20
-#define BL_ERROR_CMD_CSUM    0x10
-#define BL_ERROR_FLASH_PROT  0x08
-#define BL_ERROR_FLASH_CSUM  0x04
-
-#define BL_STATUS_SIZE  3  /* length of bootloader status registers */
-#define BLK_HEAD_BYTES 32
-
-#define PRODUCT_ID_SIZE  16
-#define QUERY_DATA_SIZE  27
-#define REG_PROTOCOL_GEN_QUERY_OFFSET  20
-
-#define REG_OFFSET_DATA_BASE     0x0000
-#define REG_OFFSET_COMMAND_BASE  0x0028
-#define REG_OFFSET_QUERY_BASE    0x002a
-
-#define CAPABILITY_LEFT_BTN_MASK       (0x01 << 3)
-#define CAPABILITY_RIGHT_BTN_MASK      (0x01 << 4)
-#define CAPABILITY_MIDDLE_BTN_MASK     (0x01 << 5)
-#define CAPABILITY_BTN_MASK  (CAPABILITY_LEFT_BTN_MASK | \
-                             CAPABILITY_RIGHT_BTN_MASK | \
-                             CAPABILITY_MIDDLE_BTN_MASK)
-
-#define CYAPA_OFFSET_SOFT_RESET  REG_OFFSET_COMMAND_BASE
-
-#define REG_OFFSET_POWER_MODE (REG_OFFSET_COMMAND_BASE + 1)
-
-#define PWR_MODE_MASK   0xfc
-#define PWR_MODE_FULL_ACTIVE (0x3f << 2)
-#define PWR_MODE_IDLE        (0x05 << 2) /* default sleep time is 50 ms. */
-#define PWR_MODE_OFF         (0x00 << 2)
-
-#define PWR_STATUS_MASK      0x0c
-#define PWR_STATUS_ACTIVE    (0x03 << 2)
-#define PWR_STATUS_IDLE      (0x02 << 2)
-#define PWR_STATUS_OFF       (0x00 << 2)
-
-/*
- * CYAPA trackpad device states.
- * Used in register 0x00, bit1-0, DeviceStatus field.
- * Other values indicate device is in an abnormal state and must be reset.
- */
-#define CYAPA_DEV_NORMAL  0x03
-#define CYAPA_DEV_BUSY    0x01
-
-enum cyapa_state {
-       CYAPA_STATE_OP,
-       CYAPA_STATE_BL_IDLE,
-       CYAPA_STATE_BL_ACTIVE,
-       CYAPA_STATE_BL_BUSY,
-       CYAPA_STATE_NO_DEVICE,
-};
-
-
-struct cyapa_touch {
-       /*
-        * high bits or x/y position value
-        * bit 7 - 4: high 4 bits of x position value
-        * bit 3 - 0: high 4 bits of y position value
-        */
-       u8 xy_hi;
-       u8 x_lo;  /* low 8 bits of x position value. */
-       u8 y_lo;  /* low 8 bits of y position value. */
-       u8 pressure;
-       /* id range is 1 - 15.  It is incremented with every new touch. */
-       u8 id;
-} __packed;
-
-/* The touch.id is used as the MT slot id, thus max MT slot is 15 */
-#define CYAPA_MAX_MT_SLOTS  15
-
-struct cyapa_reg_data {
-       /*
-        * bit 0 - 1: device status
-        * bit 3 - 2: power mode
-        * bit 6 - 4: reserved
-        * bit 7: interrupt valid bit
-        */
-       u8 device_status;
-       /*
-        * bit 7 - 4: number of fingers currently touching pad
-        * bit 3: valid data check bit
-        * bit 2: middle mechanism button state if exists
-        * bit 1: right mechanism button state if exists
-        * bit 0: left mechanism button state if exists
-        */
-       u8 finger_btn;
-       /* CYAPA reports up to 5 touches per packet. */
-       struct cyapa_touch touches[5];
-} __packed;
-
-/* The main device structure */
-struct cyapa {
-       enum cyapa_state state;
-
-       struct i2c_client *client;
-       struct input_dev *input;
-       char phys[32];  /* device physical location */
-       int irq;
-       bool irq_wake;  /* irq wake is enabled */
-       bool smbus;
-
-       /* read from query data region. */
-       char product_id[16];
-       u8 btn_capability;
-       u8 gen;
-       int max_abs_x;
-       int max_abs_y;
-       int physical_size_x;
-       int physical_size_y;
-};
-
-static const u8 bl_deactivate[] = { 0x00, 0xff, 0x3b, 0x00, 0x01, 0x02, 0x03,
-               0x04, 0x05, 0x06, 0x07 };
-static const u8 bl_exit[] = { 0x00, 0xff, 0xa5, 0x00, 0x01, 0x02, 0x03, 0x04,
-               0x05, 0x06, 0x07 };
-
-struct cyapa_cmd_len {
-       u8 cmd;
-       u8 len;
-};

 #define CYAPA_ADAPTER_FUNC_NONE   0
 #define CYAPA_ADAPTER_FUNC_I2C    1
 #define CYAPA_ADAPTER_FUNC_SMBUS  2
 #define CYAPA_ADAPTER_FUNC_BOTH   3

-/*
- * macros for SMBus communication
- */
-#define SMBUS_READ   0x01
-#define SMBUS_WRITE 0x00
-#define SMBUS_ENCODE_IDX(cmd, idx) ((cmd) | (((idx) & 0x03) << 1))
-#define SMBUS_ENCODE_RW(cmd, rw) ((cmd) | ((rw) & 0x01))
-#define SMBUS_BYTE_BLOCK_CMD_MASK 0x80
-#define SMBUS_GROUP_BLOCK_CMD_MASK 0x40
-
- /* for byte read/write command */
-#define CMD_RESET 0
-#define CMD_POWER_MODE 1
-#define CMD_DEV_STATUS 2
-#define SMBUS_BYTE_CMD(cmd) (((cmd) & 0x3f) << 1)
-#define CYAPA_SMBUS_RESET SMBUS_BYTE_CMD(CMD_RESET)
-#define CYAPA_SMBUS_POWER_MODE SMBUS_BYTE_CMD(CMD_POWER_MODE)
-#define CYAPA_SMBUS_DEV_STATUS SMBUS_BYTE_CMD(CMD_DEV_STATUS)
-
- /* for group registers read/write command */
-#define REG_GROUP_DATA 0
-#define REG_GROUP_CMD 2
-#define REG_GROUP_QUERY 3
-#define SMBUS_GROUP_CMD(grp) (0x80 | (((grp) & 0x07) << 3))
-#define CYAPA_SMBUS_GROUP_DATA SMBUS_GROUP_CMD(REG_GROUP_DATA)
-#define CYAPA_SMBUS_GROUP_CMD SMBUS_GROUP_CMD(REG_GROUP_CMD)
-#define CYAPA_SMBUS_GROUP_QUERY SMBUS_GROUP_CMD(REG_GROUP_QUERY)
-
- /* for register block read/write command */
-#define CMD_BL_STATUS 0
-#define CMD_BL_HEAD 1
-#define CMD_BL_CMD 2
-#define CMD_BL_DATA 3
-#define CMD_BL_ALL 4
-#define CMD_BLK_PRODUCT_ID 5
-#define CMD_BLK_HEAD 6
-#define SMBUS_BLOCK_CMD(cmd) (0xc0 | (((cmd) & 0x1f) << 1))
-
-/* register block read/write command in bootloader mode */
-#define CYAPA_SMBUS_BL_STATUS SMBUS_BLOCK_CMD(CMD_BL_STATUS)
-#define CYAPA_SMBUS_BL_HEAD SMBUS_BLOCK_CMD(CMD_BL_HEAD)
-#define CYAPA_SMBUS_BL_CMD SMBUS_BLOCK_CMD(CMD_BL_CMD)
-#define CYAPA_SMBUS_BL_DATA SMBUS_BLOCK_CMD(CMD_BL_DATA)
-#define CYAPA_SMBUS_BL_ALL SMBUS_BLOCK_CMD(CMD_BL_ALL)
-
-/* register block read/write command in operational mode */
-#define CYAPA_SMBUS_BLK_PRODUCT_ID SMBUS_BLOCK_CMD(CMD_BLK_PRODUCT_ID)
-#define CYAPA_SMBUS_BLK_HEAD SMBUS_BLOCK_CMD(CMD_BLK_HEAD)
-
-static const struct cyapa_cmd_len cyapa_i2c_cmds[] = {
-       { CYAPA_OFFSET_SOFT_RESET, 1 },
-       { REG_OFFSET_COMMAND_BASE + 1, 1 },
-       { REG_OFFSET_DATA_BASE, 1 },
-       { REG_OFFSET_DATA_BASE, sizeof(struct cyapa_reg_data) },
-       { REG_OFFSET_COMMAND_BASE, 0 },
-       { REG_OFFSET_QUERY_BASE, QUERY_DATA_SIZE },
-       { BL_HEAD_OFFSET, 3 },
-       { BL_HEAD_OFFSET, 16 },
-       { BL_HEAD_OFFSET, 16 },
-       { BL_DATA_OFFSET, 16 },
-       { BL_HEAD_OFFSET, 32 },
-       { REG_OFFSET_QUERY_BASE, PRODUCT_ID_SIZE },
-       { REG_OFFSET_DATA_BASE, 32 }
-};
+#define CYAPA_DEBUGFS_READ_FW  "read_fw"
+#define CYAPA_DEBUGFS_RAW_DATA "raw_data"
+#define CYAPA_FW_NAME          "cyapa.bin"

-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 },
-};
+const char unique_str[] = "CYTRA";

-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);
-}

-static ssize_t cyapa_i2c_reg_write_block(struct cyapa *cyapa, u8 reg,
-                                        size_t len, const u8 *values)
+void cyapa_enable_irq(struct cyapa *cyapa)
 {
-       return i2c_smbus_write_i2c_block_data(cyapa->client, reg, len, values);
+       mutex_lock(&cyapa->irq_state_lock);
+       if (!cyapa->irq_enabled)
+               enable_irq(cyapa->irq);
+       cyapa->irq_enabled = true;
+       cyapa->prev_irq_enabled = true;
+       mutex_unlock(&cyapa->irq_state_lock);
 }

-/*
- * cyapa_smbus_read_block - perform smbus block read command
- * @cyapa  - private data structure of the driver
- * @cmd    - the properly encoded smbus command
- * @len    - expected length of smbus command result
- * @values - buffer to store smbus command result
- *
- * Returns negative errno, else the number of bytes written.
- *
- * Note:
- * In trackpad device, the memory block allocated for I2C register map
- * is 256 bytes, so the max read block for I2C bus is 256 bytes.
- */
-static ssize_t cyapa_smbus_read_block(struct cyapa *cyapa, u8 cmd, size_t len,
-                                     u8 *values)
+void cyapa_disable_irq(struct cyapa *cyapa)
 {
-       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;
+       mutex_lock(&cyapa->irq_state_lock);
+       if (cyapa->irq_enabled)
+               disable_irq(cyapa->irq);
+       cyapa->irq_enabled = false;
+       cyapa->prev_irq_enabled = false;
+       mutex_unlock(&cyapa->irq_state_lock);
 }

-static s32 cyapa_read_byte(struct cyapa *cyapa, u8 cmd_idx)
+void cyapa_enable_irq_save(struct cyapa *cyapa)
 {
-       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;
+       mutex_lock(&cyapa->irq_state_lock);
+       if (!cyapa->irq_enabled) {
+               enable_irq(cyapa->irq);
+               cyapa->irq_enabled = true;
        }
-       return i2c_smbus_read_byte_data(cyapa->client, cmd);
+       mutex_unlock(&cyapa->irq_state_lock);
 }

-static s32 cyapa_write_byte(struct cyapa *cyapa, u8 cmd_idx, u8 value)
+void cyapa_disable_irq_save(struct cyapa *cyapa)
 {
-       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;
+       mutex_lock(&cyapa->irq_state_lock);
+       if (cyapa->irq_enabled) {
+               disable_irq(cyapa->irq);
+               cyapa->irq_enabled = false;
        }
-       return i2c_smbus_write_byte_data(cyapa->client, cmd, value);
+       mutex_unlock(&cyapa->irq_state_lock);
 }

-static ssize_t cyapa_read_block(struct cyapa *cyapa, u8 cmd_idx, u8 *values)
+void cyapa_irq_restore(struct cyapa *cyapa)
 {
-       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_lock(&cyapa->irq_state_lock);
+       if (cyapa->irq_enabled != cyapa->prev_irq_enabled) {
+               if (cyapa->prev_irq_enabled) {
+                       enable_irq(cyapa->irq);
+                       cyapa->irq_enabled = true;
+               } else {
+                       disable_irq(cyapa->irq);
+                       cyapa->irq_enabled = false;
+               }
        }
+       mutex_unlock(&cyapa->irq_state_lock);
 }

-/*
- * Query device for its current operating state.
- *
- */
-static int cyapa_get_state(struct cyapa *cyapa)
+bool cyapa_is_irq_enabled(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);
+       bool enabled;

-       /*
-        * 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;
+       mutex_lock(&cyapa->irq_state_lock);
+       enabled = cyapa->irq_enabled;
+       mutex_unlock(&cyapa->irq_state_lock);
+       return enabled;
 }

-/*
- * Poll device for its status in a loop, waiting up to timeout for a response.
- *
- * When the device switches state, it usually takes ~300 ms.
- * However, when running a new firmware image, the device must calibrate its
- * sensors, which can take as long as 2 seconds.
- *
- * Note: The timeout has granularity of the polling rate, which is 100 ms.
- *
- * Returns:
- *   0 when the device eventually responds with a valid non-busy state.
- *   -ETIMEDOUT if device never responds (too many -EAGAIN)
- *   < 0    other errors
- */
-static int cyapa_poll_state(struct cyapa *cyapa, unsigned int timeout)
+bool cyapa_state_sync_enter(struct cyapa *cyapa)
 {
-       int ret;
-       int tries = timeout / 100;
-
-       ret = cyapa_get_state(cyapa);
-       while ((ret || cyapa->state >= CYAPA_STATE_BL_BUSY) && tries--) {
-               msleep(100);
-               ret = cyapa_get_state(cyapa);
+       mutex_lock(&cyapa->state_sync_lock);
+       if (cyapa->in_syncing) {
+               mutex_unlock(&cyapa->state_sync_lock);
+               return false;
        }
-       return (ret == -EAGAIN || ret == -ETIMEDOUT) ? -ETIMEDOUT : ret;
+       cyapa->in_syncing = true;
+       mutex_unlock(&cyapa->state_sync_lock);
+       return true;
 }

-static int cyapa_bl_deactivate(struct cyapa *cyapa)
+void cyapa_state_sync_exit(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;
+       mutex_lock(&cyapa->state_sync_lock);
+       cyapa->in_syncing = false;
+       mutex_unlock(&cyapa->state_sync_lock);
 }

-/*
- * 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)
+/* Returns the number of read bytes or a negative errno code. */
+ssize_t cyapa_i2c_read(struct cyapa *cyapa, u8 reg, size_t len,
+                                       u8 *values)
 {
        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.
-        */
-       ret = cyapa_poll_state(cyapa, 2000);
-       if (ret < 0)
-               return ret;
-       if (cyapa->state != CYAPA_STATE_OP)
-               return -EAGAIN;
-
-       return 0;
+       struct i2c_client *client = cyapa->client;
+       struct i2c_msg msgs[] = {
+               {
+                       .addr = client->addr,
+                       .flags = 0,
+                       .len = 1,
+                       .buf = &reg,
+               },
+               {
+                       .addr = client->addr,
+                       .flags = I2C_M_RD,
+                       .len = len,
+                       .buf = values,
+               },
+       };
+
+       ret = i2c_transfer(client->adapter, msgs, 2);
+
+       return (ret == 2) ? len : ((ret < 0) ? ret : -EIO);
 }

-/*
- * Set device power mode
+/**
+ * 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: the data length of bytes to written.
+ * @values: Data to be written
  *
+ * This executes returns a negative errno code else zero on success.
  */
-static int cyapa_set_power_mode(struct cyapa *cyapa, u8 power_mode)
+ssize_t cyapa_i2c_write(struct cyapa *cyapa, u8 reg,
+                                        size_t len, const u8 *values)
 {
-       struct device *dev = &cyapa->client->dev;
        int ret;
-       u8 power;
+       struct i2c_client *client = cyapa->client;
+       char data[32], *buf;

-       if (cyapa->state != CYAPA_STATE_OP)
-               return 0;
+       if (len > 31)
+               buf = kzalloc(len + 1, GFP_KERNEL);
+       else
+               buf = &data[0];

-       ret = cyapa_read_byte(cyapa, CYAPA_CMD_POWER_MODE);
-       if (ret < 0)
-               return ret;
+       buf[0] = reg;
+       memcpy(&buf[1], values, len);
+       ret = i2c_master_send(client, buf, len + 1);

-       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;
+       if (buf != &data[0])
+               kfree(buf);
+       return (ret == (len + 1)) ? 0 : ((ret < 0) ? ret : -EIO);
 }

-static int cyapa_get_query_data(struct cyapa *cyapa)
+void cyapa_default_irq_handler(struct cyapa *cyapa)
 {
-       u8 query_data[QUERY_DATA_SIZE];
-       int ret;
-
-       if (cyapa->state != CYAPA_STATE_OP)
-               return -EBUSY;
-
-       ret = cyapa_read_block(cyapa, CYAPA_CMD_GROUP_QUERY, query_data);
-       if (ret < 0)
-               return ret;
-       if (ret != QUERY_DATA_SIZE)
-               return -EIO;
-
-       memcpy(&cyapa->product_id[0], &query_data[0], 5);
-       cyapa->product_id[5] = '-';
-       memcpy(&cyapa->product_id[6], &query_data[5], 6);
-       cyapa->product_id[12] = '-';
-       memcpy(&cyapa->product_id[13], &query_data[11], 2);
-       cyapa->product_id[15] = '\0';
-
-       cyapa->btn_capability = query_data[19] & CAPABILITY_BTN_MASK;
-
-       cyapa->gen = query_data[20] & 0x0f;
-
-       cyapa->max_abs_x = ((query_data[21] & 0xf0) << 4) | query_data[22];
-       cyapa->max_abs_y = ((query_data[21] & 0x0f) << 8) | query_data[23];
-
-       cyapa->physical_size_x =
-               ((query_data[24] & 0xf0) << 4) | query_data[25];
-       cyapa->physical_size_y =
-               ((query_data[24] & 0x0f) << 8) | query_data[26];
-
-       return 0;
+       /* do redetecting when device states is still unknown and
+        * interrupt envent is received from device. */
+       async_schedule(cyapa_detect_async, cyapa);
 }

-/*
- * Check if device is operational.
- *
- * An operational device is responding, has exited bootloader, and has
- * firmware supported by this driver.
- *
- * Returns:
- *   -EBUSY  no device or in bootloader
- *   -EIO    failure while reading from device
- *   -EAGAIN device is still in bootloader
- *           if ->state = CYAPA_STATE_BL_IDLE, device has invalid firmware
- *   -EINVAL device is in operational mode, but not supported by this driver
- *   0       device is supported
- */
-static int cyapa_check_is_operational(struct cyapa *cyapa)
-{
-       struct device *dev = &cyapa->client->dev;
-       static const char unique_str[] = "CYTRA";
-       int ret;
-
-       ret = cyapa_poll_state(cyapa, 2000);
-       if (ret < 0)
-               return ret;
-       switch (cyapa->state) {
-       case CYAPA_STATE_BL_ACTIVE:
-               ret = cyapa_bl_deactivate(cyapa);
-               if (ret)
-                       return ret;
-
-       /* Fallthrough state */
-       case CYAPA_STATE_BL_IDLE:
-               ret = cyapa_bl_exit(cyapa);
-               if (ret)
-                       return ret;
+const struct cyapa_dev_ops cyapa_default_ops = {
+       NULL,
+       NULL,

-       /* Fallthrough state */
-       case CYAPA_STATE_OP:
-               ret = cyapa_get_query_data(cyapa);
-               if (ret < 0)
-                       return ret;
+       NULL,
+       NULL,

-               /* only support firmware protocol gen3 */
-               if (cyapa->gen != CYAPA_GEN3) {
-                       dev_err(dev, "unsupported protocol version (%d)",
-                               cyapa->gen);
-                       return -EINVAL;
-               }
+       cyapa_default_irq_handler,
+       NULL,
+       NULL,

-               /* only support product ID starting with CYTRA */
-               if (memcmp(cyapa->product_id, unique_str,
-                          sizeof(unique_str) - 1) != 0) {
-                       dev_err(dev, "unsupported product ID (%s)\n",
-                               cyapa->product_id);
-                       return -EINVAL;
-               }
-               return 0;
-
-       default:
-               return -EIO;
-       }
-       return 0;
-}
-
-static irqreturn_t cyapa_irq(int irq, void *dev_id)
-{
-       struct cyapa *cyapa = dev_id;
-       struct device *dev = &cyapa->client->dev;
-       struct input_dev *input = cyapa->input;
-       struct cyapa_reg_data data;
-       int i;
-       int ret;
-       int num_fingers;
-
-       if (device_may_wakeup(dev))
-               pm_wakeup_event(dev, 0);
-
-       ret = cyapa_read_block(cyapa, CYAPA_CMD_GROUP_DATA, (u8 *)&data);
-       if (ret != sizeof(data))
-               goto out;
-
-       if ((data.device_status & OP_STATUS_SRC) != OP_STATUS_SRC ||
-           (data.device_status & OP_STATUS_DEV) != CYAPA_DEV_NORMAL ||
-           (data.finger_btn & OP_DATA_VALID) != OP_DATA_VALID) {
-               goto out;
-       }
-
-       num_fingers = (data.finger_btn >> 4) & 0x0f;
-       for (i = 0; i < num_fingers; i++) {
-               const struct cyapa_touch *touch = &data.touches[i];
-               /* Note: touch->id range is 1 to 15; slots are 0 to 14. */
-               int slot = touch->id - 1;
-
-               input_mt_slot(input, slot);
-               input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
-               input_report_abs(input, ABS_MT_POSITION_X,
-                                ((touch->xy_hi & 0xf0) << 4) | touch->x_lo);
-               input_report_abs(input, ABS_MT_POSITION_Y,
-                                ((touch->xy_hi & 0x0f) << 8) | touch->y_lo);
-               input_report_abs(input, ABS_MT_PRESSURE, touch->pressure);
-       }
-
-       input_mt_sync_frame(input);
-
-       if (cyapa->btn_capability & CAPABILITY_LEFT_BTN_MASK)
-               input_report_key(input, BTN_LEFT,
-                                data.finger_btn & OP_DATA_LEFT_BTN);
-
-       if (cyapa->btn_capability & CAPABILITY_MIDDLE_BTN_MASK)
-               input_report_key(input, BTN_MIDDLE,
-                                data.finger_btn & OP_DATA_MIDDLE_BTN);
-
-       if (cyapa->btn_capability & CAPABILITY_RIGHT_BTN_MASK)
-               input_report_key(input, BTN_RIGHT,
-                                data.finger_btn & OP_DATA_RIGHT_BTN);
-
-       input_sync(input);
+       NULL,
+};

-out:
-       return IRQ_HANDLED;
-}

 static u8 cyapa_check_adapter_functionality(struct i2c_client *client)
 {
@@ -784,7 +246,27 @@ static int cyapa_create_input_dev(struct cyapa *cyapa)
                             0);
        input_set_abs_params(input, ABS_MT_POSITION_Y, 0, cyapa->max_abs_y, 0,
                             0);
-       input_set_abs_params(input, ABS_MT_PRESSURE, 0, 255, 0, 0);
+       input_set_abs_params(input, ABS_MT_PRESSURE, 0, cyapa->max_z, 0, 0);
+       if (cyapa->gen > CYAPA_GEN3) {
+               input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
+               input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, 255, 0, 0);
+               /* orientation is the angle between the vertial axis and
+                * the major axis of the contact ellipse.
+                * The range is -127 to 127.
+                * the positive direction is clockwise form the vertical axis.
+                * If the ellipse of contact degenerates into a circle,
+                * orientation is reported as 0.
+                *
+                * Also, for Gen5 trackpad the accurate of this orientation
+                * value is value + (-30 ~ 30).
+                */
+               input_set_abs_params(input, ABS_MT_ORIENTATION,
+                               -127, 127, 0, 0);
+       }
+       if (cyapa->gen >= CYAPA_GEN5) {
+               input_set_abs_params(input, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
+               input_set_abs_params(input, ABS_MT_WIDTH_MINOR, 0, 255, 0, 0);
+       }

        input_abs_set_res(input, ABS_MT_POSITION_X,
                          cyapa->max_abs_x / cyapa->physical_size_x);
@@ -823,6 +305,214 @@ err_free_device:
        return ret;
 }

+/*
+ * Check if device is operational.
+ *
+ * An operational device is responding, has exited bootloader, and has
+ * firmware supported by this driver.
+ *
+ * Returns:
+ *   -EBUSY  no device or in bootloader
+ *   -EIO    failure while reading from device
+ *   -EAGAIN device is still in bootloader
+ *           if ->state = CYAPA_STATE_BL_IDLE, device has invalid firmware
+ *   -EINVAL device is in operational mode, but not supported by this driver
+ *   0       device is supported
+ */
+static int cyapa_check_is_operational(struct cyapa *cyapa)
+{
+       int ret;
+
+       ret = cyapa_poll_state(cyapa, 4000);
+       if (ret)
+               return ret;
+
+       switch (cyapa->gen) {
+       default:
+               cyapa->ops = &cyapa_default_ops;
+               cyapa->gen = CYAPA_GEN_UNKNOWN;
+               break;
+       }
+
+       if (cyapa->ops->cyapa_operational_check)
+               ret = cyapa->ops->cyapa_operational_check(cyapa);
+       else
+               ret = -EBUSY;
+
+       return ret;
+}
+
+
+static irqreturn_t cyapa_irq(int irq, void *dev_id)
+{
+       struct cyapa *cyapa = dev_id;
+       struct input_dev *input = cyapa->input;
+       bool cont;
+
+       /* interrupt event maybe cuased by host command to trackpad device. */
+       cont = true;
+       if (cyapa->ops->cyapa_irq_cmd_handler)
+               cont = cyapa->ops->cyapa_irq_cmd_handler(cyapa);
+
+       /* interrupt event maybe from trackpad device input reporting. */
+       if (cont && cyapa->ops->cyapa_irq_handler) {
+               if (!cyapa_state_sync_enter(cyapa)) {
+                       if (cyapa->ops->cyapa_sort_empty_output_data)
+                               cyapa->ops->cyapa_sort_empty_output_data(cyapa,
+                                       NULL, NULL, NULL);
+                       goto out;
+               }
+
+               if (!input && cyapa->ops->cyapa_sort_empty_output_data) {
+                       cyapa->ops->cyapa_sort_empty_output_data(cyapa,
+                               NULL, NULL, NULL);
+                       goto out;
+               }
+
+               cyapa->ops->cyapa_irq_handler(cyapa);
+
+               cyapa_state_sync_exit(cyapa);
+       }
+out:
+       return IRQ_HANDLED;
+}
+
+/*
+ * Query device for its current operating state.
+ *
+ */
+static int cyapa_get_state(struct cyapa *cyapa)
+{
+       cyapa->state = CYAPA_STATE_NO_DEVICE;
+
+       return -ENODEV;
+}
+
+/*
+ * Poll device for its status in a loop, waiting up to timeout for a response.
+ *
+ * When the device switches state, it usually takes ~300 ms.
+ * However, when running a new firmware image, the device must calibrate its
+ * sensors, which can take as long as 2 seconds.
+ *
+ * Note: The timeout has granularity of the polling rate, which is 100 ms.
+ *
+ * Returns:
+ *   0 when the device eventually responds with a valid non-busy state.
+ *   -ETIMEDOUT if device never responds (too many -EAGAIN)
+ *   < 0    other errors
+ */
+int cyapa_poll_state(struct cyapa *cyapa, unsigned int timeout)
+{
+       int ret;
+       int tries = timeout / 100;
+
+       ret = cyapa_get_state(cyapa);
+       while ((ret || cyapa->state >= CYAPA_STATE_BL_BUSY) && tries--) {
+               msleep(100);
+               ret = cyapa_get_state(cyapa);
+       }
+
+       return (ret == -EAGAIN || ret == -ETIMEDOUT) ? -ETIMEDOUT : ret;
+}
+
+static void cyapa_detect(struct cyapa *cyapa)
+{
+       struct device *dev = &cyapa->client->dev;
+       char *envp[2] = {"ERROR=1", NULL};
+       int ret;
+
+       ret = cyapa_check_is_operational(cyapa);
+       if (ret == -ETIMEDOUT)
+               dev_err(dev, "no device detected, %d\n", ret);
+       else if (ret)
+               dev_err(dev, "device detected, but not operational, %d\n", ret);
+
+       if (ret) {
+               kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
+               return;
+       }
+
+       if (!cyapa->input) {
+               ret = cyapa_create_input_dev(cyapa);
+               if (ret)
+                       dev_err(dev, "create input_dev instance failed, %d\n",
+                               ret);
+
+               cyapa_enable_irq(cyapa);
+
+               /*
+                * 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->cyapa_set_power_mode) {
+                       ret = cyapa->ops->cyapa_set_power_mode(cyapa,
+                                       PWR_MODE_FULL_ACTIVE, 0);
+                       if (ret)
+                               dev_warn(dev, "set active power failed, %d\n",
+                                               ret);
+               }
+       }
+}
+
+/*
+ * cyapa_sleep_time_to_pwr_cmd and cyapa_pwr_cmd_to_sleep_time
+ *
+ * These are helper functions that convert to and from integer idle
+ * times and register settings to write to the PowerMode register.
+ * The trackpad supports between 20ms to 1000ms scan intervals.
+ * The time will be increased in increments of 10ms from 20ms to 100ms.
+ * From 100ms to 1000ms, time will be increased in increments of 20ms.
+ *
+ * When Idle_Time < 100, the format to convert Idle_Time to Idle_Command is:
+ *   Idle_Command = Idle Time / 10;
+ * When Idle_Time >= 100, the format to convert Idle_Time to Idle_Command is:
+ *   Idle_Command = Idle Time / 20 + 5;
+ */
+u8 cyapa_sleep_time_to_pwr_cmd(u16 sleep_time)
+{
+       if (sleep_time < 20)
+               sleep_time = 20;     /* minimal sleep time. */
+       else if (sleep_time > 1000)
+               sleep_time = 1000;   /* maximal sleep time. */
+
+       if (sleep_time < 100)
+               return ((sleep_time / 10) << 2) & PWR_MODE_MASK;
+       else
+               return ((sleep_time / 20 + 5) << 2) & PWR_MODE_MASK;
+}
+
+u16 cyapa_pwr_cmd_to_sleep_time(u8 pwr_mode)
+{
+       u8 encoded_time = pwr_mode >> 2;
+       return (encoded_time < 10) ? encoded_time * 10
+                                  : (encoded_time - 5) * 20;
+}
+
+void cyapa_detect_async(void *data, async_cookie_t cookie)
+{
+       struct cyapa *cyapa = (struct cyapa *)data;
+
+       if (!cyapa_state_sync_enter(cyapa))
+               return;
+
+       /* keep synchnized with sys interface process threads. */
+       cyapa_detect(cyapa);
+
+       cyapa_state_sync_exit(cyapa);
+}
+
+static void cyapa_detect_and_start(void *data, async_cookie_t cookie)
+{
+       cyapa_detect_async(data, cookie);
+}
+
 static int cyapa_probe(struct i2c_client *client,
                       const struct i2c_device_id *dev_id)
 {
@@ -830,6 +520,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,41 +528,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");
                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);

+       cyapa->ops = &cyapa_default_ops;
+       cyapa->in_syncing = false;
+       mutex_init(&cyapa->state_sync_lock);
+       cyapa->gen = CYAPA_GEN_UNKNOWN;
+       mutex_init(&cyapa->state_sync_lock);
+       mutex_init(&cyapa->irq_state_lock);
+
        /* 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);
-       if (ret) {
-               dev_err(dev, "device not operational, %d\n", ret);
-               goto err_mem_free;
-       }
-
-       ret = cyapa_create_input_dev(cyapa);
-       if (ret) {
-               dev_err(dev, "create input_dev instance failed, %d\n", ret);
-               goto err_mem_free;
-       }
-
-       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;
-       }
+       /* 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;
+       cyapa->irq_enabled = true;
        ret = request_threaded_irq(cyapa->irq,
                                   NULL,
                                   cyapa_irq,
@@ -882,12 +573,14 @@ static int cyapa_probe(struct i2c_client *client,
                dev_err(dev, "IRQ request failed: %d\n, ", ret);
                goto err_unregister_device;
        }
+       cyapa_disable_irq(cyapa);

+       async_schedule(cyapa_detect_and_start, cyapa);
        return 0;

 err_unregister_device:
        input_unregister_device(cyapa->input);
-err_mem_free:
+       i2c_set_clientdata(client, NULL);
        kfree(cyapa);

        return ret;
@@ -898,8 +591,11 @@ static int cyapa_remove(struct i2c_client *client)
        struct cyapa *cyapa = i2c_get_clientdata(client);

        free_irq(cyapa->irq, cyapa);
+
        input_unregister_device(cyapa->input);
-       cyapa_set_power_mode(cyapa, PWR_MODE_OFF);
+       if (cyapa->ops->cyapa_set_power_mode)
+               cyapa->ops->cyapa_set_power_mode(cyapa, PWR_MODE_OFF, 0);
+       i2c_set_clientdata(client, NULL);
        kfree(cyapa);

        return 0;
@@ -912,17 +608,21 @@ static int cyapa_suspend(struct device *dev)
        u8 power_mode;
        struct cyapa *cyapa = dev_get_drvdata(dev);

-       disable_irq(cyapa->irq);
+       cyapa_disable_irq(cyapa);

        /*
         * 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->cyapa_set_power_mode) {
+               ret = cyapa->ops->cyapa_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 +636,24 @@ static int cyapa_resume(struct device *dev)

        if (device_may_wakeup(dev) && cyapa->irq_wake)
                disable_irq_wake(cyapa->irq);
+       cyapa_enable_irq(cyapa);

-       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->cyapa_set_power_mode) {
+               ret = cyapa->ops->cyapa_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 },
diff --git a/drivers/input/mouse/cyapa.h b/drivers/input/mouse/cyapa.h
new file mode 100644
index 0000000..1780d82
--- /dev/null
+++ b/drivers/input/mouse/cyapa.h
@@ -0,0 +1,265 @@
+/*
+ * Cypress APA trackpad with I2C interface
+ *
+ * Author: Dudley Du <dudl@cypress.com>
+ *
+ * Copyright (C) 2014-2015 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)
+
+/*
+ * 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 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 {
+       size_t (*cyapa_get_private_size)(void);
+       int (*cyapa_private_init)(struct cyapa *cyapa, void *private_mem);
+
+       int (*cyapa_state_parse)(struct cyapa *cyapa, u8 *reg_status, int len);
+       int (*cyapa_operational_check)(struct cyapa *cyapa);
+
+       void (*cyapa_irq_handler)(struct cyapa *);
+       bool (*cyapa_irq_cmd_handler)(struct cyapa *);
+       int (*cyapa_sort_empty_output_data)(struct cyapa *,
+                       u8 *, int *, cb_sort);
+
+       int (*cyapa_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;
+
+       /* 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;
+
+       struct mutex state_sync_lock;
+       bool in_syncing;
+
+       /* record irq disabled/enable state. */
+       struct mutex irq_state_lock;
+       bool irq_enabled;
+       bool prev_irq_enabled;
+
+       const struct cyapa_dev_ops *ops;
+};
+
+
+void cyapa_enable_irq(struct cyapa *cyapa);
+void cyapa_disable_irq(struct cyapa *cyapa);
+void cyapa_enable_irq_save(struct cyapa *cyapa);
+void cyapa_disable_irq_save(struct cyapa *cyapa);
+void cyapa_irq_restore(struct cyapa *cyapa);
+bool cyapa_is_irq_enabled(struct cyapa *cyapa);
+
+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 u8 *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
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.

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 23878 bytes --]

^ permalink raw reply related

* [PATCH v2 2/14] input: cyapa: add cyapa driver power management interfaces supported
From: Dudley Du @ 2014-06-06  7:28 UTC (permalink / raw)
  To: Dmitry Torokhov, Rafael J. Wysocki, Alan Stern
  Cc: Benson Leung, Lily Rui, Daniel Kurtz,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 4581 bytes --]

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 Chomebooks.

Signed-off-by: Du, Dudley <dudl@cypress.com>
---
diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index d5adee8..1dfc16d 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -462,6 +462,10 @@ static void cyapa_detect(struct cyapa *cyapa)
 }

 /*
+ * Sysfs Interface.
+ */
+
+/*
  * cyapa_sleep_time_to_pwr_cmd and cyapa_pwr_cmd_to_sleep_time
  *
  * These are helper functions that convert to and from integer idle
@@ -495,6 +499,81 @@ 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;
+
+       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);
+               else
+                       sleep_time = cyapa->suspend_sleep_time;
+               len = scnprintf(buf, PAGE_SIZE, "%u\n", sleep_time);
+       }
+
+       return len;
+}
+
+static int cyapa_sleep_time_check(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;
+
+       if (buf == NULL || count == 0)
+               goto invalidparam;
+
+       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_sleep_time_check(sleep_time);
+               cyapa->suspend_power_mode =
+                       cyapa_sleep_time_to_pwr_cmd(cyapa->suspend_sleep_time);
+       } else
+               goto invalidparam;
+
+       return count;
+
+invalidparam:
+       dev_err(dev, "invalid suspend scanrate ms parameters\n");
+       return -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;
@@ -575,6 +654,12 @@ static int cyapa_probe(struct i2c_client *client,
        }
        cyapa_disable_irq(cyapa);

+#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;

@@ -590,6 +675,9 @@ static int cyapa_remove(struct i2c_client *client)
 {
        struct cyapa *cyapa = i2c_get_clientdata(client);

+#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);
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.

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 5693 bytes --]

^ permalink raw reply related

* [PATCH v2 4/14] input: cyapa: add cyapa key function interfaces in sysfs system
From: Dudley Du @ 2014-06-06  7:28 UTC (permalink / raw)
  To: Dmitry Torokhov, Rafael J. Wysocki, Alan Stern
  Cc: Benson Leung, Lily Rui, Daniel Kurtz,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 9932 bytes --]

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 Chomebooks.

Signed-off-by: Du, Dudley <dudl@cypress.com>
---
diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index c2b67d3..3b80de6 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -190,6 +190,17 @@ void cyapa_default_irq_handler(struct cyapa *cyapa)
 const struct cyapa_dev_ops cyapa_default_ops = {
        NULL,
        NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+
+       NULL,
+       NULL,
+
+       NULL,
+       NULL,

        NULL,
        NULL,
@@ -470,6 +481,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->cyapa_check_fw) {
+               ret = cyapa->ops->cyapa_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 = -EPERM;
+               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->cyapa_bl_enter) {
+               ret = cyapa->ops->cyapa_bl_enter(cyapa);
+               if (ret)
+                       goto err_detect;
+       }
+
+       if (cyapa->ops->cyapa_bl_activate) {
+               ret = cyapa->ops->cyapa_bl_activate(cyapa);
+               if (ret)
+                       goto err_detect;
+       }
+
+       if (cyapa->ops->cyapa_bl_initiate) {
+               ret = cyapa->ops->cyapa_bl_initiate(cyapa, fw);
+               if (ret)
+                       goto err_detect;
+       }
+
+       if (cyapa->ops->cyapa_update_fw) {
+               ret = cyapa->ops->cyapa_update_fw(cyapa, fw);
+               if (ret)
+                       goto err_detect;
+       }
+
+       if (cyapa->ops->cyapa_bl_verify_app_integrity) {
+               ret = cyapa->ops->cyapa_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.
  */
@@ -656,6 +739,127 @@ 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);
+
+       if (!cyapa_state_sync_enter(cyapa))
+               return -EBUSY;
+
+       ret = scnprintf(buf, PAGE_SIZE, "%d.%d\n", cyapa->fw_maj_ver,
+                        cyapa->fw_min_ver);
+       cyapa_state_sync_exit(cyapa);
+       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);
+
+       if (!cyapa_state_sync_enter(cyapa))
+               return -EBUSY;
+
+       ret = scnprintf(buf, PAGE_SIZE, "%s\n", cyapa->product_id);
+       cyapa_state_sync_exit(cyapa);
+       return ret;
+}
+
+static ssize_t cyapa_update_fw_store(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+       struct cyapa *cyapa = dev_get_drvdata(dev);
+       const char *fw_name;
+       int ret;
+
+       /* Do not allow paths that step out of /lib/firmware  */
+       if (strstr(buf, "../") != NULL)
+               return -EINVAL;
+
+       fw_name = !strncmp(buf, "1", count) ||
+                 !strncmp(buf, "1\n", count) ? CYAPA_FW_NAME : buf;
+
+       if (!cyapa_state_sync_enter(cyapa))
+               return -EBUSY;
+
+       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");
+
+       cyapa_state_sync_exit(cyapa);
+
+       /* 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;
+
+       if (!cyapa_state_sync_enter(cyapa))
+               return -EBUSY;
+
+       if (!cyapa->ops->cyapa_calibrate_store) {
+               cyapa_state_sync_exit(cyapa);
+               dev_err(dev, "Calibrate operation not permitted.\n");
+               return -EPERM;
+       }
+       ret = cyapa->ops->cyapa_calibrate_store(dev, attr, buf, count);
+
+       cyapa_state_sync_exit(cyapa);
+       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;
+
+       if (!cyapa_state_sync_enter(cyapa))
+               return -EBUSY;
+
+       if (!cyapa->ops->cyapa_show_baseline) {
+               cyapa_state_sync_exit(cyapa);
+               dev_err(dev, "Calibrate operation not permitted.\n");
+               return -EPERM;
+       }
+       ret = cyapa->ops->cyapa_show_baseline(dev, attr, buf);
+
+       cyapa_state_sync_exit(cyapa);
+       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;
@@ -740,6 +944,9 @@ static int cyapa_probe(struct i2c_client *client,
        }
        cyapa_disable_irq(cyapa);

+       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))
@@ -762,6 +969,7 @@ static int cyapa_remove(struct i2c_client *client)
        struct cyapa *cyapa = i2c_get_clientdata(client);

        pm_runtime_disable(&client->dev);
+       sysfs_remove_group(&client->dev.kobj, &cyapa_sysfs_group);

 #ifdef CONFIG_PM_SLEEP
        sysfs_unmerge_group(&client->dev.kobj, &cyapa_power_wakeup_group);
diff --git a/drivers/input/mouse/cyapa.h b/drivers/input/mouse/cyapa.h
index 91fb84a..3e72fca 100644
--- a/drivers/input/mouse/cyapa.h
+++ b/drivers/input/mouse/cyapa.h
@@ -160,6 +160,19 @@ struct cyapa;
 typedef bool (*cb_sort)(struct cyapa *, u8 *, int);

 struct cyapa_dev_ops {
+       int (*cyapa_check_fw)(struct cyapa *, const struct firmware *);
+       int (*cyapa_bl_enter)(struct cyapa *);
+       int (*cyapa_bl_activate)(struct cyapa *);
+       int (*cyapa_bl_initiate)(struct cyapa *, const struct firmware *);
+       int (*cyapa_update_fw)(struct cyapa *, const struct firmware *);
+       int (*cyapa_bl_verify_app_integrity)(struct cyapa *);
+       int (*cyapa_bl_deactivate)(struct cyapa *);
+
+       ssize_t (*cyapa_show_baseline)(struct device *,
+                       struct device_attribute *, char *);
+       ssize_t (*cyapa_calibrate_store)(struct device *,
+                       struct device_attribute *, const char *, size_t);
+
        size_t (*cyapa_get_private_size)(void);
        int (*cyapa_private_init)(struct cyapa *cyapa, void *private_mem);

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.

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 7100 bytes --]

^ permalink raw reply related

* [PATCH v2 5/14] input: cyapa: add read firmware image and raw data interfaces in debugfs system
From: Dudley Du @ 2014-06-06  7:28 UTC (permalink / raw)
  To: Dmitry Torokhov, Rafael J. Wysocki, Alan Stern
  Cc: Benson Leung, Lily Rui, Daniel Kurtz,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 9450 bytes --]

Add read_fw and raw_data debugfs interfaces for easier issues location
and collection when report by user.
TEST=test on Chomebooks.

Signed-off-by: Du, Dudley <dudl@cypress.com>
---
diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index 3b80de6..b5dc9f9 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -39,6 +39,9 @@

 const char unique_str[] = "CYTRA";

+/* global root node of the cyapa debugfs directory. */
+static struct dentry *cyapa_debugfs_root;
+

 void cyapa_enable_irq(struct cyapa *cyapa)
 {
@@ -205,6 +208,9 @@ const struct cyapa_dev_ops cyapa_default_ops = {
        NULL,
        NULL,

+       NULL,
+       NULL,
+
        cyapa_default_irq_handler,
        NULL,
        NULL,
@@ -554,6 +560,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 (!kobject_get(&cyapa->client->dev.kobj)) {
+               ret = -ENODEV;
+               goto out;
+       }
+
+       file->private_data = cyapa;
+
+       if (cyapa->read_fw_image) {
+               ret = 0;
+               goto out;
+       }
+
+       if (!cyapa_state_sync_enter(cyapa))
+               return -EBUSY;
+       /*
+        * 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->cyapa_read_fw)
+               ret = cyapa->ops->cyapa_read_fw(cyapa);
+       else
+               ret = -EPERM;
+       cyapa_state_sync_exit(cyapa);
+
+       /* 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;
+       kobject_put(&cyapa->client->dev.kobj);
+       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->read_fw_image)
+               return -EINVAL;
+
+       if (*ppos >= cyapa->read_fw_image_size)
+               return 0;
+
+       if (count + *ppos > cyapa->read_fw_image_size)
+               count = cyapa->read_fw_image_size - *ppos;
+
+       if (copy_to_user(buffer, &cyapa->read_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;
+
+       ret = mutex_lock_interruptible(&cyapa->debugfs_mutex);
+       if (ret)
+               return ret;
+
+       if (!kobject_get(&cyapa->client->dev.kobj)) {
+               ret = -ENODEV;
+               goto out;
+       }
+
+       file->private_data = cyapa;
+
+       if (!cyapa_state_sync_enter(cyapa)) {
+               ret = -EBUSY;
+               goto out;
+       }
+       if (cyapa->ops->cyapa_read_raw_data)
+               ret = cyapa->ops->cyapa_read_raw_data(cyapa);
+       else
+               ret = -EPERM;
+       cyapa_state_sync_exit(cyapa);
+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;
+       kobject_put(&cyapa->client->dev.kobj);
+       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.
  */

@@ -947,6 +1152,13 @@ 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");

+       /* 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;
+       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))
@@ -978,8 +1190,19 @@ static int cyapa_remove(struct i2c_client *client)
 #ifdef CONFIG_PM_RUNTIME
        sysfs_unmerge_group(&client->dev.kobj, &cyapa_power_runtime_group);
 #endif
+
+       kfree(cyapa->read_fw_image);
+       cyapa->read_fw_image = NULL;
+       cyapa->read_fw_image_size = 0;
+       kfree(cyapa->tp_raw_data);
+       cyapa->tp_raw_data = NULL;
+       cyapa->tp_raw_data_size = 0;
        free_irq(cyapa->irq, cyapa);

+       debugfs_remove_recursive(cyapa->dentry_dev);
+       debugfs_remove_recursive(cyapa_debugfs_root);
+       mutex_destroy(&cyapa->debugfs_mutex);
+
        input_unregister_device(cyapa->input);
        if (cyapa->ops->cyapa_set_power_mode)
                cyapa->ops->cyapa_set_power_mode(cyapa, PWR_MODE_OFF, 0);
diff --git a/drivers/input/mouse/cyapa.h b/drivers/input/mouse/cyapa.h
index 3e72fca..319f19d 100644
--- a/drivers/input/mouse/cyapa.h
+++ b/drivers/input/mouse/cyapa.h
@@ -173,6 +173,9 @@ struct cyapa_dev_ops {
        ssize_t (*cyapa_calibrate_store)(struct device *,
                        struct device_attribute *, const char *, size_t);

+       int (*cyapa_read_fw)(struct cyapa *);
+       int (*cyapa_read_raw_data)(struct cyapa *);
+
        size_t (*cyapa_get_private_size)(void);
        int (*cyapa_private_init)(struct cyapa *cyapa, void *private_mem);

@@ -244,6 +247,17 @@ struct cyapa {
        bool irq_enabled;
        bool prev_irq_enabled;

+       /* per-instance debugfs root */
+       struct dentry *dentry_dev;
+
+       /* Buffer to store firmware read using debugfs */
+       struct mutex debugfs_mutex;
+       u8 *read_fw_image;
+       size_t read_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;
 };

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.

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 6972 bytes --]

^ permalink raw reply related

* [PATCH v2 6/14] input: cyapa: add gen3 trackpad device basic functions supported
From: Dudley Du @ 2014-06-06  7:28 UTC (permalink / raw)
  To: Dmitry Torokhov, Rafael J. Wysocki, Alan Stern
  Cc: Benson Leung, Lily Rui, Daniel Kurtz,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 33817 bytes --]

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 Chomebooks.

Signed-off-by: Du, Dudley <dudl@cypress.com>
---
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index d8948df..cc2927b 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -35,5 +35,5 @@ 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 b5dc9f9..3f870e5 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -185,6 +185,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.cyapa_irq_cmd_handler)
+               cont = cyapa_gen3_ops.cyapa_irq_cmd_handler(cyapa);
+       if (!cont)
+               return;
+
        /* do redetecting when device states is still unknown and
         * interrupt envent is received from device. */
        async_schedule(cyapa_detect_async, cyapa);
@@ -345,6 +354,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;
@@ -409,9 +421,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 retires = 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.cyapa_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, 0x00, 2, cmd);
+                       if (ret)
+                               goto error;
+
+                       msleep(50);
+
+                       ret = cyapa_i2c_read(cyapa, BL_HEAD_OFFSET,
+                                       BL_STATUS_SIZE, status);
+                       if (ret != BL_STATUS_SIZE)
+                               goto error;
+               }
+       } while (--retires > 0 && !smbus);
+
+       goto error;
+
+out_detected:
+       return 0;
+
+error:
+       return (ret < 0) ? ret : -EAGAIN;
 }

 /*
@@ -1095,6 +1183,8 @@ static int cyapa_probe(struct i2c_client *client,
        struct cyapa *cyapa;
        struct device *dev = &client->dev;
        union i2c_smbus_data dummy;
+       int private_size;
+       void *private_mem;

        adapter_func = cyapa_check_adapter_functionality(client);
        if (adapter_func == CYAPA_ADAPTER_FUNC_NONE) {
@@ -1107,7 +1197,10 @@ static int cyapa_probe(struct i2c_client *client,
                        I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &dummy) < 0)
                return -ENODEV;

-       cyapa = kzalloc(sizeof(struct cyapa), GFP_KERNEL);
+       private_size = 0;
+       if (cyapa_gen3_ops.cyapa_get_private_size)
+               private_size += cyapa_gen3_ops.cyapa_get_private_size();
+       cyapa = kzalloc(sizeof(struct cyapa) + private_size, GFP_KERNEL);
        if (!cyapa) {
                dev_err(dev, "allocate memory for cyapa failed\n");
                return -ENOMEM;
@@ -1118,6 +1211,13 @@ static int cyapa_probe(struct i2c_client *client,
        sprintf(cyapa->phys, "i2c-%d-%04x/input0", client->adapter->nr,
                client->addr);

+       private_mem = (void *)cyapa + sizeof(struct cyapa);
+       ret = 0;
+       if (cyapa_gen3_ops.cyapa_private_init)
+               ret = cyapa_gen3_ops.cyapa_private_init(cyapa, private_mem);
+       if (ret)
+               goto err_unregister_device;
+
        cyapa->ops = &cyapa_default_ops;
        cyapa->in_syncing = false;
        mutex_init(&cyapa->state_sync_lock);
diff --git a/drivers/input/mouse/cyapa.h b/drivers/input/mouse/cyapa.h
index 319f19d..7bd27b7 100644
--- a/drivers/input/mouse/cyapa.h
+++ b/drivers/input/mouse/cyapa.h
@@ -292,5 +292,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..5345a9e
--- /dev/null
+++ b/drivers/input/mouse/cyapa_gen3.c
@@ -0,0 +1,734 @@
+/*
+ * 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-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/module.h>
+#include <linux/slab.h>
+#include "cyapa.h"
+
+
+#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
+
+
+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;
+};
+
+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 },
+       { REG_OFFSET_MAX_BASELINE, 1 },
+       { REG_OFFSET_MIN_BASELINE, 1 },
+};
+
+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 },
+       { CYAPA_SMBUS_MAX_BASELINE, 1 },
+       { CYAPA_SMBUS_MIN_BASELINE, 1 },
+};
+
+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);
+}
+
+ssize_t cyapa_i2c_reg_write_block(struct cyapa *cyapa, u8 reg,
+                                        size_t len, const u8 *values)
+{
+       return i2c_smbus_write_i2c_block_data(cyapa->client, reg, len, values);
+}
+
+/*
+ * cyapa_smbus_read_block - perform smbus block read command
+ * @cyapa  - private data structure of the driver
+ * @cmd    - the properly encoded smbus command
+ * @len    - expected length of smbus command result
+ * @values - buffer to store smbus command result
+ *
+ * Returns negative errno, else the number of bytes written.
+ *
+ * Note:
+ * In trackpad device, the memory block allocated for I2C register map
+ * is 256 bytes, so the max read block for I2C bus is 256 bytes.
+ */
+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);
+       } 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);
+       }
+}
+
+
+/*
+ * Determine the Gen3 trackpad device's current operating state.
+ *
+ */
+static int cyapa_gen3_state_parse(struct cyapa *cyapa, u8 *reg_data, int len)
+{
+       cyapa->state = CYAPA_STATE_NO_DEVICE;
+
+       /* Parse based on Gen3 characteristic regiters and bits */
+       if (reg_data[0] == 0x00 && reg_data[2] == 0x00 &&
+               (reg_data[1] == 0x11 || reg_data[1] == 0x10)) {
+               /* normal state after power on or reset,
+                * reg_data[1] == 0x11, firmware image checksum is valid.
+                * reg_data[1] == 0x10, firmware image checksum is invalid. */
+               cyapa->gen = CYAPA_GEN3;
+               cyapa->state = CYAPA_STATE_BL_IDLE;
+       } else if (reg_data[0] == 0x00 &&
+               (reg_data[1] & 0x10) == 0x10) {
+               cyapa->gen = CYAPA_GEN3;
+               if (reg_data[1] & BL_STATUS_BUSY) {
+                       cyapa->state = CYAPA_STATE_BL_BUSY;
+               } else {
+                       if ((reg_data[2] & 0x20) == 0x00)
+                               cyapa->state = CYAPA_STATE_BL_IDLE;
+                       else
+                               cyapa->state = CYAPA_STATE_BL_ACTIVE;
+               }
+       } else if ((reg_data[0] & 0x80) && (reg_data[1] & 0x08)) {
+               /* normal state when running in operaitonal mode,
+                * may also not in full power state or
+                * busying in command process. */
+               if (((reg_data[1] >> 4) & 0x07) <= 5) {
+                       /* only finger number data is valid. */
+                       cyapa->gen = CYAPA_GEN3;
+                       cyapa->state = CYAPA_STATE_OP;
+               }
+       } else if (reg_data[0] == 0x0C && reg_data[1] == 0x08) {
+               /* Op state when first two registers overwritten with 0x00 */
+               cyapa->gen = CYAPA_GEN3;
+               cyapa->state = CYAPA_STATE_OP;
+       } else if (reg_data[1] & (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 reverved)
+{
+       int ret;
+       u8 power;
+       int tries = SET_POWER_MODE_TRIES;
+       u16 sleep_time;
+
+       /* Specific parameter for Gen4 and later trackpad devices.
+        * Avoid compile warning.
+        */
+       reverved = 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;
+}
+
+/*
+ * 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:
+               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;
+               }
+               return 0;
+
+       default:
+               return -EIO;
+       }
+       return 0;
+}
+
+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 = {
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+
+       NULL,
+       NULL,
+
+       NULL,
+       NULL,
+
+       NULL,
+       NULL,
+
+       cyapa_gen3_state_parse,
+       cyapa_gen3_do_operational_check,
+
+       cyapa_gen3_irq_handler,
+       NULL,
+       NULL,
+       cyapa_gen3_set_power_mode,
+};
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.

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 15657 bytes --]

^ permalink raw reply related

* [PATCH v2 7/14] input: cyapa: add gen3 trackpad device firmware update function supported
From: Dudley Du @ 2014-06-06  7:29 UTC (permalink / raw)
  To: Dmitry Torokhov, Rafael J. Wysocki, Alan Stern
  Cc: Benson Leung, Lily Rui, Daniel Kurtz,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 10866 bytes --]

Add firmware image update function supported for gen3 trackpad device,
which its function is supplied through cyapa core update_fw interface.
TEST=test on Chomebooks.

Signed-off-by: Du, Dudley <dudl@cypress.com>
---
diff --git a/drivers/input/mouse/cyapa_gen3.c b/drivers/input/mouse/cyapa_gen3.c
index 5345a9e..a3e1e72 100644
--- a/drivers/input/mouse/cyapa_gen3.c
+++ b/drivers/input/mouse/cyapa_gen3.c
@@ -392,6 +392,78 @@ static int cyapa_gen3_state_parse(struct cyapa *cyapa, u8 *reg_data, int len)
        return -EAGAIN;
 }

+/*
+ * Enter bootloader by soft resetting the device.
+ *
+ * If device is already in the bootloader, the function just returns.
+ * Otherwise, reset the device; after reset, device enters bootloader idle
+ * state immediately.
+ *
+ * Also, if device was unregister device from input core.  Device will
+ * re-register after it is detected following resumption of operational mode.
+ *
+ * Returns:
+ *   0 on success
+ *   -EAGAIN  device was reset, but is not now in bootloader idle state
+ *   < 0 if the device never responds within the timeout
+ */
+static int cyapa_gen3_bl_enter(struct cyapa *cyapa)
+{
+       int ret;
+
+       if (cyapa->input) {
+               cyapa_disable_irq(cyapa);
+               input_unregister_device(cyapa->input);
+               cyapa->input = NULL;
+       }
+
+       ret = cyapa_poll_state(cyapa, 500);
+       if (ret < 0)
+               return ret;
+       if (cyapa->state == CYAPA_STATE_BL_IDLE) {
+               /* Already in BL_IDLE. Skipping exit. */
+               return 0;
+       }
+
+       if (cyapa->state != CYAPA_STATE_OP)
+               return -EAGAIN;
+
+       cyapa->state = CYAPA_STATE_NO_DEVICE;
+       ret = cyapa_write_byte(cyapa, CYAPA_CMD_SOFT_RESET, 0x01);
+       if (ret < 0)
+               return -EIO;
+
+       usleep_range(25000, 50000);
+       ret = cyapa_poll_state(cyapa, 500);
+       if (ret < 0)
+               return ret;
+       if ((cyapa->state != CYAPA_STATE_BL_IDLE) ||
+               (cyapa->status[REG_BL_STATUS] & BL_STATUS_WATCHDOG))
+               return -EAGAIN;
+
+       return 0;
+}
+
+static int cyapa_gen3_bl_activate(struct cyapa *cyapa)
+{
+       int ret;
+
+       ret = cyapa_i2c_reg_write_block(cyapa, 0, sizeof(bl_activate),
+                                       bl_activate);
+       if (ret < 0)
+               return ret;
+
+       /* Wait for bootloader to activate; takes between 2 and 12 seconds */
+       msleep(2000);
+       ret = cyapa_poll_state(cyapa, 11000);
+       if (ret < 0)
+               return ret;
+       if (cyapa->state != CYAPA_STATE_BL_ACTIVE)
+               return -EAGAIN;
+
+       return 0;
+}
+
 static int cyapa_gen3_bl_deactivate(struct cyapa *cyapa)
 {
        int ret;
@@ -452,6 +524,206 @@ static int cyapa_gen3_bl_exit(struct cyapa *cyapa)
        return 0;
 }

+/* Used in gen3 bootloader commands. */
+static u16 cyapa_gen3_csum(const u8 *buf, size_t count)
+{
+       int i;
+       u16 csum = 0;
+
+       for (i = 0; i < count; i++)
+               csum += buf[i];
+
+       return csum;
+}
+
+/*
+ * Verify the integrity of a CYAPA firmware image file.
+ *
+ * The firmware image file is 30848 bytes, composed of 482 64-byte blocks.
+ *
+ * The first 2 blocks are the firmware header.
+ * The next 480 blocks are the firmware image.
+ *
+ * The first two bytes of the header hold the header checksum, computed by
+ * summing the other 126 bytes of the header.
+ * The last two bytes of the header hold the firmware image checksum, computed
+ * by summing the 30720 bytes of the image modulo 0xffff.
+ *
+ * Both checksums are stored little-endian.
+ */
+static int cyapa_gen3_check_fw(struct cyapa *cyapa, const struct firmware *fw)
+{
+       struct device *dev = &cyapa->client->dev;
+       u16 csum;
+       u16 csum_expected;
+
+       /* Firmware must match exact 30848 bytes = 482 64-byte blocks. */
+       if (fw->size != CYAPA_FW_SIZE) {
+               dev_err(dev, "invalid firmware size = %zu, expected %u.\n",
+                       fw->size, CYAPA_FW_SIZE);
+               return -EINVAL;
+       }
+
+       /* Verify header block */
+       csum_expected = (fw->data[0] << 8) | fw->data[1];
+       csum = cyapa_gen3_csum(&fw->data[2], CYAPA_FW_HDR_SIZE - 2);
+       if (csum != csum_expected) {
+               dev_err(dev, "%s %04x, expected: %04x\n",
+                       "invalid firmware header checksum = ",
+                       csum, csum_expected);
+               return -EINVAL;
+       }
+
+       /* Verify firmware image */
+       csum_expected = (fw->data[CYAPA_FW_HDR_SIZE - 2] << 8) |
+                        fw->data[CYAPA_FW_HDR_SIZE - 1];
+       csum = cyapa_gen3_csum(&fw->data[CYAPA_FW_HDR_SIZE],
+                       CYAPA_FW_DATA_SIZE);
+       if (csum != csum_expected) {
+               dev_err(dev, "%s %04x, expected: %04x\n",
+                       "invalid firmware header checksum = ",
+                       csum, csum_expected);
+               return -EINVAL;
+       }
+       return 0;
+}
+
+/*
+ * Write a |len| byte long buffer |buf| to the device, by chopping it up into a
+ * sequence of smaller |CYAPA_CMD_LEN|-length write commands.
+ *
+ * The data bytes for a write command are prepended with the 1-byte offset
+ * of the data relative to the start of |buf|.
+ */
+static int cyapa_gen3_write_buffer(struct cyapa *cyapa,
+               const u8 *buf, size_t len)
+{
+       int ret;
+       size_t i;
+       unsigned char cmd[CYAPA_CMD_LEN + 1];
+       size_t cmd_len;
+
+       for (i = 0; i < len; i += CYAPA_CMD_LEN) {
+               const u8 *payload = &buf[i];
+               cmd_len = (len - i >= CYAPA_CMD_LEN) ? CYAPA_CMD_LEN : len - i;
+               cmd[0] = i;
+               memcpy(&cmd[1], payload, cmd_len);
+
+               ret = cyapa_i2c_reg_write_block(cyapa, 0, cmd_len + 1, cmd);
+               if (ret < 0)
+                       return ret;
+       }
+       return 0;
+}
+
+/*
+ * A firmware block write command writes 64 bytes of data to a single flash
+ * page in the device.  The 78-byte block write command has the format:
+ *   <0xff> <CMD> <Key> <Start> <Data> <Data-Checksum> <CMD Checksum>
+ *
+ *  <0xff>  - every command starts with 0xff
+ *  <CMD>   - the write command value is 0x39
+ *  <Key>   - write commands include an 8-byte key: { 00 01 02 03 04 05 06 07 }
+ *  <Block> - Memory Block number (address / 64) (16-bit, big-endian)
+ *  <Data>  - 64 bytes of firmware image data
+ *  <Data Checksum> - sum of 64 <Data> bytes, modulo 0xff
+ *  <CMD Checksum> - sum of 77 bytes, from 0xff to <Data Checksum>
+ *
+ * Each write command is split into 5 i2c write transactions of up to 16 bytes.
+ * Each transaction starts with an i2c register offset: (00, 10, 20, 30, 40).
+ */
+static int cyapa_gen3_write_fw_block(struct cyapa *cyapa,
+               u16 block, const u8 *data)
+{
+       int ret;
+       u8 cmd[78];
+       u8 status[BL_STATUS_SIZE];
+       /* Programming for one block can take about 100ms. */
+       int tries = 11;
+       u8 bl_status, bl_error;
+
+       /* set write command and security key bytes. */
+       cmd[0] = 0xff;
+       cmd[1] = 0x39;
+       cmd[2] = 0x00;
+       cmd[3] = 0x01;
+       cmd[4] = 0x02;
+       cmd[5] = 0x03;
+       cmd[6] = 0x04;
+       cmd[7] = 0x05;
+       cmd[8] = 0x06;
+       cmd[9] = 0x07;
+       cmd[10] = block >> 8;
+       cmd[11] = block;
+       memcpy(&cmd[12], data, CYAPA_FW_BLOCK_SIZE);
+       cmd[76] = cyapa_gen3_csum(data, CYAPA_FW_BLOCK_SIZE);
+       cmd[77] = cyapa_gen3_csum(cmd, sizeof(cmd) - 1);
+
+       ret = cyapa_gen3_write_buffer(cyapa, cmd, sizeof(cmd));
+       if (ret)
+               return ret;
+
+       /* wait for write to finish */
+       do {
+               usleep_range(10000, 20000);
+
+               /* check block write command result status. */
+               ret = cyapa_i2c_reg_read_block(cyapa, BL_HEAD_OFFSET,
+                                              BL_STATUS_SIZE, status);
+               if (ret != BL_STATUS_SIZE)
+                       return (ret < 0) ? ret : -EIO;
+       } while ((status[1] & BL_STATUS_BUSY) && --tries);
+
+       /* ignore WATCHDOG bit and reserved bits. */
+       bl_status = status[1] & ~BL_STATUS_REV_MASK;
+       bl_error = status[2] & ~BL_ERROR_RESERVED;
+
+       if (status[1] & BL_STATUS_BUSY)
+               ret = -ETIMEDOUT;
+       else if (bl_status != BL_STATUS_RUNNING ||
+               bl_error != BL_ERROR_BOOTLOADING)
+               ret = -EIO;
+       else
+               ret = 0;
+
+       return ret;
+}
+
+static int cyapa_gen3_do_fw_update(struct cyapa *cyapa,
+               const struct firmware *fw)
+{
+       struct device *dev = &cyapa->client->dev;
+       int ret;
+       int i;
+
+       /* First write data, starting at byte 128  of fw->data */
+       for (i = 0; i < CYAPA_FW_DATA_BLOCK_COUNT; i++) {
+               size_t block = CYAPA_FW_DATA_BLOCK_START + i;
+               size_t addr = (i + CYAPA_FW_HDR_BLOCK_COUNT) *
+                               CYAPA_FW_BLOCK_SIZE;
+               const u8 *data = &fw->data[addr];
+               ret = cyapa_gen3_write_fw_block(cyapa, block, data);
+               if (ret) {
+                       dev_err(dev, "FW update aborted, %d\n", ret);
+                       return ret;
+               }
+       }
+
+       /* Then write checksum */
+       for (i = 0; i < CYAPA_FW_HDR_BLOCK_COUNT; i++) {
+               size_t block = CYAPA_FW_HDR_BLOCK_START + i;
+               size_t addr = i * CYAPA_FW_BLOCK_SIZE;
+               const u8 *data = &fw->data[addr];
+               ret = cyapa_gen3_write_fw_block(cyapa, block, data);
+               if (ret) {
+                       dev_err(dev, "FW update aborted, %d\n", ret);
+                       return ret;
+               }
+       }
+
+       return 0;
+}
+
 /*
  * cyapa_get_wait_time_for_pwr_cmd
  *
@@ -707,13 +979,13 @@ static void cyapa_gen3_irq_handler(struct cyapa *cyapa)


 const struct cyapa_dev_ops cyapa_gen3_ops = {
+       cyapa_gen3_check_fw,
+       cyapa_gen3_bl_enter,
+       cyapa_gen3_bl_activate,
        NULL,
+       cyapa_gen3_do_fw_update,
        NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
+       cyapa_gen3_bl_deactivate,

        NULL,
        NULL,
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.

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 8018 bytes --]

^ permalink raw reply related

* [PATCH v2 8/14] input: cyapa: add gen3 trackpad device baseline and calibrate functions supported
From: Dudley Du @ 2014-06-06  7:29 UTC (permalink / raw)
  To: Dmitry Torokhov, Rafael J. Wysocki, Alan Stern
  Cc: Benson Leung, Lily Rui, Daniel Kurtz,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 5637 bytes --]

Add report baseline and force calibrate functions supported for gen3
trackpad device, which these functions are supplied through
cyapa core baseline and calibrate interfaces.
TEST=test on Chomebooks.

Signed-off-by: Du, Dudley <dudl@cypress.com>
---
diff --git a/drivers/input/mouse/cyapa_gen3.c b/drivers/input/mouse/cyapa_gen3.c
index a3e1e72..9ffdbc1 100644
--- a/drivers/input/mouse/cyapa_gen3.c
+++ b/drivers/input/mouse/cyapa_gen3.c
@@ -724,6 +724,138 @@ static int cyapa_gen3_do_fw_update(struct cyapa *cyapa,
        return 0;
 }

+static ssize_t cyapa_gen3_do_calibrate(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+       struct cyapa *cyapa = dev_get_drvdata(dev);
+       int tries = 20;  /* max recalibration timeout 2s. */
+       int ret;
+
+       cyapa_disable_irq(cyapa);
+
+       ret = cyapa_read_byte(cyapa, CYAPA_CMD_DEV_STATUS);
+       if (ret < 0) {
+               dev_err(dev, "Error reading dev status. err = %d\n", ret);
+               goto out;
+       }
+       if ((ret & CYAPA_DEV_NORMAL) != CYAPA_DEV_NORMAL) {
+               dev_warn(dev, "Trackpad device is busy. device state = 0x%x\n",
+                        ret);
+               ret = -EAGAIN;
+               goto out;
+       }
+
+       ret = cyapa_write_byte(cyapa, CYAPA_CMD_SOFT_RESET,
+                              OP_RECALIBRATION_MASK);
+       if (ret < 0) {
+               dev_err(dev, "Failed to send calibrate command. ret = %d\n",
+                       ret);
+               goto out;
+       }
+
+       do {
+               /*
+                * For this recalibration, the max time will not exceed 2s.
+                * The average time is approximately 500 - 700 ms, and we
+                * will check the status every 100 - 200ms.
+                */
+               usleep_range(100000, 200000);
+
+               ret = cyapa_read_byte(cyapa, CYAPA_CMD_DEV_STATUS);
+               if (ret < 0) {
+                       dev_err(dev, "Error reading dev status. err = %d\n",
+                               ret);
+                       goto out;
+               }
+               if ((ret & CYAPA_DEV_NORMAL) == CYAPA_DEV_NORMAL)
+                       break;
+       } while (--tries);
+
+       if (tries == 0) {
+               dev_err(dev, "Failed to calibrate. Timeout.\n");
+               ret = -ETIMEDOUT;
+               goto out;
+       }
+       dev_dbg(dev, "Calibration successful.\n");
+
+out:
+       cyapa_enable_irq(cyapa);
+       return ret < 0 ? ret : count;
+}
+
+static ssize_t cyapa_gen3_show_baseline(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       struct cyapa *cyapa = dev_get_drvdata(dev);
+       int max_baseline, min_baseline;
+       int tries = 3;
+       int ret;
+
+       cyapa_disable_irq(cyapa);
+
+       ret = cyapa_read_byte(cyapa, CYAPA_CMD_DEV_STATUS);
+       if (ret < 0) {
+               dev_err(dev, "Error reading dev status. err = %d\n", ret);
+               goto out;
+       }
+       if ((ret & CYAPA_DEV_NORMAL) != CYAPA_DEV_NORMAL) {
+               dev_warn(dev, "Trackpad device is busy. device state = 0x%x\n",
+                        ret);
+               ret = -EAGAIN;
+               goto out;
+       }
+
+       ret = cyapa_write_byte(cyapa, CYAPA_CMD_SOFT_RESET,
+                              OP_REPORT_BASELINE_MASK);
+       if (ret < 0) {
+               dev_err(dev, "Failed to send report baseline command. %d\n",
+                       ret);
+               goto out;
+       }
+
+       do {
+               usleep_range(10000, 20000);
+
+               ret = cyapa_read_byte(cyapa, CYAPA_CMD_DEV_STATUS);
+               if (ret < 0) {
+                       dev_err(dev, "Error reading dev status. err = %d\n",
+                               ret);
+                       goto out;
+               }
+               if ((ret & CYAPA_DEV_NORMAL) == CYAPA_DEV_NORMAL)
+                       break;
+       } while (--tries);
+
+       if (tries == 0) {
+               dev_err(dev, "Device timed out going to Normal state.\n");
+               ret = -ETIMEDOUT;
+               goto out;
+       }
+
+       ret = cyapa_read_byte(cyapa, CYAPA_CMD_MAX_BASELINE);
+       if (ret < 0) {
+               dev_err(dev, "Failed to read max baseline. err = %d\n", ret);
+               goto out;
+       }
+       max_baseline = ret;
+
+       ret = cyapa_read_byte(cyapa, CYAPA_CMD_MIN_BASELINE);
+       if (ret < 0) {
+               dev_err(dev, "Failed to read min baseline. err = %d\n", ret);
+               goto out;
+       }
+       min_baseline = ret;
+
+       dev_dbg(dev, "Baseline report successful. Max: %d Min: %d\n",
+               max_baseline, min_baseline);
+       ret = scnprintf(buf, PAGE_SIZE, "%d %d\n", max_baseline, min_baseline);
+
+out:
+       cyapa_enable_irq(cyapa);
+       return ret;
+}
+
 /*
  * cyapa_get_wait_time_for_pwr_cmd
  *
@@ -987,8 +1119,8 @@ const struct cyapa_dev_ops cyapa_gen3_ops = {
        NULL,
        cyapa_gen3_bl_deactivate,

-       NULL,
-       NULL,
+       cyapa_gen3_show_baseline,
+       cyapa_gen3_do_calibrate,

        NULL,
        NULL,
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.

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 5794 bytes --]

^ permalink raw reply related

* [PATCH v2 9/14] input: cyapa: add gen3 trackpad device read firmware image function supported
From: Dudley Du @ 2014-06-06  7:29 UTC (permalink / raw)
  To: Dmitry Torokhov, Rafael J. Wysocki, Alan Stern
  Cc: Benson Leung, Lily Rui, Daniel Kurtz,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 3749 bytes --]

Add read firmware image function supported for gen3 trackpad device,
which its function is supplied through cyapa core read_fw interface.
TEST=test on Chomebooks.

Signed-off-by: Du, Dudley <dudl@cypress.com>
---
diff --git a/drivers/input/mouse/cyapa_gen3.c b/drivers/input/mouse/cyapa_gen3.c
index 9ffdbc1..e903e62 100644
--- a/drivers/input/mouse/cyapa_gen3.c
+++ b/drivers/input/mouse/cyapa_gen3.c
@@ -689,6 +689,35 @@ static int cyapa_gen3_write_fw_block(struct cyapa *cyapa,
        return ret;
 }

+/*
+ * A firmware block read command reads 16 bytes of data from flash starting
+ * from a given address.  The 12-byte block read command has the format:
+ *   <0xff> <CMD> <Key> <Addr>
+ *
+ *  <0xff>  - every command starts with 0xff
+ *  <CMD>   - the read command value is 0x3c
+ *  <Key>   - read commands include an 8-byte key: { 00 01 02 03 04 05 06 07 }
+ *  <Addr>  - Memory address (16-bit, big-endian)
+ *
+ * The command is followed by an i2c block read to read the 16 bytes of data.
+ */
+static int cyapa_gen3_read_fw_bytes(struct cyapa *cyapa, u16 addr, u8 *data)
+{
+       int ret;
+       u8 cmd[] = { 0xff, 0x3c, 0, 1, 2, 3, 4, 5, 6, 7, addr >> 8, addr };
+
+       ret = cyapa_gen3_write_buffer(cyapa, cmd, sizeof(cmd));
+       if (ret)
+               return ret;
+
+       /* read data buffer starting from offset 16 */
+       ret = cyapa_i2c_reg_read_block(cyapa, 16, CYAPA_FW_READ_SIZE, data);
+       if (ret != CYAPA_FW_READ_SIZE)
+               return (ret < 0) ? ret : -EIO;
+
+       return 0;
+}
+
 static int cyapa_gen3_do_fw_update(struct cyapa *cyapa,
                const struct firmware *fw)
 {
@@ -724,6 +753,47 @@ static int cyapa_gen3_do_fw_update(struct cyapa *cyapa,
        return 0;
 }

+/*
+ * Read the entire firmware image into ->read_fw_image.
+ * If the ->read_fw_image has already been allocated, then this function
+ * doesn't do anything and just returns 0.
+ * If an error occurs while reading the image, ->read_fw_image is freed, and
+ * the error is returned.
+ *
+ * The firmware is a fixed size (CYAPA_FW_SIZE), and is read out in
+ * fixed length (CYAPA_FW_READ_SIZE) chunks.
+ */
+static int cyapa_gen3_read_fw(struct cyapa *cyapa)
+{
+       int ret;
+       int addr;
+
+       ret = cyapa_gen3_bl_enter(cyapa);
+       if (ret)
+               goto err;
+
+       cyapa->read_fw_image = kmalloc(CYAPA_FW_SIZE, GFP_KERNEL);
+       if (!cyapa->read_fw_image) {
+               ret = -ENOMEM;
+               goto err;
+       }
+
+       for (addr = 0; addr < CYAPA_FW_SIZE; addr += CYAPA_FW_READ_SIZE) {
+               ret = cyapa_gen3_read_fw_bytes(cyapa, CYAPA_FW_HDR_START + addr,
+                                         &cyapa->read_fw_image[addr]);
+               if (ret) {
+                       kfree(cyapa->read_fw_image);
+                       cyapa->read_fw_image = NULL;
+                       break;
+               }
+       }
+
+err:
+       if (cyapa->read_fw_image)
+               cyapa->read_fw_image_size = CYAPA_FW_SIZE;
+       return ret;
+}
+
 static ssize_t cyapa_gen3_do_calibrate(struct device *dev,
                                     struct device_attribute *attr,
                                     const char *buf, size_t count)
@@ -1122,7 +1192,7 @@ const struct cyapa_dev_ops cyapa_gen3_ops = {
        cyapa_gen3_show_baseline,
        cyapa_gen3_do_calibrate,

-       NULL,
+       cyapa_gen3_read_fw,
        NULL,

        NULL,
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.

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 5546 bytes --]

^ permalink raw reply related

* [PATCH v2 10/14] input: cyapa: add gen5 trackpad device basic functions supported
From: Dudley Du @ 2014-06-06  7:29 UTC (permalink / raw)
  To: Dmitry Torokhov, Rafael J. Wysocki, Alan Stern
  Cc: Benson Leung, Lily Rui, Daniel Kurtz,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 67667 bytes --]

Based on the cyapa core, add the gen5 trackpad device's basic functions
supported, so gen5 trackpad device can work with kernel input system.
And also based on the state parse interface, the cyapa driver can
automatically determine the attached is gen3 or gen5 protocol trackpad
device, then set the correct protocol to work with the attached
trackpad device.
TEST=test on Chomebooks.

Signed-off-by: Du, Dudley <dudl@cypress.com>
---
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index cc2927b..59a1abd 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -35,5 +35,5 @@ 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 cyapa_gen3.o
+cyapatp-y := cyapa.o cyapa_gen3.o cyapa_gen5.o

diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index 3f870e5..8d37032 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -191,6 +191,8 @@ void cyapa_default_irq_handler(struct cyapa *cyapa)
        cont = true;
        if (cyapa_gen3_ops.cyapa_irq_cmd_handler)
                cont = cyapa_gen3_ops.cyapa_irq_cmd_handler(cyapa);
+       if (cont && cyapa_gen5_ops.cyapa_irq_cmd_handler)
+               cont = cyapa_gen5_ops.cyapa_irq_cmd_handler(cyapa);
        if (!cont)
                return;

@@ -354,6 +356,9 @@ static int cyapa_check_is_operational(struct cyapa *cyapa)
                return ret;

        switch (cyapa->gen) {
+       case CYAPA_GEN5:
+               cyapa->ops = &cyapa_gen5_ops;
+               break;
        case CYAPA_GEN3:
                cyapa->ops = &cyapa_gen3_ops;
                break;
@@ -469,6 +474,14 @@ static int cyapa_get_state(struct cyapa *cyapa)
                        if (ret == 0)
                                goto out_detected;
                }
+               if ((cyapa->gen == CYAPA_GEN_UNKNOWN ||
+                               cyapa->gen == CYAPA_GEN5) &&
+                       !smbus && even_addr) {
+                       ret = cyapa_gen5_ops.cyapa_state_parse(cyapa,
+                                       status, BL_STATUS_SIZE);
+                       if (ret == 0)
+                               goto out_detected;
+               }

                /*
                 * cannot detect communication protocol based on current
@@ -1200,6 +1213,8 @@ static int cyapa_probe(struct i2c_client *client,
        private_size = 0;
        if (cyapa_gen3_ops.cyapa_get_private_size)
                private_size += cyapa_gen3_ops.cyapa_get_private_size();
+       if (cyapa_gen5_ops.cyapa_get_private_size)
+               private_size += cyapa_gen5_ops.cyapa_get_private_size();
        cyapa = kzalloc(sizeof(struct cyapa) + private_size, GFP_KERNEL);
        if (!cyapa) {
                dev_err(dev, "allocate memory for cyapa failed\n");
@@ -1215,6 +1230,11 @@ static int cyapa_probe(struct i2c_client *client,
        ret = 0;
        if (cyapa_gen3_ops.cyapa_private_init)
                ret = cyapa_gen3_ops.cyapa_private_init(cyapa, private_mem);
+       if (!ret && cyapa_gen5_ops.cyapa_private_init) {
+               if (cyapa_gen3_ops.cyapa_get_private_size)
+                       private_mem += cyapa_gen3_ops.cyapa_get_private_size();
+               ret = cyapa_gen5_ops.cyapa_private_init(cyapa, private_mem);
+       }
        if (ret)
                goto err_unregister_device;

diff --git a/drivers/input/mouse/cyapa.h b/drivers/input/mouse/cyapa.h
index 7bd27b7..7f8c3d4 100644
--- a/drivers/input/mouse/cyapa.h
+++ b/drivers/input/mouse/cyapa.h
@@ -293,5 +293,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;
+extern const struct cyapa_dev_ops cyapa_gen5_ops;

 #endif
diff --git a/drivers/input/mouse/cyapa_gen5.c b/drivers/input/mouse/cyapa_gen5.c
new file mode 100644
index 0000000..00ca3a6
--- /dev/null
+++ b/drivers/input/mouse/cyapa_gen5.c
@@ -0,0 +1,1595 @@
+/*
+ * Cypress APA trackpad with I2C interface
+ *
+ * Author: Dudley Du <dudl@cypress.com>
+ *
+ * Copyright (C) 2014-2015 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.
+ */
+
+#include <linux/delay.h>
+#include <linux/i2c.h>
+#include <linux/input.h>
+#include <linux/input/mt.h>
+#include <linux/mutex.h>
+#include <linux/completion.h>
+#include <linux/slab.h>
+#include <linux/unaligned/access_ok.h>
+#include "cyapa.h"
+
+
+/* mcros of Gen5 */
+#define RECORD_EVENT_NONE        0
+#define RECORD_EVENT_TOUCHDOWN  1
+#define RECORD_EVENT_DISPLACE    2
+#define RECORD_EVENT_LIFTOFF     3
+
+#define CYAPA_TSG_FLASH_MAP_BLOCK_SIZE      0x80
+#define CYAPA_TSG_IMG_FW_HDR_SIZE           13
+#define CYAPA_TSG_FW_ROW_SIZE               (CYAPA_TSG_FLASH_MAP_BLOCK_SIZE)
+#define CYAPA_TSG_IMG_START_ROW_NUM         0x002e
+#define CYAPA_TSG_IMG_END_ROW_NUM           0x01fe
+#define CYAPA_TSG_IMG_APP_INTEGRITY_ROW_NUM 0x01ff
+#define CYAPA_TSG_IMG_MAX_RECORDS           (CYAPA_TSG_IMG_END_ROW_NUM - \
+                               CYAPA_TSG_IMG_START_ROW_NUM + 1 + 1)
+#define CYAPA_TSG_IMG_READ_SIZE             (CYAPA_TSG_FLASH_MAP_BLOCK_SIZE / 2)
+#define CYAPA_TSG_START_OF_APPLICATION      0x1700
+#define CYAPA_TSG_APP_INTEGRITY_SIZE        60
+#define CYAPA_TSG_FLASH_MAP_METADATA_SIZE   60
+#define CYAPA_TSG_BL_KEY_SIZE               8
+
+/* Macro definitions for Gen5 trackpad device. */
+#define GEN5_TOUCH_REPORT_HEAD_SIZE     7
+#define GEN5_TOUCH_REPORT_MAX_SIZE      127
+#define GEN5_BTN_REPORT_HEAD_SIZE       6
+#define GEN5_BTN_REPORT_MAX_SIZE        14
+#define GEN5_WAKEUP_EVENT_SIZE          4
+#define GEN5_RAW_DATA_HEAD_SIZE         24
+
+#define GEN5_BL_CMD_REPORT_ID           0x40
+#define GEN5_BL_RESP_REPORT_ID          0x30
+#define GEN5_APP_CMD_REPORT_ID          0x2f
+#define GEN5_APP_RESP_REPORT_ID         0x1f
+
+#define GEN5_APP_DEEP_SLEEP_REPORT_ID   0xf0
+#define GEN5_DEEP_SLEEP_RESP_LENGTH     5
+
+#define GEN5_PARAMETER_ACT_INTERVL_ID        0x4d
+#define GEN5_PARAMETER_ACT_INTERVL_SIZE      1
+#define GEN5_PARAMETER_ACT_LFT_INTERVL_ID    0x4f
+#define GEN5_PARAMETER_ACT_LFT_INTERVL_SIZE  2
+#define GEN5_PARAMETER_LP_INTRVL_ID          0x4c
+#define GEN5_PARAMETER_LP_INTRVL_SIZE        2
+
+#define GEN5_PARAMETER_DISABLE_PIP_REPORT    0x08
+
+#define GEN5_POWER_STATE_ACTIVE              0x01
+#define GEN5_POWER_STATE_LOOK_FOR_TOUCH      0x02
+#define GEN5_POWER_STATE_READY               0x03
+#define GEN5_POWER_STATE_IDLE                0x04
+#define GEN5_POWER_STATE_BTN_ONLY            0x05
+#define GEN5_POWER_STATE_OFF                 0x06
+
+#define GEN5_DEEP_SLEEP_STATE_MASK  0x03
+#define GEN5_DEEP_SLEEP_STATE_ON    0x00
+#define GEN5_DEEP_SLEEP_STATE_OFF   0x01
+
+#define GEN5_DEEP_SLEEP_OPCODE      0x08
+#define GEN5_DEEP_SLEEP_OPCODE_MASK 0x0f
+
+#define GEN5_POWER_READY_MAX_INTRVL_TIME  50   /* unit: ms */
+#define GEN5_POWER_IDLE_MAX_INTRVL_TIME   250  /* unit: ms */
+
+#define GEN5_CMD_REPORT_ID_OFFSET       4
+
+#define GEN5_RESP_REPORT_ID_OFFSET      2
+#define GEN5_RESP_RSVD_OFFSET           3
+#define     GEN5_RESP_RSVD_KEY          0x00
+#define GEN5_RESP_BL_SOP_OFFSET         4
+#define     GEN5_SOP_KEY                0x01  /* Start of Packet */
+#define     GEN5_EOP_KEY                0x17  /* End of Packet */
+#define GEN5_RESP_APP_CMD_OFFSET        4
+#define     GET_GEN5_CMD_CODE(reg)      ((reg) & 0x7f)
+
+#define GEN5_MIN_BL_CMD_LENGTH           13
+#define GEN5_MIN_BL_RESP_LENGTH          11
+#define GEN5_MIN_APP_CMD_LENGTH          7
+#define GEN5_MIN_APP_RESP_LENGTH         5
+#define GEN5_UNSUPPORTED_CMD_RESP_LENGTH 6
+
+#define GEN5_RESP_LENGTH_SIZE 2
+
+#define GEN5_HID_DESCRIPTOR_SIZE      32
+#define GEN5_BL_HID_REPORT_ID         0xff
+#define GEN5_APP_HID_REPORT_ID        0xf7
+#define GEN5_BL_MAX_OUTPUT_LENGTH     0x0100
+#define GEN5_APP_MAX_OUTPUT_LENGTH    0x00fe
+
+#define GEN5_BL_REPORT_DESCRIPTOR_SIZE            0x1d
+#define GEN5_BL_REPORT_DESCRIPTOR_ID              0xfe
+#define GEN5_APP_REPORT_DESCRIPTOR_SIZE           0xee
+#define GEN5_APP_CONTRACT_REPORT_DESCRIPTOR_SIZE  0xfa
+#define GEN5_APP_REPORT_DESCRIPTOR_ID             0xf6
+
+#define GEN5_TOUCH_REPORT_ID         0x01
+#define GEN5_BTN_REPORT_ID           0x03
+#define GEN5_WAKEUP_EVENT_REPORT_ID  0x04
+#define GEN5_OLD_PUSH_BTN_REPORT_ID  0x05
+#define GEN5_PUSH_BTN_REPORT_ID      0x06
+
+#define GEN5_CMD_COMPLETE_SUCCESS(status) ((status) == 0x00)
+
+#define GEN5_BL_INITIATE_RESP_LEN            11
+#define GEN5_BL_FAIL_EXIT_RESP_LEN           11
+#define GEN5_BL_FAIL_EXIT_STATUS_CODE        0x0c
+#define GEN5_BL_VERIFY_INTEGRITY_RESP_LEN    12
+#define GEN5_BL_INTEGRITY_CHEKC_PASS         0x00
+#define GEN5_BL_BLOCK_WRITE_RESP_LEN         11
+#define GEN5_BL_READ_APP_INFO_RESP_LEN       31
+#define GEN5_CMD_CALIBRATE                   0x28
+#define CYAPA_SENSING_MODE_MUTUAL_CAP_FINE   0x00
+#define CYAPA_SENSING_MODE_SELF_CAP          0x02
+
+#define GEN5_CMD_RETRIEVE_DATA_STRUCTURE     0x24
+#define GEN5_RETRIEVE_MUTUAL_PWC_DATA        0x00
+#define GEN5_RETRIEVE_SELF_CAP_PWC_DATA      0x01
+
+#define GEN5_RETRIEVE_DATA_ELEMENT_SIZE_MASK 0x07
+
+#define GEN5_CMD_EXECUTE_PANEL_SCAN          0x2a
+#define GEN5_CMD_RETRIEVE_PANEL_SCAN         0x2b
+#define GEN5_PANEL_SCAN_MUTUAL_RAW_DATA      0x00
+#define GEN5_PANEL_SCAN_MUTUAL_BASELINE      0x01
+#define GEN5_PANEL_SCAN_MUTUAL_DIFFCOUNT     0x02
+#define GEN5_PANEL_SCAN_SELF_RAW_DATA        0x03
+#define GEN5_PANEL_SCAN_SELF_BASELINE        0x04
+#define GEN5_PANEL_SCAN_SELF_DIFFCOUNT       0x05
+
+#define GEN5_PWC_DATA_ELEMENT_SIZE_MASK      0x07
+
+#define GEN5_NUMBER_OF_TOUCH_MASK    0x1f
+#define GEN5_GET_EVENT_ID(reg)       (((reg) >> 5) & 0x03)
+#define GEN5_GET_TOUCH_ID(reg)       ((reg) & 0x1f)
+
+#define GEN5_PRODUCT_FAMILY_MASK        0xf000
+#define GEN5_PRODUCT_FAMILY_TRACKPAD    0x1000
+
+#define TSG_INVALID_CMD   0xff
+
+struct cyapa_gen5_touch_record {
+       /*
+        * bit 7 - 3: reserved
+        * bit 2 - 0: touch type;
+        *            0 : standard finger;
+        *            1 - 15 : reserved.
+        */
+       u8 touch_type;
+
+       /*
+        * bit 7: indicates touch liftoff status.
+        *              0 : touch is currently on the panel.
+        *              1 : touch record indicates a liftoff.
+        * bit 6 - 5: indicates an event associated with this touch instance
+        *              0 : no event
+        *              1 : touchdown
+        *              2 : significant displacement (> active distance)
+        *              3 : liftoff (record reports last known coordinates)
+        * bit 4 - 0: An arbitrary ID tag associated with a finger
+        *              to alow tracking a touch as it moves around the panel.
+        */
+       u8 touch_tip_event_id;
+
+       /* bit 7 - 0 of X-axis corrinate of the touch in pixel. */
+       u8 x_lo;
+
+       /* bit 15 - 8 of X-axis corrinate of the touch in pixel. */
+       u8 x_hi;
+
+       /* bit 7 - 0 of Y-axis corrinate of the touch in pixel. */
+       u8 y_lo;
+
+       /* bit 15 - 8 of Y-axis corrinate of the touch in pixel. */
+       u8 y_hi;
+
+       /* touch intensity in counts, pressure value. */
+       u8 z;
+
+       /*
+        * The length of the major axis of the ellipse of contact between
+        * the finger and the panel (ABS_MT_TOUCH_MAJOR).
+        */
+       u8 major_axis_len;
+
+       /*
+        * The length of the minor axis of the ellipse of contact between
+        * the finger and the panel (ABS_MT_TOUCH_MINOR).
+        */
+       u8 minor_axis_len;
+
+       /*
+        * The length of the major axis of the approaching tool.
+        * (ABS_MT_WIDTH_MAJOR)
+        */
+       u8 major_tool_len;
+
+       /*
+        * The length of the minor axis of the approaching tool.
+        * (ABS_MT_WIDTH_MINOR)
+        */
+       u8 minor_tool_len;
+
+       /*
+        * The angle between the panel vertical axis and
+        * the major axis of the contact ellipse. This value is an 8-bit
+        * signed integer. The range is -127 to +127 (corresponding to
+        * -90 degree and +90 degree respectively).
+        * The positive direction is clockwise from the vertical axis.
+        * If the ellipse of contact degenerates into a circle,
+        * orientation is reported as 0.
+        */
+       u8 orientation;
+} __packed;
+
+struct cyapa_gen5_report_data {
+       u8 report_head[GEN5_TOUCH_REPORT_HEAD_SIZE];
+       struct cyapa_gen5_touch_record touch_records[10];
+} __packed;
+
+struct cyapa_tsg_bin_image_head {
+       u8 head_size;  /* in bytes, including itself. */
+       u8 ttda_driver_major_version;  /* reserved as 0. */
+       u8 ttda_driver_minor_version;  /* reserved as 0. */
+       u8 fw_major_version;
+       u8 fw_minor_version;
+       u8 fw_revision_control_number[8];
+} __packed;
+
+struct cyapa_tsg_bin_image_data_record {
+       u8 flash_array_id;
+       __be16 row_number;
+       /* the number of bytes of flash data contained in this record. */
+       __be16 record_len;
+       /* the flash program data. */
+       u8 record_data[CYAPA_TSG_FW_ROW_SIZE];
+} __packed;
+
+struct cyapa_tsg_bin_image {
+       struct cyapa_tsg_bin_image_head image_head;
+       struct cyapa_tsg_bin_image_data_record records[0];
+} __packed;
+
+/* variables for PIP irq sync command processing. */
+struct pip_sync_cmd_states {
+       struct mutex cmd_lock;
+       struct completion cmd_ready;
+       atomic_t cmd_issued;
+       u8 in_progress_cmd;
+
+       cb_sort resp_sort_func;
+       u8 *resp_data;
+       int *resp_len;
+
+       u8 irq_cmd_buf[CYAPA_REG_MAP_SIZE];
+       u8 empty_buf[CYAPA_REG_MAP_SIZE];
+};
+
+static struct pip_sync_cmd_states *gen5_pip;
+static struct cyapa_tsg_bin_image_head gen5_fw_img_head;
+/* record current read the power states of gen5 trackpad device. */
+#define UNINIT_SLEEP_TIME 0xFFFF
+static u8 gen5_pwr_mode = 0xFF;
+static u16 gen5_sleep_time = UNINIT_SLEEP_TIME;
+#define GEN5_UNINIT_SLEEP_TIME(sleep_time)  \
+               ((sleep_time) == UNINIT_SLEEP_TIME)
+
+
+static size_t cyapa_gen5_get_private_size(void)
+{
+       return sizeof(struct pip_sync_cmd_states);
+}
+
+static int cyapa_gen5_private_init(struct cyapa *cyapa, void *private_mem)
+{
+       if (!private_mem)
+               return -ENOMEM;
+
+       gen5_pip = (struct pip_sync_cmd_states *)private_mem;
+       init_completion(&gen5_pip->cmd_ready);
+       atomic_set(&gen5_pip->cmd_issued, 0);
+       mutex_init(&gen5_pip->cmd_lock);
+       atomic_set(&gen5_pip->cmd_issued, 0);
+
+       gen5_pip->resp_sort_func = NULL;
+       gen5_pip->in_progress_cmd = TSG_INVALID_CMD;
+       gen5_pip->resp_data = NULL;
+       gen5_pip->resp_len = NULL;
+
+       return 0;
+}
+
+/* Return negative errno, or else the number of bytes read. */
+static ssize_t cyapa_i2c_pip_read(struct cyapa *cyapa, u8 *buf, size_t size)
+{
+       int ret;
+
+       if (size == 0)
+               return 0;
+
+       if (!buf || size > CYAPA_REG_MAP_SIZE)
+               return -EINVAL;
+
+       ret = i2c_master_recv(cyapa->client, buf, size);
+
+       if (ret != size)
+               return (ret < 0) ? ret : -EIO;
+
+       return size;
+}
+
+/**
+ * Return a negative errno code else zero on success.
+ */
+static ssize_t cyapa_i2c_pip_write(struct cyapa *cyapa, u8 *buf, size_t size)
+{
+       int ret;
+
+       if (!buf || !size)
+               return -EINVAL;
+
+       ret = i2c_master_send(cyapa->client, buf, size);
+
+       if (ret != size)
+               return (ret < 0) ? ret : -EIO;
+
+       return 0;
+}
+
+/**
+ * this function is aimed to dump all not read data in Gen5 trackpad
+ * before send any command, otherwise, the interrupt line will be blocked.
+ */
+int cyapa_empty_pip_output_data(struct cyapa *cyapa,
+               u8 *buf, int *len, cb_sort func)
+{
+       int ret;
+       int length;
+       int report_count;
+       int empty_count;
+       int buf_len;
+
+       buf_len = 0;
+       if (len) {
+               buf_len = (*len < CYAPA_REG_MAP_SIZE) ?
+                               *len : CYAPA_REG_MAP_SIZE;
+               *len = 0;
+       }
+
+       report_count = 8;  /* max 7 pending data before command response data */
+       empty_count = 0;
+       do {
+               /*
+                * Depnding on testing in cyapa driver, there are max 5 "02 00"
+                * packets between two valid bufferred data report in firmware.
+                * So in order to dump all buffered data out and
+                * make interrupt line release for reassert again,
+                * we must set the empty_count check value bigger than 5 to
+                * make it work. Otherwise, in some situation,
+                * the interrupt line may unable to reactive again,
+                * which will cause trackpad device unable to
+                * report data any more.
+                * for example, it may happen in EFT and ESD testing.
+                */
+               if (empty_count > 5)
+                       return 0;
+
+               ret = cyapa_i2c_pip_read(cyapa, gen5_pip->empty_buf,
+                               GEN5_RESP_LENGTH_SIZE);
+               if (ret < 0)
+                       return ret;
+
+               length = get_unaligned_le16(gen5_pip->empty_buf);
+               if (length == GEN5_RESP_LENGTH_SIZE) {
+                       empty_count++;
+                       continue;
+               } else if (length > CYAPA_REG_MAP_SIZE) {
+                       /* should not happen */
+                       return -EINVAL;
+               } else if (length == 0) {
+                       /* application or bootloader launch data polled out. */
+                       length = GEN5_RESP_LENGTH_SIZE;
+                       if (buf && buf_len && func &&
+                               func(cyapa, gen5_pip->empty_buf, length)) {
+                               length = min(buf_len, length);
+                               memcpy(buf, gen5_pip->empty_buf, length);
+                               *len = length;
+                               /* response found, success. */
+                               return 0;
+                       } else {
+                               continue;
+                       }
+               }
+
+               ret = cyapa_i2c_pip_read(cyapa, gen5_pip->empty_buf, length);
+               if (ret < 0)
+                       return ret;
+
+               report_count--;
+               empty_count = 0;
+               length = get_unaligned_le16(gen5_pip->empty_buf);
+               if (length <= GEN5_RESP_LENGTH_SIZE)
+                       empty_count++;
+               else if (buf && buf_len && func &&
+                       func(cyapa, gen5_pip->empty_buf, length)) {
+                       length = min(buf_len, length);
+                       memcpy(buf, gen5_pip->empty_buf, length);
+                       *len = length;
+                       /* response found, success. */
+                       return 0;
+               }
+
+               ret = -EINVAL;
+       } while (report_count);
+
+       return ret;
+}
+
+static int cyapa_do_i2c_pip_cmd_irq_sync(
+               struct cyapa *cyapa,
+               u8 *cmd, size_t cmd_len,
+               unsigned long timeout)
+{
+       int ret;
+
+       /* wait for interrupt to set ready completion */
+       init_completion(&gen5_pip->cmd_ready);
+
+       atomic_inc(&gen5_pip->cmd_issued);
+       ret = cyapa_i2c_pip_write(cyapa, cmd, cmd_len);
+       if (ret) {
+               atomic_dec(&gen5_pip->cmd_issued);
+               return (ret < 0) ? ret : -EIO;
+       }
+
+       /* wait for interrupt to indicate command is completed. */
+       timeout = wait_for_completion_timeout(&gen5_pip->cmd_ready,
+                               msecs_to_jiffies(timeout));
+       if (timeout == 0) {
+               atomic_dec(&gen5_pip->cmd_issued);
+               return -ETIMEDOUT;
+       }
+       return 0;
+}
+
+static int cyapa_i2c_pip_cmd_irq_sync(
+               struct cyapa *cyapa,
+               u8 *cmd, int cmd_len,
+               u8 *resp_data, int *resp_len,
+               unsigned long timeout,
+               cb_sort func)
+{
+       int ret;
+       int tries;
+       int length;
+
+       if (!cmd || !cmd_len)
+               return -EINVAL;
+
+       /* commands must be serialized. */
+       mutex_lock(&gen5_pip->cmd_lock);
+
+       gen5_pip->resp_sort_func = func;
+       gen5_pip->resp_data = resp_data;
+       gen5_pip->resp_len = resp_len;
+
+       if (cmd_len >= GEN5_MIN_APP_CMD_LENGTH &&
+                       cmd[4] == GEN5_APP_CMD_REPORT_ID) {
+               /* application command */
+               gen5_pip->in_progress_cmd = cmd[6] & 0x7f;
+       } else if (cmd_len >= GEN5_MIN_BL_CMD_LENGTH &&
+                       cmd[4] == GEN5_BL_CMD_REPORT_ID) {
+               /* bootloader command */
+               gen5_pip->in_progress_cmd = cmd[7];
+       }
+
+       /* send command data, wait and read output response data's length. */
+       if (cyapa_is_irq_enabled(cyapa)) {
+               ret = cyapa_do_i2c_pip_cmd_irq_sync(cyapa, cmd, cmd_len,
+                                                       timeout);
+               if (ret == -ETIMEDOUT && resp_data &&
+                               resp_len && *resp_len != 0 && func) {
+                       /*
+                        * for some old version with some unknown reasons,
+                        * there was no interrupt for the command response data,
+                        * so need to poll here to try to get the response data.
+                        */
+                       ret = cyapa_empty_pip_output_data(cyapa,
+                                       resp_data, resp_len, func);
+                       if (ret || *resp_len == 0)
+                               ret = ret ? ret : -ETIMEDOUT;
+               }
+       } else {
+               ret = cyapa_i2c_pip_write(cyapa, cmd, cmd_len);
+               if (ret) {
+                       ret = ret < 0 ? ret : -EIO;
+                       goto out;
+               }
+
+               tries = timeout / 5;
+               length = *resp_len;
+               if (resp_data && resp_len && length != 0 && func) {
+                       do {
+                               usleep_range(3000, 5000);
+                               *resp_len = length;
+                               ret = cyapa_empty_pip_output_data(cyapa,
+                                               resp_data, resp_len, func);
+                               if (ret || *resp_len == 0)
+                                       continue;
+                               else
+                                       break;
+                       } while (--tries > 0);
+                       if ((ret || *resp_len == 0) || tries <= 0)
+                               ret = ret ? ret : -ETIMEDOUT;
+               }
+       }
+
+out:
+       gen5_pip->resp_sort_func = NULL;
+       gen5_pip->resp_data = NULL;
+       gen5_pip->resp_len = NULL;
+       gen5_pip->in_progress_cmd = TSG_INVALID_CMD;
+
+       mutex_unlock(&gen5_pip->cmd_lock);
+       return ret;
+}
+
+bool cyapa_gen5_sort_tsg_pip_bl_resp_data(struct cyapa *cyapa,
+               u8 *data, int len)
+{
+       if (!data || len < GEN5_MIN_BL_RESP_LENGTH)
+               return false;
+
+       /* bootloader input report id 30h */
+       if (data[GEN5_RESP_REPORT_ID_OFFSET] == GEN5_BL_RESP_REPORT_ID &&
+                       data[GEN5_RESP_RSVD_OFFSET] == GEN5_RESP_RSVD_KEY &&
+                       data[GEN5_RESP_BL_SOP_OFFSET] == GEN5_SOP_KEY)
+               return true;
+
+       return false;
+}
+
+bool cyapa_gen5_sort_tsg_pip_app_resp_data(struct cyapa *cyapa,
+               u8 *data, int len)
+{
+       int resp_len;
+
+       if (!data || len < GEN5_MIN_APP_RESP_LENGTH)
+               return false;
+
+       if (data[GEN5_RESP_REPORT_ID_OFFSET] == GEN5_APP_RESP_REPORT_ID &&
+                       data[GEN5_RESP_RSVD_OFFSET] == GEN5_RESP_RSVD_KEY) {
+               resp_len = get_unaligned_le16(&data[0]);
+               if (GET_GEN5_CMD_CODE(data[GEN5_RESP_APP_CMD_OFFSET]) == 0x00 &&
+                       resp_len == GEN5_UNSUPPORTED_CMD_RESP_LENGTH &&
+                       data[5] == gen5_pip->in_progress_cmd) {
+                       /* unsupported command code */
+                       return false;
+               } else if (GET_GEN5_CMD_CODE(data[GEN5_RESP_APP_CMD_OFFSET]) ==
+                               gen5_pip->in_progress_cmd) {
+                       /* correct command response received */
+                       return true;
+               }
+       }
+
+       return false;
+}
+
+bool cyapa_gen5_sort_application_launch_data(struct cyapa *cyapa,
+               u8 *buf, int len)
+{
+       if (buf == NULL || len < GEN5_RESP_LENGTH_SIZE)
+               return false;
+
+       if (buf[0] == 0 && buf[1] == 0)
+               return true;
+
+       return false;
+}
+
+static bool cyapa_gen5_sort_hid_descriptor_data(struct cyapa *cyapa,
+               u8 *buf, int len)
+{
+       int resp_len;
+       int max_output_len;
+
+       /* check hid descriptor. */
+       if (len != GEN5_HID_DESCRIPTOR_SIZE)
+               return false;
+
+       resp_len = get_unaligned_le16(&buf[0]);
+       max_output_len = get_unaligned_le16(&buf[16]);
+       if (resp_len == GEN5_HID_DESCRIPTOR_SIZE) {
+               if (buf[2] == GEN5_BL_HID_REPORT_ID &&
+                               max_output_len == GEN5_BL_MAX_OUTPUT_LENGTH) {
+                       /* BL mode HID Descriptor */
+                       return true;
+               } else if (buf[2] == GEN5_APP_HID_REPORT_ID &&
+                               max_output_len == GEN5_APP_MAX_OUTPUT_LENGTH) {
+                       /* APP mode HID Descriptor */
+                       return true;
+               }
+       }
+
+       return false;
+}
+
+static bool cyapa_gen5_sort_deep_sleep_data(struct cyapa *cyapa,
+               u8 *buf, int len)
+{
+       if (len == GEN5_DEEP_SLEEP_RESP_LENGTH &&
+               buf[2] == GEN5_APP_DEEP_SLEEP_REPORT_ID &&
+               (buf[4] & GEN5_DEEP_SLEEP_OPCODE_MASK) ==
+                       GEN5_DEEP_SLEEP_OPCODE)
+               return true;
+       return false;
+}
+
+static int cyapa_gen5_state_parse(struct cyapa *cyapa, u8 *reg_data, int len)
+{
+       int ret;
+       int length;
+       u8 cmd[2];
+       u8 resp_data[32];
+       int max_output_len;
+
+       /*
+        * Try to dump all bufferred data if it's known gen5 trackpad
+        * before detecting. Because the irq routine may disabled
+        * before enter this routine.
+        */
+       if (cyapa->gen == CYAPA_GEN5)
+               cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
+       cyapa->state = CYAPA_STATE_NO_DEVICE;
+       cyapa_enable_irq_save(cyapa);
+
+       /* Parse based on Gen5 characteristic regiters and bits */
+       length = get_unaligned_le16(&reg_data[0]);
+       if (length == 0 || length == GEN5_RESP_LENGTH_SIZE) {
+               /* dump all buffered data firstly for the situation
+                * when the trackpad is just power on the cyapa go here. */
+               cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
+
+               memset(resp_data, 0, sizeof(resp_data));
+               ret = cyapa_i2c_pip_read(cyapa, resp_data, 3);
+               if (ret != 3)
+                       goto out;
+
+               length = get_unaligned_le16(&resp_data[0]);
+               if (length == GEN5_RESP_LENGTH_SIZE) {
+                       /* normal state of Gen5 with no data to respose */
+                       cyapa->gen = CYAPA_GEN5;
+
+                       cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
+
+                       /* read description from trackpad device */
+                       cmd[0] = 0x01;
+                       cmd[1] = 0x00;
+                       length = GEN5_HID_DESCRIPTOR_SIZE;
+                       ret = cyapa_i2c_pip_cmd_irq_sync(cyapa,
+                                       cmd, 2,
+                                       resp_data, &length,
+                                       300,
+                                       cyapa_gen5_sort_hid_descriptor_data);
+                       if (ret)
+                               goto out;
+
+                       length = get_unaligned_le16(&resp_data[0]);
+                       max_output_len = get_unaligned_le16(&resp_data[16]);
+                       if ((length == GEN5_HID_DESCRIPTOR_SIZE ||
+                                       length == GEN5_RESP_LENGTH_SIZE) &&
+                               resp_data[2] == GEN5_BL_HID_REPORT_ID &&
+                               max_output_len == GEN5_BL_MAX_OUTPUT_LENGTH) {
+                               /* BL mode HID Description read */
+                               cyapa->state = CYAPA_STATE_GEN5_BL;
+                       } else if ((length == GEN5_HID_DESCRIPTOR_SIZE ||
+                                       length == GEN5_RESP_LENGTH_SIZE) &&
+                               resp_data[2] == GEN5_APP_HID_REPORT_ID &&
+                               max_output_len == GEN5_APP_MAX_OUTPUT_LENGTH) {
+                               /* APP mode HID Description read */
+                               cyapa->state = CYAPA_STATE_GEN5_APP;
+                       } else {
+                               /* should not happen!!! */
+                               cyapa->state = CYAPA_STATE_NO_DEVICE;
+                       }
+               }
+       } else if (length == GEN5_HID_DESCRIPTOR_SIZE &&
+                       (reg_data[2] == GEN5_BL_HID_REPORT_ID ||
+                               reg_data[2] == GEN5_APP_HID_REPORT_ID)) {
+               /* 0x20 0x00 0xF7 is Gen5 Application HID Description Header;
+                * 0x20 0x00 0xFF is Gen5 Booloader HID Description Header.
+                *
+                * must read Report Description content through out,
+                * otherwise Gen5 trackpad cannot reponse next command
+                * or report any touch or button data.
+                */
+               ret = cyapa_i2c_pip_read(cyapa, resp_data,
+                               GEN5_HID_DESCRIPTOR_SIZE);
+               if (ret != GEN5_HID_DESCRIPTOR_SIZE)
+                       goto out;
+               length = get_unaligned_le16(&resp_data[0]);
+               max_output_len = get_unaligned_le16(&resp_data[16]);
+               if (length == GEN5_RESP_LENGTH_SIZE) {
+                       if (reg_data[2] == GEN5_BL_HID_REPORT_ID) {
+                               /* BL mode HID Description has been previously
+                                * read out */
+                               cyapa->gen = CYAPA_GEN5;
+                               cyapa->state = CYAPA_STATE_GEN5_BL;
+                       } else {
+                               /* APP mode HID Description has been previously
+                                * read out */
+                               cyapa->gen = CYAPA_GEN5;
+                               cyapa->state = CYAPA_STATE_GEN5_APP;
+                       }
+               } else if (length == GEN5_HID_DESCRIPTOR_SIZE &&
+                               resp_data[2] == GEN5_BL_HID_REPORT_ID &&
+                               max_output_len == GEN5_BL_MAX_OUTPUT_LENGTH) {
+                       /* BL mode HID Description read */
+                       cyapa->gen = CYAPA_GEN5;
+                       cyapa->state = CYAPA_STATE_GEN5_BL;
+               } else if (length == GEN5_HID_DESCRIPTOR_SIZE &&
+                               resp_data[2] == GEN5_APP_HID_REPORT_ID &&
+                               max_output_len == GEN5_APP_MAX_OUTPUT_LENGTH) {
+                       /* APP mode HID Description read */
+                       cyapa->gen = CYAPA_GEN5;
+                       cyapa->state = CYAPA_STATE_GEN5_APP;
+               } else {
+                       /* should not happen!!! */
+                       cyapa->state = CYAPA_STATE_NO_DEVICE;
+               }
+       } else if ((length == GEN5_APP_REPORT_DESCRIPTOR_SIZE ||
+                       length == GEN5_APP_CONTRACT_REPORT_DESCRIPTOR_SIZE) &&
+                       reg_data[2] == GEN5_APP_REPORT_DESCRIPTOR_ID) {
+               /* 0xEE 0x00 0xF6 is Gen5 APP Report Description header. */
+               cyapa->gen = CYAPA_GEN5;
+               cyapa->state = CYAPA_STATE_GEN5_APP;
+
+               /*
+                * must read Report Description content through out,
+                * otherwise Gen5 trackpad cannot reponse next command
+                * or report any touch or button data.
+                */
+       } else if (length == GEN5_BL_REPORT_DESCRIPTOR_SIZE &&
+                       reg_data[2] == GEN5_BL_REPORT_DESCRIPTOR_ID) {
+               /* 0x1D 0x00 0xFE is Gen5 BL Report Descriptior header. */
+               cyapa->gen = CYAPA_GEN5;
+               cyapa->state = CYAPA_STATE_NO_DEVICE;
+
+               /*
+                * must read Report Description content through out,
+                * otherwise Gen5 trackpad cannot reponse next command
+                * or report any touch or button data.
+                */
+               ret = cyapa_i2c_pip_read(cyapa, gen5_pip->empty_buf,
+                               GEN5_BL_REPORT_DESCRIPTOR_SIZE);
+               if (ret == GEN5_BL_REPORT_DESCRIPTOR_SIZE)
+                       cyapa->state = CYAPA_STATE_GEN5_BL;
+       } else if (reg_data[2] == GEN5_TOUCH_REPORT_ID ||
+                       reg_data[2] == GEN5_BTN_REPORT_ID ||
+                       reg_data[2] == GEN5_OLD_PUSH_BTN_REPORT_ID ||
+                       reg_data[2] == GEN5_PUSH_BTN_REPORT_ID ||
+                       reg_data[2] == GEN5_WAKEUP_EVENT_REPORT_ID) {
+               ret = 0;
+               length = get_unaligned_le16(&reg_data[0]);
+               switch (reg_data[2]) {
+               case GEN5_TOUCH_REPORT_ID:
+                       if (length < GEN5_TOUCH_REPORT_HEAD_SIZE ||
+                               length > GEN5_TOUCH_REPORT_MAX_SIZE)
+                               ret = -EAGAIN;
+                       break;
+               case GEN5_BTN_REPORT_ID:
+               case GEN5_OLD_PUSH_BTN_REPORT_ID:
+               case GEN5_PUSH_BTN_REPORT_ID:
+                       if (length < GEN5_BTN_REPORT_HEAD_SIZE ||
+                               length > GEN5_BTN_REPORT_MAX_SIZE)
+                               ret = -EAGAIN;
+                       break;
+               case GEN5_WAKEUP_EVENT_REPORT_ID:
+                       if (length != GEN5_WAKEUP_EVENT_SIZE)
+                               ret = -EAGAIN;
+                       break;
+               }
+
+               if (ret == 0) {
+                       cyapa->gen = CYAPA_GEN5;
+                       cyapa->state = CYAPA_STATE_GEN5_APP;
+               }
+       } else if (reg_data[2] == GEN5_BL_RESP_REPORT_ID ||
+                       reg_data[2] == GEN5_APP_RESP_REPORT_ID) {
+               /*
+                * must read report data through out,
+                * otherwise Gen5 trackpad cannot reponse next command
+                * or report any touch or button data.
+                */
+               length = get_unaligned_le16(reg_data);
+               ret = cyapa_i2c_pip_read(cyapa, gen5_pip->empty_buf, length);
+               if (ret != length)
+                       goto out;
+
+               if (length == GEN5_RESP_LENGTH_SIZE) {
+                       /* previous command has read the data through out. */
+                       if (reg_data[2] == GEN5_BL_RESP_REPORT_ID) {
+                               /* Gen5 BL command response data detected */
+                               cyapa->gen = CYAPA_GEN5;
+                               cyapa->state = CYAPA_STATE_GEN5_BL;
+                       } else {
+                               /* Gen5 APP command response data detected */
+                               cyapa->gen = CYAPA_GEN5;
+                               cyapa->state = CYAPA_STATE_GEN5_APP;
+                       }
+               } else if (gen5_pip->empty_buf[2] == GEN5_BL_RESP_REPORT_ID &&
+                               gen5_pip->empty_buf[3] == GEN5_RESP_RSVD_KEY &&
+                               gen5_pip->empty_buf[4] == GEN5_SOP_KEY &&
+                               gen5_pip->empty_buf[length - 1] ==
+                                       GEN5_EOP_KEY) {
+                       /* Gen5 BL command response data detected */
+                       cyapa->gen = CYAPA_GEN5;
+                       cyapa->state = CYAPA_STATE_GEN5_BL;
+               } else if (gen5_pip->empty_buf[2] == GEN5_APP_RESP_REPORT_ID &&
+                               gen5_pip->empty_buf[3] == GEN5_RESP_RSVD_KEY) {
+                       /* Gen5 APP command response data detected */
+                       cyapa->gen = CYAPA_GEN5;
+                       cyapa->state = CYAPA_STATE_GEN5_APP;
+               } else {
+                       /* should not happen!!! */
+                       cyapa->state = CYAPA_STATE_NO_DEVICE;
+               }
+       }
+out:
+       cyapa_irq_restore(cyapa);
+       if (cyapa->gen == CYAPA_GEN5 && (cyapa->state == CYAPA_STATE_GEN5_APP ||
+                       cyapa->state == CYAPA_STATE_GEN5_BL)) {
+               cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
+               return 0;
+       }
+       return -EAGAIN;
+}
+
+bool cyapa_gen5_sort_bl_exit_data(struct cyapa *cyapa, u8 *buf, int len)
+{
+       if (buf == NULL || len < GEN5_RESP_LENGTH_SIZE)
+               return false;
+
+       if (buf[0] == 0 && buf[1] == 0)
+               return true;
+
+       /* exit bootloader failed for some reason. */
+       if (len == GEN5_BL_FAIL_EXIT_RESP_LEN &&
+                       buf[2] == GEN5_BL_RESP_REPORT_ID &&
+                       buf[3] == GEN5_RESP_RSVD_KEY &&
+                       buf[4] == GEN5_SOP_KEY &&
+                       buf[10] == GEN5_EOP_KEY)
+               return true;
+
+       return false;
+}
+static int cyapa_gen5_bl_exit(struct cyapa *cyapa)
+{
+       int ret;
+       u8 resp_data[11];
+       int resp_len;
+       u8 bl_gen5_bl_exit[] = { 0x04, 0x00,
+               0x0B, 0x00, 0x40, 0x00, 0x01, 0x3b, 0x00, 0x00,
+               0x20, 0xc7, 0x17
+       };
+
+       resp_len = sizeof(resp_data);
+       ret = cyapa_i2c_pip_cmd_irq_sync(cyapa,
+                       bl_gen5_bl_exit, sizeof(bl_gen5_bl_exit),
+                       resp_data, &resp_len,
+                       5000, cyapa_gen5_sort_bl_exit_data);
+       if (ret)
+               return ret;
+
+       if (resp_len == GEN5_BL_FAIL_EXIT_RESP_LEN ||
+                       resp_data[2] == GEN5_BL_RESP_REPORT_ID)
+               return -EAGAIN;
+
+       if (resp_data[0] == 0x00 && resp_data[1] == 0x00)
+               return 0;
+
+       return -EAGAIN;
+}
+
+static int cyapa_gen5_change_power_state(struct cyapa *cyapa, u8 power_state)
+{
+       int ret;
+       u8 cmd[8] = { 0x04, 0x00, 0x06, 0x00, 0x2f, 0x00, 0x08, 0x01 };
+       u8 resp_data[6];
+       int resp_len;
+
+       cmd[7] = power_state;
+       resp_len = sizeof(resp_data);
+       ret = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, sizeof(cmd),
+                       resp_data, &resp_len,
+                       500, cyapa_gen5_sort_tsg_pip_app_resp_data);
+       if (ret || resp_data[2] != GEN5_APP_RESP_REPORT_ID ||
+                       resp_data[3] != GEN5_RESP_RSVD_KEY ||
+                       GET_GEN5_CMD_CODE(resp_data[4]) != 0x08 ||
+                       !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5]))
+               return ret < 0 ? ret : -EINVAL;
+
+       return 0;
+}
+
+static int cyapa_gen5_set_interval_time(struct cyapa *cyapa,
+               u8 parameter_id, u16 interval_time)
+{
+       int ret;
+       u8 cmd[13];
+       int cmd_len;
+       u8 resp_data[7];
+       int resp_len;
+       u8 parameter_size;
+
+       switch (parameter_id) {
+       case GEN5_PARAMETER_ACT_INTERVL_ID:
+               parameter_size = GEN5_PARAMETER_ACT_INTERVL_SIZE;
+               break;
+       case GEN5_PARAMETER_ACT_LFT_INTERVL_ID:
+               parameter_size = GEN5_PARAMETER_ACT_LFT_INTERVL_SIZE;
+               break;
+       case GEN5_PARAMETER_LP_INTRVL_ID:
+               parameter_size = GEN5_PARAMETER_LP_INTRVL_SIZE;
+               break;
+       default:
+               return -EINVAL;
+       }
+       cmd_len = 7 + parameter_size;  /* not incuding 2 bytes address */
+       cmd[0] = 0x04;
+       cmd[1] = 0x00;
+       put_unaligned_le16(cmd_len, &cmd[2]);
+       cmd[4] = 0x2f;
+       cmd[5] = 0x00;
+       cmd[6] = 0x06; /* set parameter command code */
+       cmd[7] = parameter_id;
+       cmd[8] = parameter_size;
+       put_unaligned_le16(interval_time, &cmd[9]);
+       resp_len = sizeof(resp_data);
+       ret = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, cmd_len + 2,
+                       resp_data, &resp_len,
+                       500, cyapa_gen5_sort_tsg_pip_app_resp_data);
+       if (ret || resp_data[2] != GEN5_APP_RESP_REPORT_ID ||
+                       resp_data[3] != GEN5_RESP_RSVD_KEY ||
+                       GET_GEN5_CMD_CODE(resp_data[4]) != 0x06 ||
+                       resp_data[5] != parameter_id ||
+                       resp_data[6] != parameter_size)
+               return ret < 0 ? ret : -EINVAL;
+
+       return 0;
+}
+
+static int cyapa_gen5_get_interval_time(struct cyapa *cyapa,
+               u8 parameter_id, u16 *interval_time)
+{
+       int ret;
+       u8 cmd[8];
+       u8 resp_data[11];
+       int resp_len;
+       u8 parameter_size;
+       u16 mask, i;
+
+       *interval_time = 0;
+       switch (parameter_id) {
+       case GEN5_PARAMETER_ACT_INTERVL_ID:
+               parameter_size = GEN5_PARAMETER_ACT_INTERVL_SIZE;
+               break;
+       case GEN5_PARAMETER_ACT_LFT_INTERVL_ID:
+               parameter_size = GEN5_PARAMETER_ACT_LFT_INTERVL_SIZE;
+               break;
+       case GEN5_PARAMETER_LP_INTRVL_ID:
+               parameter_size = GEN5_PARAMETER_LP_INTRVL_SIZE;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       cmd[0] = 0x04;
+       cmd[1] = 0x00;
+       cmd[2] = 0x06;
+       cmd[3] = 0x00;
+       cmd[4] = 0x2f;
+       cmd[5] = 0x00;
+       cmd[6] = 0x05; /* get parameter command code */
+       cmd[7] = parameter_id;
+       resp_len = sizeof(resp_data);
+       ret = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, sizeof(cmd),
+                       resp_data, &resp_len,
+                       500, cyapa_gen5_sort_tsg_pip_app_resp_data);
+       if (ret || resp_data[2] != GEN5_APP_RESP_REPORT_ID ||
+                       resp_data[3] != GEN5_RESP_RSVD_KEY ||
+                       GET_GEN5_CMD_CODE(resp_data[4]) != 0x05 ||
+                       resp_data[5] != parameter_id ||
+                       resp_data[6] == 0)
+               return ret < 0 ? ret : -EINVAL;
+
+       mask = 0;
+       for (i = 0; i < parameter_size; i++)
+               mask |= (0xff << (i * 8));
+       *interval_time = get_unaligned_le16(&resp_data[7]) & mask;
+
+       return 0;
+}
+
+static int cyapa_gen5_disable_pip_report(struct cyapa *cyapa)
+{
+       int ret;
+       u8 cmd[10];
+       u8 resp_data[7];
+       int resp_len;
+
+       cmd[0] = 0x04;
+       cmd[1] = 0x00;
+       put_unaligned_le16(8, &cmd[2]);
+       cmd[4] = 0x2f;
+       cmd[5] = 0x00;
+       cmd[6] = 0x06; /* set parameter command code */
+       cmd[7] = GEN5_PARAMETER_DISABLE_PIP_REPORT;
+       cmd[8] = 0x01;
+       cmd[9] = 0x01;
+       resp_len = sizeof(resp_data);
+       ret = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, 10,
+                       resp_data, &resp_len,
+                       500, cyapa_gen5_sort_tsg_pip_app_resp_data);
+       if (ret || resp_data[2] != GEN5_APP_RESP_REPORT_ID ||
+                       resp_data[3] != GEN5_RESP_RSVD_KEY ||
+                       GET_GEN5_CMD_CODE(resp_data[4]) != 0x06 ||
+                       resp_data[5] != GEN5_PARAMETER_DISABLE_PIP_REPORT ||
+                       resp_data[6] != 0x01)
+               return ret < 0 ? ret : -EINVAL;
+
+       return 0;
+}
+
+static int cyapa_gen5_deep_sleep(struct cyapa *cyapa, u8 state)
+{
+       int ret;
+       u8 cmd[4] = { 0x05, 0x00, 0x00, 0x08};
+       u8 resp_data[5];
+       int resp_len;
+
+       cmd[0] = 0x05;
+       cmd[1] = 0x00;
+       cmd[2] = state & GEN5_DEEP_SLEEP_STATE_MASK;
+       cmd[3] = 0x08;
+       resp_len = sizeof(resp_data);
+       ret = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, sizeof(cmd),
+                       resp_data, &resp_len,
+                       100, cyapa_gen5_sort_deep_sleep_data);
+       if (ret || ((resp_data[3] & GEN5_DEEP_SLEEP_STATE_MASK) != state))
+               return -EINVAL;
+
+       return 0;
+}
+
+static int cyapa_gen5_set_power_mode(struct cyapa *cyapa,
+               u8 power_mode, u16 sleep_time)
+{
+       struct device *dev = &cyapa->client->dev;
+       int ret;
+       u8 power_state;
+
+       if (cyapa->state != CYAPA_STATE_GEN5_APP)
+               return 0;
+
+       /* dump all the report data before do power mode commmands. */
+       cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
+
+       if (gen5_pwr_mode != PWR_MODE_OFF &&
+                       GEN5_UNINIT_SLEEP_TIME(gen5_sleep_time)) {
+               if (cyapa_gen5_get_interval_time(cyapa,
+                               GEN5_PARAMETER_LP_INTRVL_ID,
+                               &gen5_sleep_time) != 0)
+                       gen5_sleep_time = UNINIT_SLEEP_TIME;
+       }
+
+       switch (power_mode) {
+       case PWR_MODE_OFF:
+       case PWR_MODE_FULL_ACTIVE:
+       case PWR_MODE_BTN_ONLY:
+               /* has in correct power mode state, early return. */
+               if (gen5_pwr_mode == power_mode)
+                       return 0;
+
+               /* enter deep sleep directly without any additional steps. */
+               if (power_mode == PWR_MODE_OFF) {
+                       ret = cyapa_gen5_deep_sleep(cyapa,
+                               GEN5_DEEP_SLEEP_STATE_OFF);
+                       if (ret) {
+                               dev_err(dev, "enter deep sleep fail, (%d)\n",
+                                       ret);
+                               return ret;
+                       }
+                       gen5_pwr_mode = power_mode;
+                       return 0;
+               }
+       default:
+               /* has in correct power mode state, early return. */
+               if (gen5_sleep_time == sleep_time &&
+                       gen5_pwr_mode == power_mode)
+                       return 0;
+       }
+
+       /* when trackpad in power off mode, it cannot change to other power
+        * state directly, must be wake up from sleep firstly, then
+        * continue to do next power sate change. */
+       if (gen5_pwr_mode == PWR_MODE_OFF) {
+               ret = cyapa_gen5_deep_sleep(cyapa, GEN5_DEEP_SLEEP_STATE_ON);
+               if (ret) {
+                       dev_err(dev, "deep sleep wake fail, (%d)\n", ret);
+                       return ret;
+               }
+       }
+
+       if (power_mode == PWR_MODE_FULL_ACTIVE) {
+               ret = cyapa_gen5_change_power_state(cyapa,
+                               GEN5_POWER_STATE_ACTIVE);
+               if (ret) {
+                       dev_err(dev, "change to active fail, (%d)\n", ret);
+                       return ret;
+               }
+
+               gen5_pwr_mode = PWR_MODE_FULL_ACTIVE;
+       } else if (power_mode == PWR_MODE_BTN_ONLY) {
+               ret = cyapa_gen5_change_power_state(cyapa,
+                               GEN5_POWER_STATE_BTN_ONLY);
+               if (ret) {
+                       dev_err(dev, "fail change to active, (%d)\n", ret);
+                       return ret;
+               }
+
+               gen5_pwr_mode = PWR_MODE_BTN_ONLY;
+       } else {
+               /* continue to change power mode even failed to set
+                * interval time, it won't affect the power mode change.
+                * except the sleep interval time is not correct. */
+               if (GEN5_UNINIT_SLEEP_TIME(gen5_sleep_time) ||
+                               sleep_time != gen5_sleep_time)
+                       if (cyapa_gen5_set_interval_time(cyapa,
+                               GEN5_PARAMETER_LP_INTRVL_ID, sleep_time) == 0)
+                                       gen5_sleep_time = sleep_time;
+
+               if (sleep_time <= GEN5_POWER_READY_MAX_INTRVL_TIME)
+                       power_state = GEN5_POWER_STATE_READY;
+               else
+                       power_state = GEN5_POWER_STATE_IDLE;
+               ret = cyapa_gen5_change_power_state(cyapa, power_state);
+               if (ret) {
+                       dev_err(dev, "set power state %d fail, (%d)\n",
+                               power_state, ret);
+                       return ret;
+               }
+
+               /* disable pip report for a little time, firmware will
+                * re-enable it automatically. It's used to fix the issue
+                * that trackpad unable to report signal to wake system up
+                * in the special situation that system is in suspending, and
+                * at the same time, user touch trackpad to wake system up.
+                * This function can avoid the data to be buffured when system
+                * is suspending which may cause interrput line unable to be
+                * asserted again. */
+               cyapa_gen5_disable_pip_report(cyapa);
+
+               gen5_pwr_mode = cyapa_sleep_time_to_pwr_cmd(sleep_time);
+       }
+
+       cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
+       return ret;
+}
+
+static bool cyapa_gen5_sort_system_info_data(struct cyapa *cyapa,
+               u8 *buf, int len)
+{
+       /* check the report id and command code */
+       if (buf[2] == GEN5_APP_RESP_REPORT_ID &&
+                       GET_GEN5_CMD_CODE(buf[4]) == 0x02)
+               return true;
+
+       return false;
+}
+
+static int cyapa_gen5_bl_query_data(struct cyapa *cyapa)
+{
+       int ret;
+       u8 cmd[16];
+       int cmd_len;
+       u8 resp_data[GEN5_BL_READ_APP_INFO_RESP_LEN];
+       int resp_len;
+
+       /* read application information. */
+       cmd[0] = 0x04;
+       cmd[1] = 0x00;
+       cmd[2] = 0x0b;
+       cmd[3] = 0x00;
+       cmd[4] = 0x40;
+       cmd[5] = 0x00;
+       cmd[6] = GEN5_SOP_KEY;
+       cmd[7] = 0x3c;  /* read application information command code */
+       cmd[8] = 0x00;
+       cmd[9] = 0x00;
+       cmd[10] = 0xb0;
+       cmd[11] = 0x42;
+       cmd[12] = GEN5_EOP_KEY;
+       cmd_len = 13;
+       resp_len = GEN5_BL_READ_APP_INFO_RESP_LEN;
+       ret = cyapa_i2c_pip_cmd_irq_sync(cyapa,
+                       cmd, cmd_len,
+                       resp_data, &resp_len,
+                       500, cyapa_gen5_sort_tsg_pip_bl_resp_data);
+       if (ret || resp_len != GEN5_BL_READ_APP_INFO_RESP_LEN ||
+                       resp_data[2] != GEN5_BL_RESP_REPORT_ID ||
+                       !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5]))
+               return (ret < 0) ? ret : -EIO;
+
+       memcpy(&cyapa->product_id[0], &resp_data[8], 5);
+       cyapa->product_id[5] = '-';
+       memcpy(&cyapa->product_id[6], &resp_data[13], 6);
+       cyapa->product_id[12] = '-';
+       memcpy(&cyapa->product_id[13], &resp_data[19], 2);
+       cyapa->product_id[15] = '\0';
+
+       cyapa->fw_maj_ver = resp_data[22];
+       cyapa->fw_min_ver = resp_data[23];
+
+       return 0;
+}
+
+static int cyapa_gen5_get_query_data(struct cyapa *cyapa)
+{
+       int ret;
+       u8 resp_data[71];
+       int resp_len;
+       u8 get_system_information[] = {
+               0x04, 0x00, 0x05, 0x00, 0x2f, 0x00, 0x02
+       };
+       u16 product_family;
+
+       resp_len = sizeof(resp_data);
+       ret = cyapa_i2c_pip_cmd_irq_sync(cyapa,
+                       get_system_information, sizeof(get_system_information),
+                       resp_data, &resp_len,
+                       2000, cyapa_gen5_sort_system_info_data);
+       if (ret || resp_len < sizeof(resp_data))
+               return ret;
+
+       gen5_fw_img_head.head_size =
+               sizeof(struct cyapa_tsg_bin_image_head) - 1;
+       memcpy(&gen5_fw_img_head.ttda_driver_major_version,
+               &resp_data[5], gen5_fw_img_head.head_size);
+
+       product_family = get_unaligned_le16(&resp_data[7]);
+       if ((product_family & GEN5_PRODUCT_FAMILY_MASK) !=
+               GEN5_PRODUCT_FAMILY_TRACKPAD)
+               return -EINVAL;
+
+       cyapa->fw_maj_ver = resp_data[15];
+       cyapa->fw_min_ver = resp_data[16];
+
+       cyapa->electrodes_x = resp_data[52];
+       cyapa->electrodes_y = resp_data[53];
+
+       cyapa->physical_size_x =  get_unaligned_le16(&resp_data[54]) / 100;
+       cyapa->physical_size_y = get_unaligned_le16(&resp_data[56]) / 100;
+
+       cyapa->max_abs_x = get_unaligned_le16(&resp_data[58]);
+       cyapa->max_abs_y = get_unaligned_le16(&resp_data[60]);
+
+       cyapa->max_z = get_unaligned_le16(&resp_data[62]);
+
+       cyapa->x_origin = resp_data[64] & 0x01;
+       cyapa->y_origin = resp_data[65] & 0x01;
+
+       cyapa->btn_capability = (resp_data[70] << 3) & CAPABILITY_BTN_MASK;
+
+       memcpy(&cyapa->product_id[0], &resp_data[33], 5);
+       cyapa->product_id[5] = '-';
+       memcpy(&cyapa->product_id[6], &resp_data[38], 6);
+       cyapa->product_id[12] = '-';
+       memcpy(&cyapa->product_id[13], &resp_data[44], 2);
+       cyapa->product_id[15] = '\0';
+
+       if (!cyapa->electrodes_x || !cyapa->electrodes_y ||
+               !cyapa->physical_size_x || !cyapa->physical_size_y ||
+               !cyapa->max_abs_x || !cyapa->max_abs_y || !cyapa->max_z)
+               return -EINVAL;
+
+       return 0;
+}
+
+static int cyapa_gen5_do_operational_check(struct cyapa *cyapa)
+{
+       struct device *dev = &cyapa->client->dev;
+       int ret;
+
+       if (cyapa->gen != CYAPA_GEN5)
+               return -EINVAL;
+
+       cyapa_enable_irq_save(cyapa);
+       switch (cyapa->state) {
+       case CYAPA_STATE_GEN5_BL:
+               ret = cyapa_gen5_bl_exit(cyapa);
+               if (ret) {
+                       /* try to update trackpad product information. */
+                       cyapa_gen5_bl_query_data(cyapa);
+                       goto out;
+               }
+
+               cyapa->state = CYAPA_STATE_GEN5_APP;
+
+       case CYAPA_STATE_GEN5_APP:
+               /* if trackpad device in deep sleep mode,
+                * the app command will fail.
+                * So always reset trackpad device to full active when
+                * the device state is requeried.
+                */
+               ret = cyapa_gen5_set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE, 0);
+               if (ret)
+                       goto out;
+
+               /* Get trackpad product information. */
+               ret = cyapa_gen5_get_query_data(cyapa);
+               if (ret)
+                       goto out;
+               /* only support product ID starting with CYTRA */
+               if (memcmp(cyapa->product_id, unique_str,
+                               strlen(unique_str)) != 0) {
+                       dev_err(dev, "%s: unknown product ID (%s)\n",
+                               __func__, cyapa->product_id);
+                       ret = -EINVAL;
+               }
+               break;
+       default:
+               ret = -EINVAL;
+       }
+
+out:
+       cyapa_irq_restore(cyapa);
+       return ret;
+}
+
+/*
+ * return false, do not continue process
+ * return true, continue process.
+ */
+static bool cyapa_gen5_irq_cmd_handler(struct cyapa *cyapa)
+{
+       int length;
+
+       if (atomic_read(&gen5_pip->cmd_issued)) {
+               /*
+                * read out all none command response data.
+                * these output data may caused by user put finger on
+                * trackpad when host waiting the command response.
+                */
+               cyapa_i2c_pip_read(cyapa, gen5_pip->irq_cmd_buf, 2);
+               length = get_unaligned_le16(gen5_pip->irq_cmd_buf);
+               length = (length <= 2) ? 2 : length;
+               if (length > 2)
+                       cyapa_i2c_pip_read(cyapa,
+                               gen5_pip->irq_cmd_buf, length);
+               if (!(gen5_pip->resp_sort_func &&
+                       gen5_pip->resp_sort_func(cyapa,
+                               gen5_pip->irq_cmd_buf, length))) {
+                       /*
+                        * Cover the Gen5 V1 firmware issue.
+                        * The issue is there is no interrut will be
+                        * asserted to notityf host to read a command
+                        * data out when always has finger touch on
+                        * trackpad during the command is issued to
+                        * trackad device.
+                        * This issue has the scenario is that,
+                        * user always has his fingers touched on
+                        * trackpad device when booting/rebooting
+                        * their chrome book.
+                        */
+                       length = *gen5_pip->resp_len;
+                       cyapa_empty_pip_output_data(cyapa,
+                                       gen5_pip->resp_data,
+                                       &length,
+                                       gen5_pip->resp_sort_func);
+                       if (gen5_pip->resp_len && length != 0) {
+                               *gen5_pip->resp_len = length;
+                               atomic_dec(&gen5_pip->cmd_issued);
+                               complete(&gen5_pip->cmd_ready);
+                       }
+                       return false;
+               }
+
+               if (gen5_pip->resp_data && gen5_pip->resp_len) {
+                       *gen5_pip->resp_len = (*gen5_pip->resp_len < length) ?
+                               *gen5_pip->resp_len : length;
+                       memcpy(gen5_pip->resp_data, gen5_pip->irq_cmd_buf,
+                               *gen5_pip->resp_len);
+               }
+               atomic_dec(&gen5_pip->cmd_issued);
+               complete(&gen5_pip->cmd_ready);
+               return false;
+       }
+
+       return true;
+}
+
+static void cyapa_gen5_irq_handler(struct cyapa *cyapa)
+{
+       struct input_dev *input = cyapa->input;
+       struct cyapa_gen5_report_data report_data;
+       int i;
+       int ret;
+       u8 report_id;
+       u8 buttons;
+       unsigned int report_len, touch_num;
+       int x, y;
+
+       if (cyapa->gen != CYAPA_GEN5 ||
+               cyapa->state != CYAPA_STATE_GEN5_APP) {
+               async_schedule(cyapa_detect_async, cyapa);
+               return;
+       }
+
+       ret = cyapa_i2c_pip_read(cyapa, (u8 *)&report_data,
+                       GEN5_TOUCH_REPORT_HEAD_SIZE);
+       if (ret != GEN5_TOUCH_REPORT_HEAD_SIZE) {
+               /* failed to read report head data. */
+               async_schedule(cyapa_detect_async, cyapa);
+               return;
+       }
+
+       report_len = get_unaligned_le16(&report_data.report_head[0]);
+       if (report_len <= 2) {
+               /*
+                * trackpad power up event or end of one touch packets report,
+                * no data for report.
+                */
+               if (report_len != 2)
+                       async_schedule(cyapa_detect_async, cyapa);
+
+               return;
+       }
+
+       report_id = report_data.report_head[2];
+       if (report_id == GEN5_WAKEUP_EVENT_REPORT_ID &&
+                       report_len == GEN5_WAKEUP_EVENT_SIZE) {
+               /* Wake event from deep sleep mode, reset power state. */
+               return;
+       } else if (report_id != GEN5_TOUCH_REPORT_ID &&
+                       report_id != GEN5_BTN_REPORT_ID &&
+                       report_id != GEN5_OLD_PUSH_BTN_REPORT_ID &&
+                       report_id != GEN5_PUSH_BTN_REPORT_ID) {
+               /* Running in BL mode or unknown response data read. */
+
+               async_schedule(cyapa_detect_async, cyapa);
+               return;
+       }
+
+       if (report_len > GEN5_TOUCH_REPORT_HEAD_SIZE) {
+               /* must make sure to read all data through out before return. */
+               ret = cyapa_i2c_pip_read(cyapa, (u8 *)&report_data, report_len);
+               if (ret != report_len) {
+                       /* failed to read report head data. */
+                       async_schedule(cyapa_detect_async, cyapa);
+                       return;
+               }
+       }
+
+       if (report_id == GEN5_TOUCH_REPORT_ID &&
+               (report_len < GEN5_TOUCH_REPORT_HEAD_SIZE ||
+                       report_len > GEN5_TOUCH_REPORT_MAX_SIZE)) {
+               /* Invald report data length for finger packet. */
+               async_schedule(cyapa_detect_async, cyapa);
+               return;
+       }
+
+       if ((report_id == GEN5_BTN_REPORT_ID ||
+                       report_id == GEN5_OLD_PUSH_BTN_REPORT_ID ||
+                       report_id == GEN5_PUSH_BTN_REPORT_ID) &&
+               (report_len < GEN5_BTN_REPORT_HEAD_SIZE ||
+                       report_len > GEN5_BTN_REPORT_MAX_SIZE)) {
+               /* Invald report data length of button packet. */
+               async_schedule(cyapa_detect_async, cyapa);
+               return;
+       }
+
+       if (report_id == GEN5_BTN_REPORT_ID ||
+                       report_id == GEN5_OLD_PUSH_BTN_REPORT_ID ||
+                       report_id == GEN5_PUSH_BTN_REPORT_ID) {
+               /* button report data */
+               buttons = (report_data.report_head[5] << 3) &
+                                       CAPABILITY_BTN_MASK;
+               if (cyapa->btn_capability & CAPABILITY_LEFT_BTN_MASK) {
+                       input_report_key(input, BTN_LEFT,
+                               !!(buttons & CAPABILITY_LEFT_BTN_MASK));
+               }
+               if (cyapa->btn_capability & CAPABILITY_MIDDLE_BTN_MASK) {
+                       input_report_key(input, BTN_MIDDLE,
+                               !!(buttons & CAPABILITY_MIDDLE_BTN_MASK));
+               }
+               if (cyapa->btn_capability & CAPABILITY_RIGHT_BTN_MASK) {
+                       input_report_key(input, BTN_RIGHT,
+                               !!(buttons & CAPABILITY_RIGHT_BTN_MASK));
+               }
+
+               input_sync(input);
+       } else {
+               /* touch report data */
+               touch_num = report_data.report_head[5] &
+                                       GEN5_NUMBER_OF_TOUCH_MASK;
+
+               for (i = 0; i < touch_num; i++) {
+                       const struct cyapa_gen5_touch_record *touch =
+                               &report_data.touch_records[i];
+                       u8 event_id =
+                               GEN5_GET_EVENT_ID(touch->touch_tip_event_id);
+                       int slot = GEN5_GET_TOUCH_ID(touch->touch_tip_event_id);
+
+                       if (event_id == RECORD_EVENT_LIFTOFF)
+                               continue;
+
+                       input_mt_slot(input, slot);
+                       input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
+                       x = (touch->x_hi << 8) | touch->x_lo;
+                       if (cyapa->x_origin)
+                               x = cyapa->max_abs_x - x;
+                       input_report_abs(input, ABS_MT_POSITION_X, x);
+                       y = (touch->y_hi << 8) | touch->y_lo;
+                       if (cyapa->y_origin)
+                               y = cyapa->max_abs_y - y;
+                       input_report_abs(input, ABS_MT_POSITION_Y, y);
+                       input_report_abs(input, ABS_MT_PRESSURE,
+                               touch->z);
+                       input_report_abs(input, ABS_MT_TOUCH_MAJOR,
+                               touch->major_axis_len);
+                       input_report_abs(input, ABS_MT_TOUCH_MINOR,
+                               touch->minor_axis_len);
+
+                       input_report_abs(input, ABS_MT_WIDTH_MAJOR,
+                               touch->major_tool_len);
+                       input_report_abs(input, ABS_MT_WIDTH_MINOR,
+                               touch->minor_tool_len);
+
+                       input_report_abs(input, ABS_MT_ORIENTATION,
+                               touch->orientation);
+               }
+
+               input_mt_sync_frame(input);
+
+               input_sync(input);
+       }
+}
+
+const struct cyapa_dev_ops cyapa_gen5_ops = {
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+
+       NULL,
+       NULL,
+
+       NULL,
+       NULL,
+
+       cyapa_gen5_get_private_size,
+       cyapa_gen5_private_init,
+
+       cyapa_gen5_state_parse,
+       cyapa_gen5_do_operational_check,
+
+       cyapa_gen5_irq_handler,
+       cyapa_gen5_irq_cmd_handler,
+       cyapa_empty_pip_output_data,
+       cyapa_gen5_set_power_mode,
+};
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.

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 23902 bytes --]

^ permalink raw reply related

* [PATCH v2 11/14] input: cyapa: add gen5 trackpad device firmware update function supported
From: Dudley Du @ 2014-06-06  7:29 UTC (permalink / raw)
  To: Dmitry Torokhov, Rafael J. Wysocki, Alan Stern
  Cc: Benson Leung, Lily Rui, Daniel Kurtz,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 13512 bytes --]

Add firmware image update function supported for gen5 trackpad device,
which its function is supplied through cyapa core update_fw interface.
TEST=test on Chomebooks.

Signed-off-by: Du, Dudley <dudl@cypress.com>
---
diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index 6b8441f..e484569 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -205,7 +205,7 @@ config MOUSE_BCM5974

 config MOUSE_CYAPA
        tristate "Cypress APA I2C Trackpad support"
-       depends on I2C
+       depends on I2C && CRC_ITU_T
        help
          This driver adds support for Cypress All Points Addressable (APA)
          I2C Trackpads, including the ones used in 2012 Samsung Chromebooks.
diff --git a/drivers/input/mouse/cyapa_gen5.c b/drivers/input/mouse/cyapa_gen5.c
index 00ca3a6..e720eed 100644
--- a/drivers/input/mouse/cyapa_gen5.c
+++ b/drivers/input/mouse/cyapa_gen5.c
@@ -18,6 +18,7 @@
 #include <linux/completion.h>
 #include <linux/slab.h>
 #include <linux/unaligned/access_ok.h>
+#include <linux/crc-itu-t.h>
 #include "cyapa.h"


@@ -856,6 +857,86 @@ out:
        return -EAGAIN;
 }

+static int cyapa_gen5_bl_initiate(struct cyapa *cyapa,
+               const struct firmware *fw)
+{
+       int ret = 0;
+       u16 length = 0;
+       u16 data_len = 0;
+       u16 meta_data_crc = 0;
+       u16 cmd_crc = 0;
+       u8 bl_gen5_activate[18 + CYAPA_TSG_FLASH_MAP_BLOCK_SIZE + 3];
+       int bl_gen5_activate_size = 0;
+       u8 resp_data[11];
+       int resp_len;
+       struct cyapa_tsg_bin_image *image;
+       int records_num;
+       u8 *data;
+
+       /* Try to dump all bufferred report data before send any command. */
+       cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
+
+       bl_gen5_activate_size = sizeof(bl_gen5_activate);
+       memset(bl_gen5_activate, 0, bl_gen5_activate_size);
+
+       /* Output Report Register Address[15:0] = 0004h */
+       bl_gen5_activate[0] = 0x04;
+       bl_gen5_activate[1] = 0x00;
+
+       /* totoal command length[15:0] */
+       length = bl_gen5_activate_size - 2;
+       put_unaligned_le16(length, &bl_gen5_activate[2]);
+       bl_gen5_activate[4] = 0x40;  /* Report ID = 40h */
+       bl_gen5_activate[5] = 0x00;  /* RSVD = 00h */
+
+       bl_gen5_activate[6] = GEN5_SOP_KEY;  /* SOP = 01h */
+       bl_gen5_activate[7] = 0x48;  /* Command Code = 48h */
+
+       /* 8 Key bytes and block size */
+       data_len = CYAPA_TSG_BL_KEY_SIZE + CYAPA_TSG_FLASH_MAP_BLOCK_SIZE;
+       /* Data Length[15:0] */
+       put_unaligned_le16(data_len, &bl_gen5_activate[8]);
+       bl_gen5_activate[10] = 0xa5;  /* Key Byte 0 */
+       bl_gen5_activate[11] = 0x01;
+       bl_gen5_activate[12] = 0x02;  /*     .      */
+       bl_gen5_activate[13] = 0x03;  /*     .      */
+       bl_gen5_activate[14] = 0xff;  /*     .      */
+       bl_gen5_activate[15] = 0xfe;
+       bl_gen5_activate[16] = 0xfd;
+       bl_gen5_activate[17] = 0x5a;  /* Key Byte 7 */
+
+       /* copy 60 bytes Meta Data Row Parameters */
+       image = (struct cyapa_tsg_bin_image *)fw->data;
+       records_num = (fw->size - sizeof(struct cyapa_tsg_bin_image_head)) /
+                               sizeof(struct cyapa_tsg_bin_image_data_record);
+       /* APP_INTEGRITY row is always the last row block */
+       data = image->records[records_num - 1].record_data;
+       memcpy(&bl_gen5_activate[18], data, CYAPA_TSG_FLASH_MAP_METADATA_SIZE);
+
+       meta_data_crc = crc_itu_t(0xffff, &bl_gen5_activate[18],
+                               CYAPA_TSG_FLASH_MAP_METADATA_SIZE);
+       /* Meta Data CRC[15:0] */
+       put_unaligned_le16(meta_data_crc,
+               &bl_gen5_activate[18 + CYAPA_TSG_FLASH_MAP_METADATA_SIZE]);
+
+       cmd_crc = crc_itu_t(0xffff, &bl_gen5_activate[6], 4 + data_len);
+       put_unaligned_le16(cmd_crc,
+               &bl_gen5_activate[bl_gen5_activate_size - 3]);  /* CRC[15:0] */
+       bl_gen5_activate[bl_gen5_activate_size - 1] = GEN5_EOP_KEY;
+
+       resp_len = sizeof(resp_data);
+       ret = cyapa_i2c_pip_cmd_irq_sync(cyapa,
+                       bl_gen5_activate, sizeof(bl_gen5_activate),
+                       resp_data, &resp_len, 12000,
+                       cyapa_gen5_sort_tsg_pip_bl_resp_data);
+       if (ret || resp_len != GEN5_BL_INITIATE_RESP_LEN ||
+                       resp_data[2] != GEN5_BL_RESP_REPORT_ID ||
+                       !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5]))
+               return (ret < 0) ? ret : -EAGAIN;
+
+       return 0;
+}
+
 bool cyapa_gen5_sort_bl_exit_data(struct cyapa *cyapa, u8 *buf, int len)
 {
        if (buf == NULL || len < GEN5_RESP_LENGTH_SIZE)
@@ -902,6 +983,216 @@ static int cyapa_gen5_bl_exit(struct cyapa *cyapa)
        return -EAGAIN;
 }

+static int cyapa_gen5_bl_enter(struct cyapa *cyapa)
+{
+       int ret;
+       u8 cmd[] = { 0x04, 0x00, 0x05, 0x00, 0x2F, 0x00, 0x01 };
+       u8 resp_data[2];
+       int resp_len;
+
+       if (cyapa->input) {
+               cyapa_disable_irq(cyapa);
+               input_unregister_device(cyapa->input);
+               cyapa->input = NULL;
+       }
+       cyapa_enable_irq(cyapa);
+
+       ret = cyapa_poll_state(cyapa, 500);
+       if (ret < 0)
+               return ret;
+       if (cyapa->gen != CYAPA_GEN5)
+               return -EINVAL;
+
+       /* Already in Gen5 BL. Skipping exit. */
+       if (cyapa->state == CYAPA_STATE_GEN5_BL)
+               return 0;
+
+       if (cyapa->state != CYAPA_STATE_GEN5_APP)
+               return -EAGAIN;
+
+       /* Try to dump all bufferred report data before send any command. */
+       cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
+
+       /*
+        * send bootloader enter command to trackpad device,
+        * after enter bootloader, the response data is two bytes of 0x00 0x00.
+        */
+       resp_len = sizeof(resp_data);
+       memset(resp_data, 0, resp_len);
+       ret = cyapa_i2c_pip_cmd_irq_sync(cyapa,
+                       cmd, sizeof(cmd),
+                       resp_data, &resp_len,
+                       5000, cyapa_gen5_sort_application_launch_data);
+       if (ret || resp_data[0] != 0x00 || resp_data[1] != 0x00)
+               return (ret < 0) ? ret : -EAGAIN;
+
+       cyapa->state = CYAPA_STATE_GEN5_BL;
+       return 0;
+}
+
+static int cyapa_gen5_check_fw(struct cyapa *cyapa, const struct firmware *fw)
+{
+       int i;
+       struct cyapa_tsg_bin_image *image;
+       int flash_records_count;
+       u16 expected_app_crc;
+       u16 expected_app_integrity_crc;
+       u16 app_crc = 0;
+       u16 app_integrity_crc = 0;
+       u16 row_num;
+       u8 *data;
+       u32 app_start;
+       u16 app_len;
+       u32 img_start;
+       u16 img_len;
+       int record_index;
+       struct device *dev = &cyapa->client->dev;
+
+       image = (struct cyapa_tsg_bin_image *)fw->data;
+       flash_records_count = (fw->size -
+                       sizeof(struct cyapa_tsg_bin_image_head)) /
+                       sizeof(struct cyapa_tsg_bin_image_data_record);
+
+       /* APP_INTEGRITY row is always the last row block,
+        * and the row id must be 0x01ff */
+       row_num = get_unaligned_be16(
+                       &image->records[flash_records_count - 1].row_number);
+       if (&image->records[flash_records_count - 1].flash_array_id != 0x00 &&
+                       row_num != 0x01ff) {
+               dev_err(dev, "%s: invaid app_integrity data.\n", __func__);
+               return -EINVAL;
+       }
+       data = image->records[flash_records_count - 1].record_data;
+       app_start = get_unaligned_le32(&data[4]);
+       app_len = get_unaligned_le16(&data[8]);
+       expected_app_crc = get_unaligned_le16(&data[10]);
+       img_start = get_unaligned_le32(&data[16]);
+       img_len = get_unaligned_le16(&data[20]);
+       expected_app_integrity_crc = get_unaligned_le16(&data[60]);
+
+       if ((app_start + app_len + img_start + img_len) %
+                       CYAPA_TSG_FW_ROW_SIZE) {
+               dev_err(dev, "%s: invaid image alignment.\n", __func__);
+               return -EINVAL;
+       }
+
+       /* verify app_integrity crc */
+       app_integrity_crc = crc_itu_t(0xffff, data,
+                       CYAPA_TSG_APP_INTEGRITY_SIZE);
+       if (app_integrity_crc != expected_app_integrity_crc) {
+               dev_err(dev, "%s: invaid app_integrity crc.\n", __func__);
+               return -EINVAL;
+       }
+
+       /*
+        * verify application image CRC
+        */
+       record_index = app_start / CYAPA_TSG_FW_ROW_SIZE -
+                               CYAPA_TSG_IMG_START_ROW_NUM;
+       data = (u8 *)&image->records[record_index].record_data;
+       app_crc = crc_itu_t(0xffff, data, CYAPA_TSG_FW_ROW_SIZE);
+       for (i = 1; i < (app_len / CYAPA_TSG_FW_ROW_SIZE); i++) {
+               data = (u8 *)&image->records[++record_index].record_data;
+               app_crc = crc_itu_t(app_crc, data, CYAPA_TSG_FW_ROW_SIZE);
+       }
+
+       if (app_crc != expected_app_crc) {
+               dev_err(dev, "%s: invaid firmware app crc check.\n", __func__);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int cyapa_gen5_write_fw_block(struct cyapa *cyapa,
+               struct cyapa_tsg_bin_image_data_record *flash_record)
+{
+       u8 flash_array_id;
+       u16 flash_row_id;
+       u16 record_len;
+       u8 *record_data;
+       u8 cmd[144];  /* 13 + 128+ 3 */
+       u16 cmd_len;
+       u16 data_len;
+       u16 crc;
+       u8 resp_data[11];
+       int resp_len;
+       int ret;
+
+       flash_array_id = flash_record->flash_array_id;
+       flash_row_id = get_unaligned_be16(&flash_record->row_number);
+       record_len = get_unaligned_be16(&flash_record->record_len);
+       record_data = flash_record->record_data;
+
+       cmd_len = sizeof(cmd) - 2; /* not include 2 bytes regisetr address. */
+       memset(cmd, 0, cmd_len + 2);
+       cmd[0] = 0x04;  /* register address */
+       cmd[1] = 0x00;
+
+       put_unaligned_le16(cmd_len, &cmd[2]);
+       cmd[4] = 0x40;  /* report id 40h */
+       cmd[5] = 0x00;
+
+       cmd[6] = GEN5_SOP_KEY;  /* SOP = 01h */
+       cmd[7] = 0x39;  /* command code = 39h */
+       /* 1 (Flash Array ID) + 2 (Flash Row ID) + 128 (flash data) */
+       data_len = 3 + record_len;
+       put_unaligned_le16(data_len, &cmd[8]);
+       cmd[10] = flash_array_id;  /* Flash Array ID = 00h */
+       put_unaligned_le16(flash_row_id, &cmd[11]);
+
+       memcpy(&cmd[13], record_data, record_len);
+       crc = crc_itu_t(0xffff, &cmd[6], 4 + data_len);
+       put_unaligned_le16(crc, &cmd[2 + cmd_len - 3]);
+       cmd[2 + cmd_len - 1] = GEN5_EOP_KEY;
+
+       resp_len = sizeof(resp_data);
+       ret = cyapa_i2c_pip_cmd_irq_sync(cyapa,
+                       cmd, sizeof(cmd),
+                       resp_data, &resp_len,
+                       500, cyapa_gen5_sort_tsg_pip_bl_resp_data);
+       if (ret || resp_len != GEN5_BL_BLOCK_WRITE_RESP_LEN ||
+                       resp_data[2] != GEN5_BL_RESP_REPORT_ID ||
+                       !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5]))
+               return ret < 0 ? ret : -EAGAIN;
+
+       return 0;
+}
+
+static int cyapa_gen5_do_fw_update(struct cyapa *cyapa,
+               const struct firmware *fw)
+{
+       struct device *dev = &cyapa->client->dev;
+       struct cyapa_tsg_bin_image *image =
+               (struct cyapa_tsg_bin_image *)fw->data;
+       struct cyapa_tsg_bin_image_data_record *flash_record;
+       int flash_records_count;
+       int i;
+       int ret;
+
+       /* Try to dump all bufferred data if exists before send commands. */
+       cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
+
+       flash_records_count =
+               (fw->size - sizeof(struct cyapa_tsg_bin_image_head)) /
+                       sizeof(struct cyapa_tsg_bin_image_data_record);
+       /*
+        * the last flash row 0x01ff has been written through bl_initiate
+        *  command, so DO NOT write flash 0x01ff to trackpad device.
+        */
+       for (i = 0; i < (flash_records_count - 1); i++) {
+               flash_record = &image->records[i];
+               ret = cyapa_gen5_write_fw_block(cyapa, flash_record);
+               if (ret) {
+                       dev_err(dev, "%s: Gen5 FW update aborted, %d\n",
+                               __func__, ret);
+                       return ret;
+               }
+       }
+
+       return 0;
+}
+
 static int cyapa_gen5_change_power_state(struct cyapa *cyapa, u8 power_state)
 {
        int ret;
@@ -1568,11 +1859,11 @@ static void cyapa_gen5_irq_handler(struct cyapa *cyapa)
 }

 const struct cyapa_dev_ops cyapa_gen5_ops = {
+       cyapa_gen5_check_fw,
+       cyapa_gen5_bl_enter,
        NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
+       cyapa_gen5_bl_initiate,
+       cyapa_gen5_do_fw_update,
        NULL,
        NULL,

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.

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 8819 bytes --]

^ permalink raw reply related

* [PATCH v2 12/14] input: cyapa: add gen5 trackpad device baseline and calibrate functions supported
From: Dudley Du @ 2014-06-06  7:29 UTC (permalink / raw)
  To: Dmitry Torokhov, Rafael J. Wysocki, Alan Stern
  Cc: Benson Leung, Lily Rui, Daniel Kurtz,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 29109 bytes --]

Add report baseline and force calibrate functions supported for gen5
trackpad device, which these functions are supplied through
cyapa core baseline and calibrate interfaces.
TEST=test on Chomebooks.

Signed-off-by: Du, Dudley <dudl@cypress.com>
---
diff --git a/drivers/input/mouse/cyapa_gen5.c b/drivers/input/mouse/cyapa_gen5.c
index e720eed..3da6a91 100644
--- a/drivers/input/mouse/cyapa_gen5.c
+++ b/drivers/input/mouse/cyapa_gen5.c
@@ -1479,6 +1479,679 @@ static int cyapa_gen5_set_power_mode(struct cyapa *cyapa,
        return ret;
 }

+static int cyapa_gen5_resume_scanning(struct cyapa *cyapa)
+{
+       u8 cmd[7] = { 0x04, 0x00, 0x05, 0x00, 0x2f, 0x00, 0x04 };
+       u8 resp_data[6];
+       int resp_len;
+       int ret;
+
+       /* Try to dump all bufferred data before doing command. */
+       cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
+
+       resp_len = 6;
+       ret = cyapa_i2c_pip_cmd_irq_sync(cyapa,
+                       cmd, 7,
+                       resp_data, &resp_len,
+                       500, cyapa_gen5_sort_tsg_pip_app_resp_data);
+       if (ret || resp_data[2] != GEN5_APP_RESP_REPORT_ID ||
+                       resp_data[3] != GEN5_RESP_RSVD_KEY ||
+                       GET_GEN5_CMD_CODE(resp_data[4]) != 0x04)
+               return -EINVAL;
+
+       /* Try to dump all bufferred data when resuming scanning. */
+       cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
+
+       return 0;
+}
+
+static int cyapa_gen5_suspend_scanning(struct cyapa *cyapa)
+{
+       u8 cmd[7] = { 0x04, 0x00, 0x05, 0x00, 0x2f, 0x00, 0x03 };
+       u8 resp_data[6];
+       int resp_len;
+       int ret;
+
+       /* Try to dump all bufferred data before doing command. */
+       cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
+
+       resp_len = 6;
+       ret = cyapa_i2c_pip_cmd_irq_sync(cyapa,
+                       cmd, 7,
+                       resp_data, &resp_len,
+                       500, cyapa_gen5_sort_tsg_pip_app_resp_data);
+       if (ret || resp_data[2] != GEN5_APP_RESP_REPORT_ID ||
+                       resp_data[3] != GEN5_RESP_RSVD_KEY ||
+                       GET_GEN5_CMD_CODE(resp_data[4]) != 0x03)
+               return -EINVAL;
+
+       /* Try to dump all bufferred data when suspending scanning. */
+       cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
+
+       return 0;
+}
+
+static int cyapa_gen5_calibrate_pwcs(struct cyapa *cyapa,
+               u8 calibrate_sensing_mode_type)
+{
+       int ret;
+       u8 cmd[8];
+       u8 resp_data[6];
+       int resp_len;
+
+       /* Try to dump all bufferred data before doing command. */
+       cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
+
+       cmd[0] = 0x04;
+       cmd[1] = 0x00;
+       cmd[2] = 0x06;
+       cmd[3] = 0x00;
+       cmd[4] = GEN5_APP_CMD_REPORT_ID;
+       cmd[5] = 0x00;
+       cmd[6] = GEN5_CMD_CALIBRATE;
+       cmd[7] = calibrate_sensing_mode_type;
+       resp_len = sizeof(resp_data);
+       ret = cyapa_i2c_pip_cmd_irq_sync(cyapa,
+                       cmd, sizeof(cmd),
+                       resp_data, &resp_len,
+                       5000, cyapa_gen5_sort_tsg_pip_app_resp_data);
+       if (ret || resp_data[2] != GEN5_APP_RESP_REPORT_ID ||
+                       GET_GEN5_CMD_CODE(resp_data[4]) != GEN5_CMD_CALIBRATE ||
+                       !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5]))
+               return ret < 0 ? ret : -EAGAIN;
+
+       return 0;
+}
+
+static ssize_t cyapa_gen5_do_calibrate(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+       struct cyapa *cyapa = dev_get_drvdata(dev);
+       int ret, calibrate_ret;
+
+       /* 1. suspend Scanning*/
+       ret = cyapa_gen5_suspend_scanning(cyapa);
+       if (ret)
+               return ret;
+
+       /* 2. do mutual capacitance fine calibrate. */
+       calibrate_ret = cyapa_gen5_calibrate_pwcs(cyapa,
+                               CYAPA_SENSING_MODE_MUTUAL_CAP_FINE);
+       if (calibrate_ret)
+               goto resume_scanning;
+
+       /* 3. do self capacitance calibrate. */
+       calibrate_ret = cyapa_gen5_calibrate_pwcs(cyapa,
+                               CYAPA_SENSING_MODE_SELF_CAP);
+       if (calibrate_ret)
+               goto resume_scanning;
+
+resume_scanning:
+       /* 4. resume Scanning*/
+       ret = cyapa_gen5_resume_scanning(cyapa);
+       if (ret || calibrate_ret)
+               return ret ? ret : calibrate_ret;
+
+       return count;
+}
+
+static s32 two_complement_to_s32(s32 value, int num_bits)
+{
+       if (value >> (num_bits - 1))
+               value |=  -1 << num_bits;
+       return value;
+}
+
+static s32 cyapa_parse_structure_data(u8 data_format, u8 *buf, int buf_len)
+{
+       int data_size;
+       bool big_endian;
+       bool unsigned_type;
+       s32 value;
+
+       data_size = (data_format & 0x07);
+       big_endian = ((data_format & 0x10) == 0x00);
+       unsigned_type = ((data_format & 0x20) == 0x00);
+
+       if (buf_len < data_size)
+               return 0;
+
+       switch (data_size) {
+       case 1:
+               value  = buf[0];
+               break;
+       case 2:
+               if (big_endian)
+                       value = get_unaligned_be16(buf);
+               else
+                       value = get_unaligned_le16(buf);
+               break;
+       case 4:
+               if (big_endian)
+                       value = get_unaligned_be32(buf);
+               else
+                       value = get_unaligned_le32(buf);
+               break;
+       default:
+               /* should not happen, just as default case here. */
+               value = 0;
+               break;
+       }
+
+       if (!unsigned_type)
+               value = two_complement_to_s32(value, data_size * 8);
+
+       return value;
+}
+
+
+/*
+ * Read all the global mutual or self idac data or mutual or self local PWC
+ * data based on the @idac_data_type.
+ * If the input value of @data_size is 0, then means read global mutual or
+ * self idac data. For read global mutual idac data, @idac_max, @idac_min and
+ * @idac_ave are in order used to return the max value of global mutual idac
+ * data, the min value of global mutual idac and the average value of the
+ * global mutual idac data. For read global self idac data, @idac_max is used
+ * to return the global self cap idac data in Rx direction, @idac_min is used
+ * to return the global self cap idac data in Tx direction. @idac_ave is not
+ * used.
+ * If the input value of @data_size is not 0, than means read the mutual or
+ * self local PWC data. The @idac_max, @idac_min and @idac_ave are used to
+ * return the max, min and average value of the mutual or self local PWC data.
+ * Note, in order to raed mutual local PWC data, must read invoke this function
+ * to read the mutual global idac data firstly to set the correct Rx number
+ * value, otherwise, the read mutual idac and PWC data may not correct.
+ */
+static int cyapa_gen5_read_idac_data(struct cyapa *cyapa,
+               u8 cmd_code, u8 idac_data_type, int *data_size,
+               int *idac_max, int *idac_min, int *idac_ave)
+{
+       int ret;
+       int i;
+       u8 cmd[12];
+       u8 resp_data[256];
+       int resp_len;
+       int read_len;
+       int value;
+       u16 offset;
+       int read_elements;
+       bool read_global_idac;
+       int sum, count, max_element_cnt;
+       int tmp_max, tmp_min, tmp_ave, tmp_sum, tmp_count, tmp_max_elements;
+       int electrodes_rx;
+
+       if (cmd_code != GEN5_CMD_RETRIEVE_DATA_STRUCTURE ||
+               (idac_data_type != GEN5_RETRIEVE_MUTUAL_PWC_DATA &&
+               idac_data_type != GEN5_RETRIEVE_SELF_CAP_PWC_DATA) ||
+               !data_size || !idac_max || !idac_min || !idac_ave)
+               return -EINVAL;
+
+       *idac_max = INT_MIN;
+       *idac_min = INT_MAX;
+       sum = count = tmp_count = 0;
+       electrodes_rx = 0;
+       tmp_max_elements = 0;
+       if (*data_size == 0) {
+               /* Read global idac values firstly.
+                * Currently, no idac data exceed 4 bytes. */
+               read_global_idac = true;
+               offset = 0;
+               *data_size = 4;
+
+               if (idac_data_type == GEN5_RETRIEVE_MUTUAL_PWC_DATA) {
+                       if (cyapa->electrodes_rx == 0) {
+                               if (cyapa->electrodes_y > cyapa->electrodes_x) {
+                                       electrodes_rx = cyapa->electrodes_y;
+                                       tmp_max_elements = cyapa->electrodes_x;
+                               } else {
+                                       electrodes_rx = cyapa->electrodes_x;
+                                       tmp_max_elements = cyapa->electrodes_y;
+                               }
+                       } else {
+                               electrodes_rx = cyapa->electrodes_rx;
+                               tmp_max_elements = 0;  /* disable Rx detect. */
+                       }
+                       max_element_cnt = ((electrodes_rx + 7) / 8) * 8;
+                       tmp_max = INT_MIN;
+                       tmp_min = INT_MAX;
+                       tmp_ave = tmp_sum = tmp_count = 0;
+               } else
+                       max_element_cnt = 2;
+       } else {
+               read_global_idac = false;
+               if (*data_size > 4)
+                       *data_size = 4;
+               /* calculate the start offset in bytes of local PWC data. */
+               if (idac_data_type == GEN5_RETRIEVE_MUTUAL_PWC_DATA) {
+                       offset = ((cyapa->electrodes_rx + 7) / 8) * 8
+                                               * (*data_size);
+                       if (cyapa->electrodes_rx == cyapa->electrodes_x)
+                               tmp_count = cyapa->electrodes_y;
+                       else
+                               tmp_count = cyapa->electrodes_x;
+                       max_element_cnt = ((cyapa->electrodes_rx + 7) / 8) *
+                                               8 * tmp_count;
+               } else if (idac_data_type == GEN5_RETRIEVE_SELF_CAP_PWC_DATA) {
+                       offset = 2;
+                       max_element_cnt = cyapa->electrodes_x +
+                                               cyapa->electrodes_y;
+               }
+       }
+
+       do {
+               read_elements = (256 - 10) / (*data_size);
+               read_elements = min(read_elements, max_element_cnt - count);
+               read_len = read_elements * (*data_size);
+
+               cmd[0] = 0x04;
+               cmd[1] = 0x00;
+               cmd[2] = 0x0a;
+               cmd[3] = 0x00;
+               cmd[4] = GEN5_APP_CMD_REPORT_ID;
+               cmd[5] = 0x00;
+               cmd[6] = cmd_code;
+               put_unaligned_le16(offset, &cmd[7]); /* Read Offset[15:0] */
+               put_unaligned_le16(read_len, &cmd[9]); /* Read Length[15:0] */
+               cmd[11] = idac_data_type;
+               resp_len = 10 + read_len;
+               ret = cyapa_i2c_pip_cmd_irq_sync(cyapa,
+                               cmd, 12,
+                               resp_data, &resp_len,
+                               500, cyapa_gen5_sort_tsg_pip_app_resp_data);
+               if (ret || resp_len < 10 || resp_data[2] !=
+                                       GEN5_APP_RESP_REPORT_ID ||
+                               GET_GEN5_CMD_CODE(resp_data[4]) != cmd_code ||
+                               !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5]) ||
+                               resp_data[6] != idac_data_type)
+                       return (ret < 0) ? ret : -EAGAIN;
+               read_len = get_unaligned_le16(&resp_data[7]);
+               if (read_len == 0)
+                       break;
+
+               *data_size = (resp_data[9] & GEN5_PWC_DATA_ELEMENT_SIZE_MASK);
+               if (read_len < *data_size)
+                       return -EINVAL;
+
+               if (read_global_idac &&
+                       idac_data_type == GEN5_RETRIEVE_SELF_CAP_PWC_DATA) {
+                       /* Rx's self global idac data. */
+                       *idac_max = cyapa_parse_structure_data(
+                                       resp_data[9], &resp_data[10],
+                                       *data_size);
+                       /* Tx's self global idac data. */
+                       *idac_min = cyapa_parse_structure_data(
+                                       resp_data[9],
+                                       &resp_data[10 + *data_size],
+                                       *data_size);
+                       break;
+               }
+
+               /* read mutual global idac or local mutual/self PWC data. */
+               offset += read_len;
+               for (i = 10; i < (read_len + 10); i += *data_size) {
+                       value = cyapa_parse_structure_data(resp_data[9],
+                                       &resp_data[i], *data_size);
+                       *idac_min = min(value, *idac_min);
+                       *idac_max = max(value, *idac_max);
+
+                       if (idac_data_type == GEN5_RETRIEVE_MUTUAL_PWC_DATA &&
+                               tmp_count < tmp_max_elements &&
+                               read_global_idac) {
+                               tmp_min = min(value, tmp_min);
+                               tmp_max = max(value, tmp_max);
+                               tmp_sum += value;
+                               tmp_count++;
+                       }
+
+                       sum += value;
+                       count++;
+
+                       if (count >= max_element_cnt)
+                               goto out;
+               }
+       } while (true);
+
+out:
+       *idac_ave = count ? (sum / count) : 0;
+
+       if (read_global_idac &&
+               idac_data_type == GEN5_RETRIEVE_MUTUAL_PWC_DATA) {
+               if (tmp_count == 0)
+                       return 0;
+               /* algorithm to detect electrodes_rx value. */
+               tmp_ave = tmp_sum / tmp_count;
+               tmp_count = tmp_ave * 15 / 100;
+               if (abs(tmp_ave - *idac_ave) > tmp_count ||
+                       (abs(tmp_ave - *idac_min) > (tmp_count * 2) &&
+                               *idac_min < tmp_min) ||
+                       (abs(*idac_max - tmp_ave) > (tmp_count * 2) &&
+                               *idac_max > tmp_max)) {
+                       /* overcount the mutual global idac values. */
+                       cyapa->electrodes_rx = tmp_max_elements;
+                       *idac_min = tmp_min;
+                       *idac_max = tmp_max;
+                       *idac_ave = tmp_ave;
+               } else
+                       cyapa->electrodes_rx = electrodes_rx;
+       }
+
+       return 0;
+}
+
+static int cyapa_gen5_read_mutual_idac_data(struct cyapa *cyapa,
+       int *gidac_mutual_max, int *gidac_mutual_min, int *gidac_mutual_ave,
+       int *lidac_mutual_max, int *lidac_mutual_min, int *lidac_mutual_ave)
+{
+       int ret;
+       int data_size;
+
+       *gidac_mutual_max = *gidac_mutual_min = *gidac_mutual_ave = 0;
+       *lidac_mutual_max = *lidac_mutual_min = *lidac_mutual_ave = 0;
+
+       data_size = 0;
+       ret = cyapa_gen5_read_idac_data(cyapa,
+               GEN5_CMD_RETRIEVE_DATA_STRUCTURE,
+               GEN5_RETRIEVE_MUTUAL_PWC_DATA,
+               &data_size,
+               gidac_mutual_max, gidac_mutual_min, gidac_mutual_ave);
+       if (ret)
+               return ret;
+
+       ret = cyapa_gen5_read_idac_data(cyapa,
+               GEN5_CMD_RETRIEVE_DATA_STRUCTURE,
+               GEN5_RETRIEVE_MUTUAL_PWC_DATA,
+               &data_size,
+               lidac_mutual_max, lidac_mutual_min, lidac_mutual_ave);
+       return ret;
+}
+
+static int cyapa_gen5_read_self_idac_data(struct cyapa *cyapa,
+               int *gidac_self_rx, int *gidac_self_tx,
+               int *lidac_self_max, int *lidac_self_min, int *lidac_self_ave)
+{
+       int ret;
+       int data_size;
+
+       *gidac_self_rx = *gidac_self_tx = 0;
+       *lidac_self_max = *lidac_self_min = *lidac_self_ave = 0;
+
+       data_size = 0;
+       ret = cyapa_gen5_read_idac_data(cyapa,
+               GEN5_CMD_RETRIEVE_DATA_STRUCTURE,
+               GEN5_RETRIEVE_SELF_CAP_PWC_DATA,
+               &data_size,
+               lidac_self_max, lidac_self_min, lidac_self_ave);
+       if (ret)
+               return ret;
+       *gidac_self_rx = *lidac_self_max;
+       *gidac_self_tx = *lidac_self_min;
+
+       ret = cyapa_gen5_read_idac_data(cyapa,
+               GEN5_CMD_RETRIEVE_DATA_STRUCTURE,
+               GEN5_RETRIEVE_SELF_CAP_PWC_DATA,
+               &data_size,
+               lidac_self_max, lidac_self_min, lidac_self_ave);
+       return ret;
+}
+
+static ssize_t cyapa_gen5_execute_panel_scan(struct cyapa *cyapa)
+{
+       int ret;
+       u8 cmd[7];
+       u8 resp_data[6];
+       int resp_len;
+
+       cmd[0] = 0x04;
+       cmd[1] = 0x00;
+       cmd[2] = 0x05;
+       cmd[3] = 0x00;
+       cmd[4] = GEN5_APP_CMD_REPORT_ID;
+       cmd[5] = 0x00;
+       cmd[6] = GEN5_CMD_EXECUTE_PANEL_SCAN;  /* command code */
+       resp_len = 6;
+       ret = cyapa_i2c_pip_cmd_irq_sync(cyapa,
+                       cmd, 7,
+                       resp_data, &resp_len,
+                       500, cyapa_gen5_sort_tsg_pip_app_resp_data);
+       if (ret || resp_len != 6 ||
+                       resp_data[2] != GEN5_APP_RESP_REPORT_ID ||
+                       GET_GEN5_CMD_CODE(resp_data[4]) !=
+                               GEN5_CMD_EXECUTE_PANEL_SCAN ||
+                       !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5])) {
+               cyapa_gen5_resume_scanning(cyapa);
+               return (ret < 0) ? ret : -EAGAIN;
+       }
+
+       return 0;
+}
+
+static int cyapa_gen5_read_panel_scan_raw_data(struct cyapa *cyapa,
+               u8 cmd_code, u8 raw_data_type, int raw_data_max_num,
+               int *raw_data_max, int *raw_data_min, int *raw_data_ave,
+               u8 *buffer)
+{
+       int ret;
+       int i;
+       u8 cmd[12];
+       u8 resp_data[256];  /* max bytes can transfer one time. */
+       int resp_len;
+       int read_elements;
+       int read_len;
+       u16 offset;
+       s32 value;
+       int sum, count;
+       int data_size;
+       s32 *intp;
+
+       if (cmd_code != GEN5_CMD_RETRIEVE_PANEL_SCAN ||
+               (raw_data_type > GEN5_PANEL_SCAN_SELF_DIFFCOUNT) ||
+               !raw_data_max || !raw_data_min || !raw_data_ave)
+               return -EINVAL;
+
+       intp = (s32 *)buffer;
+       *raw_data_max = INT_MIN;
+       *raw_data_min = INT_MAX;
+       sum = count = 0;
+       offset = 0;
+       read_elements = (256 - 10) / 4;  /* currently, max element size is 4. */
+       read_len = read_elements * 4;
+       do {
+               cmd[0] = 0x04;
+               cmd[1] = 0x00;
+               cmd[2] = 0x0a;
+               cmd[3] = 0x00;
+               cmd[4] = GEN5_APP_CMD_REPORT_ID;
+               cmd[5] = 0x00;
+               cmd[6] = cmd_code;  /* command code */
+               put_unaligned_le16(offset, &cmd[7]);
+               put_unaligned_le16(read_elements, &cmd[9]);
+               cmd[11] = raw_data_type;
+               resp_len = 10 + read_len;
+
+               ret = cyapa_i2c_pip_cmd_irq_sync(cyapa,
+                       cmd, 12,
+                       resp_data, &resp_len,
+                       500, cyapa_gen5_sort_tsg_pip_app_resp_data);
+               if (ret || resp_len < 10 ||
+                               resp_data[2] != GEN5_APP_RESP_REPORT_ID ||
+                               (resp_data[4] & 0x7f) != cmd_code ||
+                               !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5]) ||
+                               resp_data[6] != raw_data_type)
+                       return (ret < 0) ? ret : -EAGAIN;
+
+               read_elements = get_unaligned_le16(&resp_data[7]);
+               if (read_elements == 0)
+                       break;
+
+               data_size = (resp_data[9] & GEN5_PWC_DATA_ELEMENT_SIZE_MASK);
+               offset += read_elements;
+               if (read_elements) {
+                       for (i = 10;
+                            i < (read_elements * data_size + 10);
+                            i += data_size) {
+                               value = cyapa_parse_structure_data(resp_data[9],
+                                               &resp_data[i], data_size);
+                               *raw_data_min = min(value, *raw_data_min);
+                               *raw_data_max = max(value, *raw_data_max);
+
+                               if (intp)
+                                       put_unaligned_le32(value, &intp[count]);
+
+                               sum += value;
+                               count++;
+
+                       }
+               }
+
+               if (count >= raw_data_max_num)
+                       break;
+
+               read_elements = (sizeof(resp_data) - 10) / data_size;
+               read_len = read_elements * data_size;
+       } while (true);
+
+       *raw_data_ave = count ? (sum / count) : 0;
+
+       return 0;
+}
+
+static ssize_t cyapa_gen5_show_baseline(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       struct cyapa *cyapa = dev_get_drvdata(dev);
+       int ret, err;
+       int gidac_mutual_max, gidac_mutual_min, gidac_mutual_ave;
+       int lidac_mutual_max, lidac_mutual_min, lidac_mutual_ave;
+       int gidac_self_rx, gidac_self_tx;
+       int lidac_self_max, lidac_self_min, lidac_self_ave;
+       int raw_cap_mutual_max, raw_cap_mutual_min, raw_cap_mutual_ave;
+       int raw_cap_self_max, raw_cap_self_min, raw_cap_self_ave;
+       int mutual_diffdata_max, mutual_diffdata_min, mutual_diffdata_ave;
+       int self_diffdata_max, self_diffdata_min, self_diffdata_ave;
+       int mutual_baseline_max, mutual_baseline_min, mutual_baseline_ave;
+       int self_baseline_max, self_baseline_min, self_baseline_ave;
+
+       if (cyapa->state != CYAPA_STATE_GEN5_APP)
+               return -EBUSY;
+
+       /* 1. suspend Scanning*/
+       ret = cyapa_gen5_suspend_scanning(cyapa);
+       if (ret)
+               return ret;
+
+       /* 2.  read global and local mutual IDAC data. */
+       gidac_self_rx = gidac_self_tx = 0;
+       err = cyapa_gen5_read_mutual_idac_data(cyapa,
+                               &gidac_mutual_max, &gidac_mutual_min,
+                               &gidac_mutual_ave, &lidac_mutual_max,
+                               &lidac_mutual_min, &lidac_mutual_ave);
+       if (err)
+               goto resume_scanning;
+
+       /* 3.  read global and local self IDAC data. */
+       err = cyapa_gen5_read_self_idac_data(cyapa,
+                               &gidac_self_rx, &gidac_self_tx,
+                               &lidac_self_max, &lidac_self_min,
+                               &lidac_self_ave);
+       if (err)
+               goto resume_scanning;
+
+       /* 4. execuate panel scan. It must be executed before read data. */
+       err = cyapa_gen5_execute_panel_scan(cyapa);
+       if (err)
+               goto resume_scanning;
+
+       /* 5. retrive panel scan, mutual cap raw data. */
+       err = cyapa_gen5_read_panel_scan_raw_data(cyapa,
+                               GEN5_CMD_RETRIEVE_PANEL_SCAN,
+                               GEN5_PANEL_SCAN_MUTUAL_RAW_DATA,
+                               cyapa->electrodes_x * cyapa->electrodes_y,
+                               &raw_cap_mutual_max, &raw_cap_mutual_min,
+                               &raw_cap_mutual_ave,
+                               NULL);
+       if (err)
+               goto resume_scanning;
+
+       /* 6. retrive panel scan, self cap raw data. */
+       err = cyapa_gen5_read_panel_scan_raw_data(cyapa,
+                               GEN5_CMD_RETRIEVE_PANEL_SCAN,
+                               GEN5_PANEL_SCAN_SELF_RAW_DATA,
+                               cyapa->electrodes_x + cyapa->electrodes_y,
+                               &raw_cap_self_max, &raw_cap_self_min,
+                               &raw_cap_self_ave,
+                               NULL);
+       if (err)
+               goto resume_scanning;
+
+       /* 7. retrive panel scan, mutual cap diffcount raw data. */
+       err = cyapa_gen5_read_panel_scan_raw_data(cyapa,
+                               GEN5_CMD_RETRIEVE_PANEL_SCAN,
+                               GEN5_PANEL_SCAN_MUTUAL_DIFFCOUNT,
+                               cyapa->electrodes_x * cyapa->electrodes_y,
+                               &mutual_diffdata_max, &mutual_diffdata_min,
+                               &mutual_diffdata_ave,
+                               NULL);
+       if (err)
+               goto resume_scanning;
+
+       /* 8. retrive panel scan, self cap diffcount raw data. */
+       err = cyapa_gen5_read_panel_scan_raw_data(cyapa,
+                               GEN5_CMD_RETRIEVE_PANEL_SCAN,
+                               GEN5_PANEL_SCAN_SELF_DIFFCOUNT,
+                               cyapa->electrodes_x + cyapa->electrodes_y,
+                               &self_diffdata_max, &self_diffdata_min,
+                               &self_diffdata_ave,
+                               NULL);
+       if (err)
+               goto resume_scanning;
+
+       /* 9. retrive panel scan, mutual cap baseline raw data. */
+       err = cyapa_gen5_read_panel_scan_raw_data(cyapa,
+                               GEN5_CMD_RETRIEVE_PANEL_SCAN,
+                               GEN5_PANEL_SCAN_MUTUAL_BASELINE,
+                               cyapa->electrodes_x * cyapa->electrodes_y,
+                               &mutual_baseline_max, &mutual_baseline_min,
+                               &mutual_baseline_ave,
+                               NULL);
+       if (err)
+               goto resume_scanning;
+
+       /* 10. retrive panel scan, self cap baseline raw data. */
+       err = cyapa_gen5_read_panel_scan_raw_data(cyapa,
+                               GEN5_CMD_RETRIEVE_PANEL_SCAN,
+                               GEN5_PANEL_SCAN_SELF_BASELINE,
+                               cyapa->electrodes_x + cyapa->electrodes_y,
+                               &self_baseline_max, &self_baseline_min,
+                               &self_baseline_ave,
+                               NULL);
+       if (err)
+               goto resume_scanning;
+
+resume_scanning:
+       /* 11. resume Scanning*/
+       ret = cyapa_gen5_resume_scanning(cyapa);
+       if (ret || err)
+               return ret ? ret : err;
+
+       /* 12. output data strings */
+       ret = scnprintf(buf, PAGE_SIZE, "%d %d %d %d %d %d %d %d %d %d %d ",
+               gidac_mutual_min, gidac_mutual_max, gidac_mutual_ave,
+               lidac_mutual_min, lidac_mutual_max, lidac_mutual_ave,
+               gidac_self_rx, gidac_self_tx,
+               lidac_self_min, lidac_self_max, lidac_self_ave);
+       err = scnprintf(buf + ret, PAGE_SIZE - ret,
+               "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
+               raw_cap_mutual_min, raw_cap_mutual_max, raw_cap_mutual_ave,
+               raw_cap_self_min, raw_cap_self_max, raw_cap_self_ave,
+               mutual_diffdata_min, mutual_diffdata_max, mutual_diffdata_ave,
+               self_diffdata_min, self_diffdata_max, self_diffdata_ave,
+               mutual_baseline_min, mutual_baseline_max, mutual_baseline_ave,
+               self_baseline_min, self_baseline_max, self_baseline_ave);
+       return ret + err;
+}
+
 static bool cyapa_gen5_sort_system_info_data(struct cyapa *cyapa,
                u8 *buf, int len)
 {
@@ -1867,8 +2540,8 @@ const struct cyapa_dev_ops cyapa_gen5_ops = {
        NULL,
        NULL,

-       NULL,
-       NULL,
+       cyapa_gen5_show_baseline,
+       cyapa_gen5_do_calibrate,

        NULL,
        NULL,
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.

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 12123 bytes --]

^ permalink raw reply related

* [PATCH v2 13/14] input: cyapa: add gen5 trackpad device read firmware image and raw data functions supported
From: Dudley Du @ 2014-06-06  7:29 UTC (permalink / raw)
  To: Dmitry Torokhov, Rafael J. Wysocki, Alan Stern
  Cc: Benson Leung, Lily Rui, Daniel Kurtz,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 12487 bytes --]

Add read firmware image function supported for gen5 trackpad device,
which its function is supplied through cyapa core read_fw interface.
Through this interface, upper layer application can read out, check
and backup the firmware image in trackpad device before updated
with new one when new firmware image may have problems.
Also add interfaces to report all sensor's raw data values to upper
layer, so it can help to find out the performance issue when users
reports problem, and also it's useful and required interface for
some customers that require sensors' raw data.
TEST=test on Chomebooks.

Signed-off-by: Du, Dudley <dudl@cypress.com>
---
diff --git a/drivers/input/mouse/cyapa_gen5.c b/drivers/input/mouse/cyapa_gen5.c
index 3da6a91..817842e 100644
--- a/drivers/input/mouse/cyapa_gen5.c
+++ b/drivers/input/mouse/cyapa_gen5.c
@@ -1159,6 +1159,158 @@ static int cyapa_gen5_write_fw_block(struct cyapa *cyapa,
        return 0;
 }

+static int cyapa_gen5_read_fw_bytes(struct cyapa *cyapa, u16 row_num, u8 *data)
+{
+       int ret;
+       u8 cmd[16];
+       size_t cmd_len;
+       u8 resp_data[CYAPA_TSG_FW_ROW_SIZE / 2 + GEN5_MIN_BL_RESP_LENGTH];
+       int resp_len;
+       u16 offset;
+       u16 cmd_crc;
+       struct cyapa_tsg_bin_image_data_record *fw_img_record;
+
+       fw_img_record = (struct cyapa_tsg_bin_image_data_record *)data;
+
+       cmd[0] = 0x04;  /* register address */
+       cmd[1] = 0x00;
+       cmd[2] = 0x0e;
+       cmd[3] = 0x00;
+       cmd[4] = 0x40;  /* report id 40h */
+       cmd[5] = 0x00;
+       cmd[6] = GEN5_SOP_KEY;
+       cmd[7] = 0x3d;  /* read application image command code */
+       cmd[8] = 0x03;
+       cmd[9] = 0x00;
+       offset = row_num * CYAPA_TSG_FW_ROW_SIZE -
+                       CYAPA_TSG_START_OF_APPLICATION;
+       put_unaligned_le16(offset, &cmd[10]);
+       cmd[12] = CYAPA_TSG_IMG_READ_SIZE;
+       cmd_crc = crc_itu_t(0xffff, &cmd[6], 7);
+       put_unaligned_le16(cmd_crc, &cmd[13]);  /* CRC[15:0] */
+       cmd[15] = GEN5_EOP_KEY;  /* EOP = 17h */
+       cmd_len = 16;
+
+       resp_len = CYAPA_TSG_IMG_READ_SIZE + GEN5_MIN_BL_RESP_LENGTH;
+       ret = cyapa_i2c_pip_cmd_irq_sync(cyapa,
+                       cmd, cmd_len,
+                       resp_data, &resp_len,
+                       50, cyapa_gen5_sort_tsg_pip_bl_resp_data);
+       if (resp_len != (CYAPA_TSG_IMG_READ_SIZE + GEN5_MIN_BL_RESP_LENGTH) ||
+                       ret || resp_data[2] != GEN5_BL_RESP_REPORT_ID ||
+                       !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5]))
+               return (ret < 0) ? ret : -EAGAIN;
+
+       /* copy first 64 bytes in the row. */
+       memcpy(&fw_img_record->record_data[0], &resp_data[8],
+                       CYAPA_TSG_IMG_READ_SIZE);
+
+       if (row_num == CYAPA_TSG_IMG_APP_INTEGRITY_ROW_NUM) {
+               /* last row's rest 64 bytes are bootloader metadata,
+                * it's not allowed to be read out, will respond with error. */
+               memset(&fw_img_record->record_data[CYAPA_TSG_IMG_READ_SIZE],
+                       0, CYAPA_TSG_IMG_READ_SIZE);
+               goto skip_last_row;
+       }
+
+       /* read next 64 bytes in the row. */
+       offset = offset + CYAPA_TSG_IMG_READ_SIZE;
+       put_unaligned_le16(offset, &cmd[10]);
+       cmd_crc = crc_itu_t(0xffff, &cmd[6], 7);
+       put_unaligned_le16(cmd_crc, &cmd[13]);  /* CRC[15:0] */
+       ret = cyapa_i2c_pip_cmd_irq_sync(cyapa,
+                       cmd, cmd_len,
+                       resp_data, &resp_len,
+                       500, cyapa_gen5_sort_tsg_pip_bl_resp_data);
+       if (resp_len != (CYAPA_TSG_IMG_READ_SIZE + GEN5_MIN_BL_RESP_LENGTH) ||
+                       ret || resp_data[2] != GEN5_BL_RESP_REPORT_ID ||
+                       !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5]))
+               return (ret < 0) ? ret : -EAGAIN;
+
+       /* copy last 64 bytes in the row. */
+       memcpy(&fw_img_record->record_data[CYAPA_TSG_IMG_READ_SIZE],
+               &resp_data[8], CYAPA_TSG_IMG_READ_SIZE);
+
+skip_last_row:
+       fw_img_record->flash_array_id = 0;
+       put_unaligned_be16(row_num, &fw_img_record->row_number);
+       put_unaligned_be16(CYAPA_TSG_FW_ROW_SIZE, &fw_img_record->record_len);
+
+       return 0;
+}
+
+static int cyapa_gen5_read_fw(struct cyapa *cyapa)
+{
+       int ret;
+       int fw_img_head_size;
+       int fw_img_record_size;
+       int row_index;
+       int array_index;
+       u32 img_start;
+       u16 img_len;
+       u16 img_start_row;
+       u16 img_end_row;
+       struct cyapa_tsg_bin_image_data_record app_integrity;
+       u8 *record_data;
+
+       ret = cyapa_gen5_bl_enter(cyapa);
+       if (ret)
+               goto err;
+
+       cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
+
+       fw_img_head_size = sizeof(struct cyapa_tsg_bin_image_head);
+       fw_img_record_size = sizeof(struct cyapa_tsg_bin_image_data_record);
+
+       /* Read app integrity block data. */
+       row_index = CYAPA_TSG_IMG_APP_INTEGRITY_ROW_NUM;
+       ret = cyapa_gen5_read_fw_bytes(cyapa, row_index, (u8 *)&app_integrity);
+       if (ret)
+               goto err;
+       img_start = get_unaligned_le32(&app_integrity.record_data[16]);
+       img_len = get_unaligned_le16(&app_integrity.record_data[20]);
+       if ((img_start + img_len) % CYAPA_TSG_FW_ROW_SIZE)
+               goto err;
+       img_start_row = img_start / CYAPA_TSG_FW_ROW_SIZE;
+       img_end_row = (img_start + img_len) / CYAPA_TSG_FW_ROW_SIZE - 1;
+
+       /* allocate memory for image. */
+       cyapa->read_fw_image_size = fw_img_head_size +
+               (img_end_row -  img_start_row + 2) * fw_img_record_size;
+       cyapa->read_fw_image = kmalloc(cyapa->read_fw_image_size, GFP_KERNEL);
+       if (!cyapa->read_fw_image) {
+               ret = -ENOMEM;
+               goto err;
+       }
+
+       /* set image head data. */
+       memcpy(cyapa->read_fw_image, &gen5_fw_img_head, fw_img_head_size);
+
+       /* read image blocks. */
+       for (row_index = img_start_row, array_index = 0;
+                       row_index <= img_end_row;
+                       row_index++, array_index++) {
+               record_data = &cyapa->read_fw_image[fw_img_head_size +
+                               array_index * fw_img_record_size];
+               ret = cyapa_gen5_read_fw_bytes(cyapa, row_index, record_data);
+               if (ret)
+                       goto err;
+       }
+
+       /* append last app integrity block data. */
+       record_data = &cyapa->read_fw_image[fw_img_head_size +
+                               array_index * fw_img_record_size];
+       memcpy(record_data, &app_integrity, fw_img_record_size);
+
+err:
+       if (ret) {
+               kfree(cyapa->read_fw_image);
+               cyapa->read_fw_image = NULL;
+               cyapa->read_fw_image_size = 0;
+       }
+       return ret;
+}
+
 static int cyapa_gen5_do_fw_update(struct cyapa *cyapa,
                const struct firmware *fw)
 {
@@ -2152,6 +2304,109 @@ resume_scanning:
        return ret + err;
 }

+static int cyapa_gen5_read_raw_data(struct cyapa *cyapa)
+{
+       int ret, err;
+       int raw_cap_mutual_max, raw_cap_mutual_min, raw_cap_mutual_ave;
+       int raw_cap_self_max, raw_cap_self_min, raw_cap_self_ave;
+       int offset;
+       int data_size, max, min, ave;
+       ktime_t time_mono;
+
+       offset = 0;
+       if (!cyapa->tp_raw_data) {
+               if (cyapa->state != CYAPA_STATE_GEN5_APP ||
+                       !cyapa->electrodes_x || !cyapa->electrodes_y)
+                       return  -EINVAL;
+
+               cyapa->tp_raw_data_size = sizeof(s32) * (cyapa->electrodes_x *
+                       cyapa->electrodes_y + cyapa->electrodes_x +
+                       cyapa->electrodes_y) + GEN5_RAW_DATA_HEAD_SIZE;
+               /* This buffer will be hold after used until the driver is
+                * unloaded, the purpose of it is to improve the performace
+                * to avoid frequently allocate and release the buffer. */
+               cyapa->tp_raw_data =
+                       kmalloc(cyapa->tp_raw_data_size, GFP_KERNEL);
+               if (!cyapa->tp_raw_data)
+                       return -ENOMEM;
+               memset(cyapa->tp_raw_data, 0, cyapa->tp_raw_data_size);
+       }
+
+
+       /* 1. suspend Scanning.
+        * After suspend scanning, the raw data will not be updated,
+        * so the time of the raw data is before scanning suspended. */
+       time_mono = ktime_get();
+       ret = cyapa_gen5_suspend_scanning(cyapa);
+       if (ret)
+               return ret;
+
+       /* 2. get the correct electrodes_rx number. */
+       if (cyapa->electrodes_rx == 0) {
+               /* Through the read global idac interface to get the Rx number.
+                * this value is useful to the raw data map.*/
+               data_size = 0;
+               err = cyapa_gen5_read_idac_data(cyapa,
+                               GEN5_CMD_RETRIEVE_DATA_STRUCTURE,
+                               GEN5_RETRIEVE_MUTUAL_PWC_DATA,
+                               &data_size, &max, &min, &ave);
+               if (err || cyapa->electrodes_rx == 0)
+                       goto resume_scanning;
+       }
+
+       /* 3. execuate panel scan. It must be executed before read data. */
+       err = cyapa_gen5_execute_panel_scan(cyapa);
+       if (err)
+               goto resume_scanning;
+
+       /* 4. retrive panel scan, mutual cap raw data. */
+       offset = GEN5_RAW_DATA_HEAD_SIZE;
+       err = cyapa_gen5_read_panel_scan_raw_data(cyapa,
+                               GEN5_CMD_RETRIEVE_PANEL_SCAN,
+                               GEN5_PANEL_SCAN_MUTUAL_DIFFCOUNT,
+                               cyapa->electrodes_x * cyapa->electrodes_y,
+                               &raw_cap_mutual_max, &raw_cap_mutual_min,
+                               &raw_cap_mutual_ave,
+                               cyapa->tp_raw_data + offset);
+       if (err)
+               goto resume_scanning;
+
+       offset += sizeof(s32) * cyapa->electrodes_x * cyapa->electrodes_y;
+
+       /* 5. retrive panel scan, self cap raw data. */
+       err = cyapa_gen5_read_panel_scan_raw_data(cyapa,
+                               GEN5_CMD_RETRIEVE_PANEL_SCAN,
+                               GEN5_PANEL_SCAN_SELF_DIFFCOUNT,
+                               cyapa->electrodes_x + cyapa->electrodes_y,
+                               &raw_cap_self_max, &raw_cap_self_min,
+                               &raw_cap_self_ave,
+                               cyapa->tp_raw_data + offset);
+       if (err)
+               goto resume_scanning;
+
+       offset += sizeof(s32) * (cyapa->electrodes_x + cyapa->electrodes_y);
+
+resume_scanning:
+       /* 6. resume Scanning*/
+       ret = cyapa_gen5_resume_scanning(cyapa);
+       if (ret || err)
+               return ret ? ret : err;
+
+       *((struct timeval *)&cyapa->tp_raw_data[0]) =
+                                               ktime_to_timeval(time_mono);
+       cyapa->tp_raw_data[16] = (u8)cyapa->electrodes_x;
+       cyapa->tp_raw_data[17] = (u8)cyapa->electrodes_y;
+       cyapa->tp_raw_data[18] = (u8)cyapa->x_origin;
+       cyapa->tp_raw_data[19] = (u8)cyapa->y_origin;
+       cyapa->tp_raw_data[20] = (u8)sizeof(s32);
+       cyapa->tp_raw_data[21] = (u8)sizeof(s32);
+       cyapa->tp_raw_data[22] = (u8)cyapa->electrodes_rx;
+       cyapa->tp_raw_data[23] = 0;  /* reserved. */
+
+       cyapa->tp_raw_data_size = offset;
+       return 0;
+}
+
 static bool cyapa_gen5_sort_system_info_data(struct cyapa *cyapa,
                u8 *buf, int len)
 {
@@ -2543,8 +2798,8 @@ const struct cyapa_dev_ops cyapa_gen5_ops = {
        cyapa_gen5_show_baseline,
        cyapa_gen5_do_calibrate,

-       NULL,
-       NULL,
+       cyapa_gen5_read_fw,
+       cyapa_gen5_read_raw_data,

        cyapa_gen5_get_private_size,
        cyapa_gen5_private_init,
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.

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 8249 bytes --]

^ permalink raw reply related

* [PATCH v2 3/14] input: cyapa: add cyapa driver runtime power management interfaces supported
From: Dudley Du @ 2014-06-06  7:29 UTC (permalink / raw)
  To: Dmitry Torokhov, Rafael J. Wysocki, Alan Stern
  Cc: Benson Leung, Lily Rui, Daniel Kurtz,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 7803 bytes --]

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 Chomebooks.

Signed-off-by: Du, Dudley <dudl@cypress.com>
---
diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index 1dfc16d..c2b67d3 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -346,9 +346,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->cyapa_irq_cmd_handler)
@@ -373,6 +380,8 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)

                cyapa_state_sync_exit(cyapa);
        }
+
+       pm_runtime_put_sync_autosuspend(dev);
 out:
        return IRQ_HANDLED;
 }
@@ -574,6 +583,79 @@ 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 = cyapa->runtime_suspend_power_mode;
+
+       if (cyapa->gen == CYAPA_GEN3)
+               return scnprintf(buf, PAGE_SIZE, "%u\n",
+                       cyapa_pwr_cmd_to_sleep_time(pwr_cmd));
+       else
+               return scnprintf(buf, PAGE_SIZE, "%u\n",
+                       cyapa->runtime_suspend_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);
+       cyapa->runtime_suspend_sleep_time = cyapa_sleep_time_check(time);
+       cyapa->runtime_suspend_power_mode =
+               cyapa_sleep_time_to_pwr_cmd(cyapa->runtime_suspend_sleep_time);
+       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;
@@ -589,7 +671,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_probe(struct i2c_client *client,
@@ -675,9 +761,15 @@ static int cyapa_remove(struct i2c_client *client)
 {
        struct cyapa *cyapa = i2c_get_clientdata(client);

+       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);
@@ -735,12 +827,54 @@ static int cyapa_resume(struct device *dev)

        async_schedule(cyapa_detect_async, cyapa);

+       /* runtime set active 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->cyapa_set_power_mode) {
+               /* set trackpad device to idle mode */
+               ret = cyapa->ops->cyapa_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->cyapa_set_power_mode) {
+               /* resume to full active mode */
+               ret = cyapa->ops->cyapa_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[] = {
diff --git a/drivers/input/mouse/cyapa.h b/drivers/input/mouse/cyapa.h
index 1780d82..91fb84a 100644
--- a/drivers/input/mouse/cyapa.h
+++ b/drivers/input/mouse/cyapa.h
@@ -199,6 +199,10 @@ struct cyapa {
        /* 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 */

        /* read from query data region. */
        char product_id[16];
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.

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 6749 bytes --]

^ permalink raw reply related

* [PATCH v2 14/14] input: cyapa: add function to monitor LID close event to off trackpad device
From: Dudley Du @ 2014-06-06  7:29 UTC (permalink / raw)
  To: Dmitry Torokhov, Rafael J. Wysocki, Alan Stern
  Cc: Benson Leung, Lily Rui, Daniel Kurtz,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 8201 bytes --]

Add the function to monitor lid close event to suspend and resume
trackpad device.
Because system suspend takes some time to trigger from user space,
and in that time, the lid panel of the laptop may couple with the
active trackpad. This may generate stray input events, which may
in turn cancel the suspend if the drivers use pm_wakup_event(), and
those input events may trigger something unwanted in the UI.
So this patch adds the function to do off the trackpad device quickly.
When the lid is closed, as soon as possible, the trakcpad device must
be off. And furthermore, the policy on lid close is not always to
enter suspend (lid closed with external display), and at this time,
the trackpad device must be disabled as well as again to avoid the
risk of generating stray events.
TEST=test on Chomebooks.

Signed-off-by: Du, Dudley <dudl@cypress.com>
---
diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index 8d37032..760a43b 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -1166,6 +1166,140 @@ static const struct attribute_group cyapa_sysfs_group = {
        .attrs = cyapa_sysfs_entries,
 };

+
+/*
+ * We rely on EV_SW and SW_LID bits to identify a LID device, and hook
+ * up our filter to listen for SW_LID events to enable/disable touchpad when
+ * LID is open/closed.
+ */
+static const struct input_device_id lid_device_ids[] = {
+       {
+               .flags = INPUT_DEVICE_ID_MATCH_EVBIT |
+                        INPUT_DEVICE_ID_MATCH_SWBIT,
+               .evbit = { BIT_MASK(EV_SW) },
+               .swbit = { BIT_MASK(SW_LID) },
+       },
+       { },
+};
+
+static int lid_device_connect(struct input_handler *handler,
+                             struct input_dev *dev,
+                             const struct input_device_id *id)
+{
+       struct input_handle *lid_handle;
+       int error;
+
+       pr_info("cyapa: LID device: '%s' connected\n", dev->name);
+       lid_handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
+       if (!lid_handle)
+               return -ENOMEM;
+
+       lid_handle->dev = dev;
+       lid_handle->handler = handler;
+       lid_handle->name = "lid_event_handler";
+       lid_handle->private = handler->private;
+
+       error = input_register_handle(lid_handle);
+       if (error) {
+               pr_err("Failed to register lid_event_handler, error %d\n",
+                      error);
+               goto err_free;
+       }
+
+       error = input_open_device(lid_handle);
+       if (error) {
+               pr_err("Failed to open input device, error %d\n", error);
+               goto err_unregister;
+       }
+
+       return 0;
+err_unregister:
+       input_unregister_handle(lid_handle);
+err_free:
+       kfree(lid_handle);
+       return error;
+}
+
+static void lid_device_disconnect(struct input_handle *handle)
+{
+       input_close_device(handle);
+       input_unregister_handle(handle);
+       kfree(handle);
+}
+
+static bool lid_event_filter(struct input_handle *handle,
+                            unsigned int type, unsigned int code, int value)
+{
+       struct cyapa *cyapa = handle->private;
+       struct device *dev = &cyapa->client->dev;
+
+       if (type == EV_SW && code == SW_LID) {
+               pr_info("cyapa %s: %s touch device\n",
+                       dev_name(&cyapa->client->dev),
+                       (value ? "disable" : "enable"));
+               if (cyapa->suspended) {
+                       /*
+                        * If the lid event filter is called while suspended,
+                        * there is no guarantee that the underlying i2cs are
+                        * resumed at this point, so it is not safe to issue
+                        * the command to change power modes.
+                        * Instead, rely on cyapa_resume to set us back to
+                        * PWR_MODE_FULL_ACTIVE.
+                        */
+                       pr_info("cyapa %s: skipping lid pm change in suspend\n",
+                               dev_name(&cyapa->client->dev));
+                       return false;
+               }
+               if (value == 0) {
+                       if (cyapa->ops->cyapa_set_power_mode)
+                               cyapa->ops->cyapa_set_power_mode(cyapa,
+                                               PWR_MODE_FULL_ACTIVE, 0);
+                       pm_runtime_set_active(dev);
+                       pm_runtime_enable(dev);
+               } else {
+                       pm_runtime_disable(dev);
+                       if (cyapa->ops->cyapa_set_power_mode)
+                               cyapa->ops->cyapa_set_power_mode(cyapa,
+                                               PWR_MODE_OFF, 0);
+               }
+       }
+
+       return false;
+}
+
+static void lid_event_register_handler(struct cyapa *cyapa)
+{
+       int error;
+       struct input_handler *lid_handler = &cyapa->lid_handler;
+
+       if (cyapa->lid_handler_registered) {
+               pr_err("lid handler is registered already\n");
+               return;
+       }
+
+       lid_handler->filter     = lid_event_filter;
+       lid_handler->connect    = lid_device_connect;
+       lid_handler->disconnect = lid_device_disconnect;
+       lid_handler->name       = "cyapa_lid_event_handler";
+       lid_handler->id_table   = lid_device_ids;
+       lid_handler->private    = cyapa;
+
+       error = input_register_handler(lid_handler);
+       if (error) {
+               pr_err("Failed to register lid handler(%d)\n", error);
+               return;
+       }
+       cyapa->lid_handler_registered = true;
+}
+
+static void lid_event_unregister_handler(struct cyapa *cyapa)
+{
+       if (cyapa->lid_handler_registered) {
+               input_unregister_handler(&cyapa->lid_handler);
+               cyapa->lid_handler_registered = false;
+       }
+}
+
 void cyapa_detect_async(void *data, async_cookie_t cookie)
 {
        struct cyapa *cyapa = (struct cyapa *)data;
@@ -1186,6 +1320,7 @@ static void cyapa_detect_and_start(void *data, async_cookie_t cookie)
        cyapa_detect_async(data, cookie);

        cyapa_start_runtime(cyapa);
+       lid_event_register_handler(cyapa);
 }

 static int cyapa_probe(struct i2c_client *client,
@@ -1324,6 +1459,7 @@ static int cyapa_remove(struct i2c_client *client)
        mutex_destroy(&cyapa->debugfs_mutex);

        input_unregister_device(cyapa->input);
+       lid_event_unregister_handler(cyapa);
        if (cyapa->ops->cyapa_set_power_mode)
                cyapa->ops->cyapa_set_power_mode(cyapa, PWR_MODE_OFF, 0);
        i2c_set_clientdata(client, NULL);
@@ -1340,6 +1476,7 @@ static int cyapa_suspend(struct device *dev)
        struct cyapa *cyapa = dev_get_drvdata(dev);

        cyapa_disable_irq(cyapa);
+       cyapa->suspended = true;

        /*
         * Set trackpad device to idle mode if wakeup is allowed,
@@ -1382,6 +1519,7 @@ static int cyapa_resume(struct device *dev)
        pm_runtime_disable(dev);
        pm_runtime_set_active(dev);
        pm_runtime_enable(dev);
+       cyapa->suspended = false;
        return 0;
 }
 #endif /* CONFIG_PM_SLEEP */
diff --git a/drivers/input/mouse/cyapa.h b/drivers/input/mouse/cyapa.h
index 7f8c3d4..616db23 100644
--- a/drivers/input/mouse/cyapa.h
+++ b/drivers/input/mouse/cyapa.h
@@ -219,6 +219,7 @@ struct cyapa {
        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];
@@ -259,6 +260,9 @@ struct cyapa {
        size_t tp_raw_data_size;

        const struct cyapa_dev_ops *ops;
+
+       bool lid_handler_registered;
+       struct input_handler lid_handler;
 };


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.

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 7054 bytes --]

^ permalink raw reply related

* Re: [PATCH v2] leds: USB: Add support for MSI GT683R led panels
From: Johan Hovold @ 2014-06-06  9:47 UTC (permalink / raw)
  To: Janne Kanniainen
  Cc: cooloney, rpurdie, linux-kernel, linux-leds, linux-usb,
	Jiri Kosina, linux-input, Johan Hovold
In-Reply-To: <1402003746-6354-1-git-send-email-janne.kanniainen@gmail.com>

[ +CC: Jiri, linux-input, linux-usb (again) ]

First of all, please reply to the original thread and make sure to not
drop people or lists from CC.

On Fri, Jun 06, 2014 at 12:29:06AM +0300, Janne Kanniainen wrote:
> This driver adds support for USB controlled led panels that exist in
> MSI GT683R laptop.

I had a change to look at bit closer at this today and it turns out this
is a HID device and as such is already claimed by the HID driver.

There was a quirk added for this particular VID/PID by commit
620ae90ed8ca ("HID: usbhid: quirk for MSI GX680R led panel") in order to
avoid a 10s delay at boot due to missing report descriptors:

	https://bugzilla.redhat.com/show_bug.cgi?id=907221
	http://www.spinics.net/lists/linux-usb/msg54756.html

Since this is a HID device (and the control requests you're doing are
Set_Report requests) you should probably implement this as a specific
HID driver if there's no generic support you can use directly.

I've added Jiri Kosina (and linux-input) who knows a lot more about the
HID layer and how this is supposed to be implemented as CC.

> Changes in v2:
> 	- sorted headers to alphabetic order
> 	- using devm_kzalloc
> 	- using BIT(n)
> 	- using usb_control_msg instead of usb_submit_urb
> 	- removing unneeded code

There are still some issues in the code below, but I'll only point out
the more problematic ones for now.

> Signed-off-by: Janne Kanniainen <janne.kanniainen@gmail.com>
> ---
>  drivers/leds/Kconfig       |   6 ++
>  drivers/leds/Makefile      |   1 +
>  drivers/leds/leds-gt683r.c | 158 +++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 165 insertions(+)
>  create mode 100644 drivers/leds/leds-gt683r.c
> 
> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> index 6de9dfb..2cffa0c 100644
> --- a/drivers/leds/Kconfig
> +++ b/drivers/leds/Kconfig
> @@ -487,6 +487,12 @@ config LEDS_BLINKM
>  	  This option enables support for the BlinkM RGB LED connected
>  	  through I2C. Say Y to enable support for the BlinkM LED.
>  
> +config LEDS_GT683R
> +       tristate "LED support for the MSI GT683R"
> +       depends on LEDS_CLASS && USB
> +       help
> +         This option enables support for the MSI GT683R LEDS
> +
>  comment "LED Triggers"
>  source "drivers/leds/trigger/Kconfig"
>  
> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> index 3cd76db..af5fb4e 100644
> --- a/drivers/leds/Makefile
> +++ b/drivers/leds/Makefile
> @@ -54,6 +54,7 @@ obj-$(CONFIG_LEDS_ASIC3)		+= leds-asic3.o
>  obj-$(CONFIG_LEDS_MAX8997)		+= leds-max8997.o
>  obj-$(CONFIG_LEDS_LM355x)		+= leds-lm355x.o
>  obj-$(CONFIG_LEDS_BLINKM)		+= leds-blinkm.o
> +obj-$(CONFIG_LEDS_GT683R)		+= leds-gt683r.o
>  
>  # LED SPI Drivers
>  obj-$(CONFIG_LEDS_DAC124S085)		+= leds-dac124s085.o
> diff --git a/drivers/leds/leds-gt683r.c b/drivers/leds/leds-gt683r.c
> new file mode 100644
> index 0000000..5a204ea
> --- /dev/null
> +++ b/drivers/leds/leds-gt683r.c
> @@ -0,0 +1,158 @@
> +/*
> + * MSI GT683R led driver
> + *
> + * Copyright (c) 2014 Janne Kanniainen <janne.kanniainen@gmail.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/leds.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/usb.h>
> +
> +#define USB_DEVICE_ID_MSI_GT683R_LED_PANEL	0xff00
> +#define USB_VENDOR_ID_MSI			0x1770
> +
> +#define GT683R_LED_BACK				BIT(0)
> +#define GT683R_LED_SIDE				BIT(1)
> +#define GT683R_LED_FRONT			BIT(2)
> +#define GT683R_LED_ALL (GT683R_LED_BACK | GT683R_LED_SIDE | GT683R_LED_FRONT)
> +
> +#define GT683R_LED_OFF				0
> +#define GT683R_LED_AUDIO			2
> +#define GT683R_LED_BREATHING			3
> +#define GT683R_LED_NORMAL			5
> +
> +struct gt683r_led {
> +	struct usb_device *usb_dev;
> +	struct usb_endpoint_descriptor *ep;
> +	struct led_classdev led_dev;
> +	struct mutex lock;
> +	struct work_struct work;
> +	enum led_brightness brightness;
> +};
> +
> +static const struct usb_device_id gt683r_led_id[] = {
> +	{ USB_DEVICE(USB_VENDOR_ID_MSI, USB_DEVICE_ID_MSI_GT683R_LED_PANEL) },
> +	{ }
> +};
> +
> +static const u64 gt683r_led_select_leds = 0x300201ULL;
> +static const u64 gt683r_led_select_type = 0x100200201ULL;

No, you'd still want to use byte arrays for this in order to handle
endianess (if you are to keep these at all).

For arrays you can use the ARRAY_SIZE() macro if that was the reason for
this change. I should have mentioned that when I pointed out that you
cannot use strlen().

Where did you get these (HID report) values from by the way?

> +
> +static void gt683r_brightness_set(struct led_classdev *led_cdev,
> +				  enum led_brightness brightness)
> +{
> +	struct gt683r_led *led =
> +			container_of(led_cdev, struct gt683r_led, led_dev);
> +
> +	mutex_lock(&led->lock);

You cannot grab a mutex here since this function can be called from
interrupt context (if I remember correctly). Either way, you shouldn't
be holding the lock until the work task has finished...

> +
> +	led->brightness = brightness;
> +
> +	schedule_work(&led->work);
> +}
> +
> +static int gt683r_led_snd_msg(struct gt683r_led *led, u64 msg)
> +{
> +	int result = usb_control_msg(led->usb_dev,
> +				usb_sndctrlpipe(led->usb_dev,
> +						led->ep->bEndpointAddress),

No need to store the endpoint in the led struct as the address of
endpoint 0 is 0.

> +				0x09, 0x22, 0x0301, 0x0000,
> +				&msg, sizeof(u64), USB_CTRL_SET_TIMEOUT);

You cannot use a stack allocated buffer (msg) for the data transfer as
some platforms can't do DMA from the stack.

> +	if (result)
> +		dev_err(&led->usb_dev->dev,
> +			"Failed to send control message: %i\n", result);
> +
> +	return result;
> +}
> +
> +static void gt683r_led_set(struct gt683r_led *led, char type)
> +{
> +	gt683r_led_snd_msg(led, gt683r_led_select_leds |
> +			(GT683R_LED_ALL << 24));
> +	gt683r_led_snd_msg(led, gt683r_led_select_type |
> +			(type << 24));
> +}
> +
> +static void gt683r_led_work(struct work_struct *work)
> +{
> +	struct gt683r_led *led =
> +			container_of(work, struct gt683r_led, work);
> +
> +	if (led->brightness)
> +		gt683r_led_set(led, GT683R_LED_NORMAL);
> +	else
> +		gt683r_led_set(led, GT683R_LED_OFF);
> +
> +	mutex_unlock(&led->lock);
> +}
> +
> +static struct led_classdev gt683r_led_dev = {
> +	.name = "gt683r-led",
> +	.brightness_set = gt683r_brightness_set,
> +	.max_brightness = 1,
> +	.flags = LED_CORE_SUSPENDRESUME,
> +};
> +
> +static int gt683r_led_probe(struct usb_interface *intf,
> +			    const struct usb_device_id *id)
> +{
> +	int ret = 0;
> +	struct gt683r_led *led =
> +		devm_kzalloc(&intf->dev, sizeof(struct gt683r_led), GFP_KERNEL);

Again, please split definition and allocation.

> +	if (!led)
> +		return -ENOMEM;
> +
> +	led->usb_dev = interface_to_usbdev(intf);
> +	usb_set_intfdata(intf, led);
> +
> +	led->ep = &led->usb_dev->ep0.desc;
> +	if (!usb_endpoint_xfer_control(led->ep) ||
> +		usb_endpoint_maxp(led->ep) != sizeof(u64))
> +		return -EINVAL;

EP0 is a control endpoint, and you probably don't need the
max-packet-size test either.

> +
> +	led->led_dev = gt683r_led_dev;
> +	ret = led_classdev_register(&led->usb_dev->dev, &led->led_dev);
> +	if (ret) {
> +		dev_err(&led->usb_dev->dev, "Could not register led_classdev\n");
> +		return ret;
> +	}
> +
> +	mutex_init(&led->lock);
> +	INIT_WORK(&led->work, gt683r_led_work);
> +
> +	return 0;
> +}
> +
> +static void gt683r_led_disconnect(struct usb_interface *intf)
> +{
> +	struct gt683r_led *led = usb_get_intfdata(intf);
> +
> +	led_classdev_unregister(&led->led_dev);
> +	cancel_work_sync(&led->work);
> +}
> +
> +static struct usb_driver gt683r_led_driver = {
> +	.probe = gt683r_led_probe,
> +	.disconnect = gt683r_led_disconnect,
> +	.name = "GT683R Led Driver",
> +	.id_table = gt683r_led_id,
> +};
> +
> +module_usb_driver(gt683r_led_driver);
> +
> +MODULE_AUTHOR("Janne Kanniainen");
> +MODULE_DESCRIPTION("MSI GT683R led driver");
> +MODULE_LICENSE("GPL");

Johan

^ permalink raw reply

* [PATCH] elantech: Deal with clickpads reporting right button events
From: Hans de Goede @ 2014-06-06 14:08 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Elder Marco, linux-input, stable, Hans de Goede

At least the Dell Vostro 5470 elantech *clickpad* reports right button
clicks when clicked in the right bottom area:

https://bugzilla.redhat.com/show_bug.cgi?id=1103528

This is different from how (elantech) clickpads normally operate,
normally no matter where the user clicks on the pad the pad always reports
a left button event, since there is only 1 hardware button beneath the path.

It looks like Dell has put 2 buttons under the pad, one under each bottom
corner, causing this.

Since this however still clearly is a real clickpad hardware-wise, we still
want to report it as such to userspace, so that things like finger movement
in the bottom area can be properly ignored as it should be on clickpads.

So deal with this weirdness by simply mapping a right click to a left click
on elantech clickpads. As an added advantage this is something which we can
simply do on all elantech clickpads, so no need to add special quirks for
this weird model.

Reported-and-tested-by: Elder Marco <eldermarco@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/input/mouse/elantech.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index 4d79821..846926d 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -473,8 +473,15 @@ static void elantech_report_absolute_v3(struct psmouse *psmouse,
 	input_report_key(dev, BTN_TOOL_FINGER, fingers == 1);
 	input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2);
 	input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3);
-	input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
-	input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
+
+	/* For clickpads map both buttons to BTN_LEFT */
+	if (etd->fw_version & 0x001000) {
+		input_report_key(dev, BTN_LEFT, packet[0] & 0x03);
+	} else {
+		input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
+		input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
+	}
+
 	input_report_abs(dev, ABS_PRESSURE, pres);
 	input_report_abs(dev, ABS_TOOL_WIDTH, width);
 
@@ -484,10 +491,17 @@ static void elantech_report_absolute_v3(struct psmouse *psmouse,
 static void elantech_input_sync_v4(struct psmouse *psmouse)
 {
 	struct input_dev *dev = psmouse->dev;
+	struct elantech_data *etd = psmouse->private;
 	unsigned char *packet = psmouse->packet;
 
-	input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
-	input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
+	/* For clickpads map both buttons to BTN_LEFT */
+	if (etd->fw_version & 0x001000) {
+		input_report_key(dev, BTN_LEFT, packet[0] & 0x03);
+	} else {
+		input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
+		input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
+	}
+
 	input_mt_report_pointer_emulation(dev, true);
 	input_sync(dev);
 }
-- 
2.0.0

^ permalink raw reply related

* [PATCH] Support for new version of USB tablet KYE-i608x (ID 0458:501A)
From: Sebastien Alaiwan @ 2014-06-07  7:59 UTC (permalink / raw)
  To: linux-input

Here's a patch to make the hid-kye kernel module recognize a new
graphic tablet (which is a new version of the KYE i608x).

Technical stuff below:

Mine's branded as a "Genius MousePen i608x".
lsusb returns this:
Bus 005 Device 002: ID 0458:501a KYE Systems Corp. (Mouse Systems)

It seems to share the same magic HID feature report than the other
tablets of this vendor.
(not sending it results in the tablet not sending pen pressure information).

I get the tablet to send absolute information about the pen and the mouse ;
the generated events look correct, and it integrates well with xorg evdev
(except for the mouse for which a dedicated xorg driver may be needed).


-----------------------------------------------

Signed-off-by: Sebastien Alaiwan <sebastien.alaiwan@gmail.com>
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index da52279..df5534d 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1775,6 +1775,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_I405X) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 34bb220..447cd8c 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -514,6 +514,7 @@
 #define USB_DEVICE_ID_KYE_GPEN_560	0x5003
 #define USB_DEVICE_ID_KYE_EASYPEN_I405X	0x5010
 #define USB_DEVICE_ID_KYE_MOUSEPEN_I608X	0x5011
+#define USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2	0x501A
 #define USB_DEVICE_ID_KYE_EASYPEN_M610X	0x5013
 
 #define USB_VENDOR_ID_LABTEC		0x1020
diff --git a/drivers/hid/hid-kye.c b/drivers/hid/hid-kye.c
index e776963..7f4757f 100644
--- a/drivers/hid/hid-kye.c
+++ b/drivers/hid/hid-kye.c
@@ -186,6 +186,105 @@ static __u8 mousepen_i608x_rdesc_fixed[] = {
 	0xC0              /*  End Collection                  */
 };
 
+/* Original MousePen i608X report descriptor size */
+#define MOUSEPEN_I608X_2_RDESC_ORIG_SIZE	482
+
+/* Fixed MousePen i608X report descriptor */
+static __u8 mousepen_i608x_2_rdesc_fixed[] = {
+	0x06, 0x00, 0xFF, /*  Usage Page (FF00h),             */
+	0x09, 0x01,       /*  Usage (01h),                    */
+	0xA1, 0x01,       /*  Collection (Application),       */
+	0x85, 0x05,       /*    Report ID (5),                */
+	0x09, 0x01,       /*    Usage (01h),                  */
+	0x15, 0x80,       /*    Logical Minimum (-128),       */
+	0x25, 0x7F,       /*    Logical Maximum (127),        */
+	0x75, 0x08,       /*    Report Size (8),              */
+	0x95, 0x07,       /*    Report Count (7),             */
+	0xB1, 0x02,       /*    Feature (Variable),           */
+	0xC0,             /*  End Collection,                 */
+	0x05, 0x0D,       /*  Usage Page (Digitizer),         */
+	0x09, 0x02,       /*  Usage (Pen),                    */
+	0xA1, 0x01,       /*  Collection (Application),       */
+	0x85, 0x10,       /*    Report ID (16),               */
+	0x09, 0x20,       /*    Usage (Stylus),               */
+	0xA0,             /*    Collection (Physical),        */
+	0x14,             /*      Logical Minimum (0),        */
+	0x25, 0x01,       /*      Logical Maximum (1),        */
+	0x75, 0x01,       /*      Report Size (1),            */
+	0x09, 0x42,       /*      Usage (Tip Switch),         */
+	0x09, 0x44,       /*      Usage (Barrel Switch),      */
+	0x09, 0x46,       /*      Usage (Tablet Pick),        */
+	0x95, 0x03,       /*      Report Count (3),           */
+	0x81, 0x02,       /*      Input (Variable),           */
+	0x95, 0x04,       /*      Report Count (4),           */
+	0x81, 0x03,       /*      Input (Constant, Variable), */
+	0x09, 0x32,       /*      Usage (In Range),           */
+	0x95, 0x01,       /*      Report Count (1),           */
+	0x81, 0x02,       /*      Input (Variable),           */
+	0x75, 0x10,       /*      Report Size (16),           */
+	0x95, 0x01,       /*      Report Count (1),           */
+	0xA4,             /*      Push,                       */
+	0x05, 0x01,       /*      Usage Page (Desktop),       */
+	0x55, 0xFD,       /*      Unit Exponent (-3),         */
+	0x65, 0x13,       /*      Unit (Inch),                */
+	0x34,             /*      Physical Minimum (0),       */
+	0x09, 0x30,       /*      Usage (X),                  */
+	0x46, 0x40, 0x1F, /*      Physical Maximum (8000),    */
+	0x26, 0x00, 0xA0, /*      Logical Maximum (40960),    */
+	0x81, 0x02,       /*      Input (Variable),           */
+	0x09, 0x31,       /*      Usage (Y),                  */
+	0x46, 0x70, 0x17, /*      Physical Maximum (6000),    */
+	0x26, 0x00, 0x78, /*      Logical Maximum (30720),    */
+	0x81, 0x02,       /*      Input (Variable),           */
+	0xB4,             /*      Pop,                        */
+	0x09, 0x30,       /*      Usage (Tip Pressure),       */
+	0x26, 0xFF, 0x07, /*      Logical Maximum (2047),     */
+	0x81, 0x02,       /*      Input (Variable),           */
+	0xC0,             /*    End Collection,               */
+	0xC0,             /*  End Collection,                 */
+	0x05, 0x01,       /*  Usage Page (Desktop),           */
+	0x09, 0x02,       /*  Usage (Mouse),                  */
+	0xA1, 0x01,       /*  Collection (Application),       */
+	0x85, 0x11,       /*    Report ID (17),               */
+	0x09, 0x01,       /*    Usage (Pointer),              */
+	0xA0,             /*    Collection (Physical),        */
+	0x14,             /*      Logical Minimum (0),        */
+	0xA4,             /*      Push,                       */
+	0x05, 0x09,       /*      Usage Page (Button),        */
+	0x75, 0x01,       /*      Report Size (1),            */
+	0x19, 0x01,       /*      Usage Minimum (01h),        */
+	0x29, 0x03,       /*      Usage Maximum (03h),        */
+	0x25, 0x01,       /*      Logical Maximum (1),        */
+	0x95, 0x03,       /*      Report Count (3),           */
+	0x81, 0x02,       /*      Input (Variable),           */
+	0x95, 0x05,       /*      Report Count (5),           */
+	0x81, 0x01,       /*      Input (Constant),           */
+	0xB4,             /*      Pop,                        */
+	0x95, 0x01,       /*      Report Count (1),           */
+	0xA4,             /*      Push,                       */
+	0x55, 0xFD,       /*      Unit Exponent (-3),         */
+	0x65, 0x13,       /*      Unit (Inch),                */
+	0x34,             /*      Physical Minimum (0),       */
+	0x75, 0x10,       /*      Report Size (16),           */
+	0x09, 0x30,       /*      Usage (X),                  */
+	0x46, 0x40, 0x1F, /*      Physical Maximum (8000),    */
+	0x26, 0x00, 0x50, /*      Logical Maximum (20480),    */
+	0x81, 0x02,       /*      Input (Variable),           */
+	0x09, 0x31,       /*      Usage (Y),                  */
+	0x46, 0x70, 0x17, /*      Physical Maximum (6000),    */
+	0x26, 0x00, 0x3C, /*      Logical Maximum (15360),    */
+	0x81, 0x02,       /*      Input (Variable),           */
+	0xB4,             /*      Pop,                        */
+	0x75, 0x08,       /*      Report Size (8),            */
+	0x09, 0x38,       /*      Usage (Wheel),              */
+	0x15, 0xFF,       /*      Logical Minimum (-1),       */
+	0x25, 0x01,       /*      Logical Maximum (1),        */
+	0x81, 0x06,       /*      Input (Variable, Relative), */
+	0x81, 0x01,       /*      Input (Constant),           */
+	0xC0,             /*    End Collection,               */
+	0xC0              /*  End Collection                  */
+};
+
 /*
  * See EasyPen M610X description, device and HID report descriptors at
  * http://sf.net/apps/mediawiki/digimend/?title=KYE_EasyPen_M610X
@@ -328,6 +427,12 @@ static __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc,
 			*rsize = sizeof(mousepen_i608x_rdesc_fixed);
 		}
 		break;
+	case USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2:
+		if (*rsize == MOUSEPEN_I608X_2_RDESC_ORIG_SIZE) {
+			rdesc = mousepen_i608x_2_rdesc_fixed;
+			*rsize = sizeof(mousepen_i608x_2_rdesc_fixed);
+		}
+		break;
 	case USB_DEVICE_ID_KYE_EASYPEN_M610X:
 		if (*rsize == EASYPEN_M610X_RDESC_ORIG_SIZE) {
 			rdesc = easypen_m610x_rdesc_fixed;
@@ -415,6 +520,7 @@ static int kye_probe(struct hid_device *hdev, const struct hid_device_id *id)
 	switch (id->product) {
 	case USB_DEVICE_ID_KYE_EASYPEN_I405X:
 	case USB_DEVICE_ID_KYE_MOUSEPEN_I608X:
+	case USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2:
 	case USB_DEVICE_ID_KYE_EASYPEN_M610X:
 		ret = kye_tablet_enable(hdev);
 		if (ret) {
@@ -446,6 +552,8 @@ static const struct hid_device_id kye_devices[] = {
 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
 				USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
+				USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
 				USB_DEVICE_ID_KYE_EASYPEN_M610X) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE,
 				USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) },
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index 8e4ddb3..85c01ec 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -113,6 +113,7 @@ static const struct hid_blacklist {
 	{ USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS, HID_QUIRK_MULTI_INPUT },
 	{ USB_VENDOR_ID_SIGMA_MICRO, USB_DEVICE_ID_SIGMA_MICRO_KEYBOARD, HID_QUIRK_NO_INIT_REPORTS },
 	{ USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X, HID_QUIRK_MULTI_INPUT },
+	{ USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2, HID_QUIRK_MULTI_INPUT },
 	{ USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X, HID_QUIRK_MULTI_INPUT },
 	{ USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_DUOSENSE, HID_QUIRK_NO_INIT_REPORTS },
 	{ USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_LTS1, HID_QUIRK_NO_INIT_REPORTS },


^ permalink raw reply related

* Re: [PATCH v2] leds: USB: Add support for MSI GT683R led panels
From: Janne Kanniainen @ 2014-06-07 10:12 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Bryan Wu, rpurdie, linux-kernel, linux-leds, linux-usb,
	Jiri Kosina, linux-input
In-Reply-To: <20140606094752.GB9307@localhost>

> First of all, please reply to the original thread and make sure to not
> drop people or lists from CC.

Sorry this is my first patch and i didn't know that. Now I know.

> For arrays you can use the ARRAY_SIZE() macro if that was the reason for
> this change. I should have mentioned that when I pointed out that you
> cannot use strlen().

That wasn't the reason. I just thought it might be better to use u64
than char[8]. I know why I can't use strlen and that was only careless
error. And there was lot of them :( I will be more careful next time.

> Where did you get these (HID report) values from by the way?

I got them by reverse engineering.

>> +
>> +static void gt683r_brightness_set(struct led_classdev *led_cdev,
>> +                               enum led_brightness brightness)
>> +{
>> +     struct gt683r_led *led =
>> +                     container_of(led_cdev, struct gt683r_led, led_dev);
>> +
>> +     mutex_lock(&led->lock);
>
> You cannot grab a mutex here since this function can be called from
> interrupt context (if I remember correctly). Either way, you shouldn't
> be holding the lock until the work task has finished...

I thought use asked me to put some lock there:

>> +
>> +static void gt683r_brightness_set(struct led_classdev *led_cdev,
>> +                               enum led_brightness brightness)
>> +{
>> +     struct gt683r_led *led =
>> +                     container_of(led_cdev, struct gt683r_led, led_dev);
>> +
>> +     led->brightness = brightness;
>
> Missing locking?

Janne

^ permalink raw reply

* [patch] Input: edt-ft5x06 - fix an i2c write for M09 support
From: Simon Budig @ 2014-06-07 23:53 UTC (permalink / raw)
  To: Dmitry Torokhov, Lothar Waßmann
  Cc: Henrik Rydberg, Grant Likely, Rob Herring, Fugang Duan,
	Jingoo Han, linux-input, kernel-janitors, Robert Wörle


[-- Attachment #1.1: Type: text/plain, Size: 1016 bytes --]

Hi all.

I received notice from Robert Wörle who spotted a bug in the ft5x06
driver (M09 support) which can result in bogus values being written into
the configuration registers.

Paul wrote:
> I think i found the problem, as the driver sends 3 bytes instead of 2
> when accessing a register on the M09 firmware.
> Therefore , writing to gain seems to overflow into the offset register.
> 
> This seems to be even in the lastet upstream driver so i created a patch
> for this driver  which you find attached.
> 
> @Simon Budig
> 
> Find attached a patch to fix this edt driver bug, feel free to comment ,
> test and commit upstream ;-)

He is right, his fix is correct. Please include his patch into the
repository.

Acked-By: Simon Budig <simon.budig@kernelconcepts.de>

Thanks,
        Simon
-- 
       Simon Budig                        kernel concepts GmbH
       simon.budig@kernelconcepts.de      Sieghuetter Hauptweg 48
       +49-271-771091-17                  D-57072 Siegen


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Input-edt-ft5x06-fix-i2c-writes-to-2-bytes-on-M09-fi.patch --]
[-- Type: text/x-patch; name="0001-Input-edt-ft5x06-fix-i2c-writes-to-2-bytes-on-M09-fi.patch", Size: 929 bytes --]

From 36b9ac0e8206efefc8795c925b0f3b63ab29fd08 Mon Sep 17 00:00:00 2001
From: Robert Woerle <robert@linuxdevelopment.de>
Date: Wed, 28 May 2014 13:22:09 +0200
Subject: [PATCH] Input: edt-ft5x06 - fix i2c writes to 2 bytes on M09
 firmware

Signed-off-by: Robert Woerle <robert@linuxdevelopment.de>
---
 drivers/input/touchscreen/edt-ft5x06.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
index f8815be..d4f3399 100644
--- a/drivers/input/touchscreen/edt-ft5x06.c
+++ b/drivers/input/touchscreen/edt-ft5x06.c
@@ -271,7 +271,7 @@ static int edt_ft5x06_register_write(struct edt_ft5x06_ts_data *tsdata,
 		wrbuf[0] = addr;
 		wrbuf[1] = value;
 
-		return edt_ft5x06_ts_readwrite(tsdata->client, 3,
+		return edt_ft5x06_ts_readwrite(tsdata->client, 2,
 					wrbuf, 0, NULL);
 
 	default:
-- 
1.7.9.5


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 242 bytes --]

^ permalink raw reply related


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