linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] elan_i2c - Don't require known iap version
@ 2015-09-18 13:38 Daniel Drake
  2015-09-19 17:10 ` Dmitry Torokhov
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Drake @ 2015-09-18 13:38 UTC (permalink / raw)
  To: dmitry.torokhov, dusonlin; +Cc: jprvita, linux-input

The Asus X456UA has an ELAN1000 touchpad with IAP version 0xe.
This is unknown to elan_get_fwinfo() so driver probe fails and I
am left with an unusable touchpad.

However, the fwinfo is not required for general driver usage,
it is only needed if the user decides to upload new firmware.

Adjust the driver so that fwinfo is only calculated and used
when it is really needed.

Signed-off-by: Daniel Drake <drake@endlessm.com>
---
 drivers/input/mouse/elan_i2c_core.c | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

v2: simplified dev_err call

diff --git a/drivers/input/mouse/elan_i2c_core.c b/drivers/input/mouse/elan_i2c_core.c
index fa94530..bababfe 100644
--- a/drivers/input/mouse/elan_i2c_core.c
+++ b/drivers/input/mouse/elan_i2c_core.c
@@ -84,8 +84,6 @@ struct elan_tp_data {
 	int			pressure_adjustment;
 	u8			mode;
 	u8			ic_type;
-	u16			fw_validpage_count;
-	u16			fw_signature_address;
 
 	bool			irq_wake;
 
@@ -264,14 +262,6 @@ static int elan_query_device_info(struct elan_tp_data *data)
 	if (error)
 		return error;
 
-	error = elan_get_fwinfo(data->iap_version, &data->fw_validpage_count,
-				&data->fw_signature_address);
-	if (error) {
-		dev_err(&data->client->dev,
-			"unknown iap version %d\n", data->iap_version);
-		return error;
-	}
-
 	return 0;
 }
 
@@ -339,7 +329,8 @@ static int elan_write_fw_block(struct elan_tp_data *data,
 }
 
 static int __elan_update_firmware(struct elan_tp_data *data,
-				  const struct firmware *fw)
+				  const struct firmware *fw,
+				  u16 fw_validpage_count)
 {
 	struct i2c_client *client = data->client;
 	struct device *dev = &client->dev;
@@ -356,7 +347,7 @@ static int __elan_update_firmware(struct elan_tp_data *data,
 	iap_start_addr = get_unaligned_le16(&fw->data[ETP_IAP_START_ADDR * 2]);
 
 	boot_page_count = (iap_start_addr * 2) / ETP_FW_PAGE_SIZE;
-	for (i = boot_page_count; i < data->fw_validpage_count; i++) {
+	for (i = boot_page_count; i < fw_validpage_count; i++) {
 		u16 checksum = 0;
 		const u8 *page = &fw->data[i * ETP_FW_PAGE_SIZE];
 
@@ -393,7 +384,8 @@ static int __elan_update_firmware(struct elan_tp_data *data,
 }
 
 static int elan_update_firmware(struct elan_tp_data *data,
-				const struct firmware *fw)
+				const struct firmware *fw,
+				u16 fw_validpage_count)
 {
 	struct i2c_client *client = data->client;
 	int retval;
@@ -403,7 +395,7 @@ static int elan_update_firmware(struct elan_tp_data *data,
 	disable_irq(client->irq);
 	data->in_fw_update = true;
 
-	retval = __elan_update_firmware(data, fw);
+	retval = __elan_update_firmware(data, fw, fw_validpage_count);
 	if (retval) {
 		dev_err(&client->dev, "firmware update failed: %d\n", retval);
 		data->ops->iap_reset(client);
@@ -485,6 +477,15 @@ static ssize_t elan_sysfs_update_fw(struct device *dev,
 	int error;
 	const u8 *fw_signature;
 	static const u8 signature[] = {0xAA, 0x55, 0xCC, 0x33, 0xFF, 0xFF};
+	u16 fw_validpage_count;
+	u16 fw_signature_address;
+
+	error = elan_get_fwinfo(data->iap_version, &fw_validpage_count,
+				&fw_signature_address);
+	if (error) {
+		dev_err(dev, "unknown iap version %d\n", data->iap_version);
+		return error;
+	}
 
 	/* Look for a firmware with the product id appended. */
 	fw_name = kasprintf(GFP_KERNEL, ETP_FW_NAME, data->product_id);
@@ -502,7 +503,7 @@ static ssize_t elan_sysfs_update_fw(struct device *dev,
 	}
 
 	/* Firmware file must match signature data */
-	fw_signature = &fw->data[data->fw_signature_address];
+	fw_signature = &fw->data[fw_signature_address];
 	if (memcmp(fw_signature, signature, sizeof(signature)) != 0) {
 		dev_err(dev, "signature mismatch (expected %*ph, got %*ph)\n",
 			(int)sizeof(signature), signature,
@@ -515,7 +516,7 @@ static ssize_t elan_sysfs_update_fw(struct device *dev,
 	if (error)
 		goto out_release_fw;
 
-	error = elan_update_firmware(data, fw);
+	error = elan_update_firmware(data, fw, fw_validpage_count);
 
 	mutex_unlock(&data->sysfs_mutex);
 
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] elan_i2c - Don't require known iap version
  2015-09-18 13:38 [PATCH v2] elan_i2c - Don't require known iap version Daniel Drake
@ 2015-09-19 17:10 ` Dmitry Torokhov
  2015-09-21 14:28   ` Daniel Drake
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Torokhov @ 2015-09-19 17:10 UTC (permalink / raw)
  To: Daniel Drake; +Cc: dusonlin, jprvita, linux-input

Hi Daniel,

On Fri, Sep 18, 2015 at 07:38:15AM -0600, Daniel Drake wrote:
> The Asus X456UA has an ELAN1000 touchpad with IAP version 0xe.
> This is unknown to elan_get_fwinfo() so driver probe fails and I
> am left with an unusable touchpad.
> 
> However, the fwinfo is not required for general driver usage,
> it is only needed if the user decides to upload new firmware.
> 
> Adjust the driver so that fwinfo is only calculated and used
> when it is really needed.

I do not like the fact that the fact that the version of IAP is unknown
is not known to the driver until we try to flash the firmware. I'd
rather we check it upfront and warn user.

How about the version of the patch below?

Thanks!

-- 
Dmitry

Input: elan_i2c - don't require known iap version

From: Daniel Drake <drake@endlessm.com>

The Asus X456UA has an ELAN1000 touchpad with IAP version 0xe.  This is
unknown to elan_get_fwinfo() so driver probe fails and I am left with an
unusable touchpad.

However, the fwinfo is not required for general driver usage, it is only
needed if the user decides to upload new firmware.

Adjust the driver so that we do not abort probe when we encounter
unexpected IAP version, but rather warn user that firmware update feature
of the driver will not work.

Signed-off-by: Daniel Drake <drake@endlessm.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/mouse/elan_i2c_core.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/input/mouse/elan_i2c_core.c b/drivers/input/mouse/elan_i2c_core.c
index fa94530..7cad819 100644
--- a/drivers/input/mouse/elan_i2c_core.c
+++ b/drivers/input/mouse/elan_i2c_core.c
@@ -266,11 +266,10 @@ static int elan_query_device_info(struct elan_tp_data *data)
 
 	error = elan_get_fwinfo(data->iap_version, &data->fw_validpage_count,
 				&data->fw_signature_address);
-	if (error) {
-		dev_err(&data->client->dev,
-			"unknown iap version %d\n", data->iap_version);
-		return error;
-	}
+	if (error)
+		dev_warn(&data->client->dev,
+			 "unexpected iap version %#04x (ic type: %#04x), firmware update will not work\n",
+			 data->iap_version, data->ic_type);
 
 	return 0;
 }
@@ -486,6 +485,9 @@ static ssize_t elan_sysfs_update_fw(struct device *dev,
 	const u8 *fw_signature;
 	static const u8 signature[] = {0xAA, 0x55, 0xCC, 0x33, 0xFF, 0xFF};
 
+	if (data->fw_validpage_count == 0)
+		return -EINVAL;
+
 	/* Look for a firmware with the product id appended. */
 	fw_name = kasprintf(GFP_KERNEL, ETP_FW_NAME, data->product_id);
 	if (!fw_name) {

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] elan_i2c - Don't require known iap version
  2015-09-19 17:10 ` Dmitry Torokhov
@ 2015-09-21 14:28   ` Daniel Drake
  2015-09-21 16:17     ` Dmitry Torokhov
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Drake @ 2015-09-21 14:28 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: DusonLin, João Paulo Rechi Vita, linux-input

On Sat, Sep 19, 2015 at 11:10 AM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> I do not like the fact that the fact that the version of IAP is unknown
> is not known to the driver until we try to flash the firmware. I'd
> rather we check it upfront and warn user.
>
> How about the version of the patch below?

That looks fine and I also confirmed that the new patch is working as described.

Thanks
Daniel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] elan_i2c - Don't require known iap version
  2015-09-21 14:28   ` Daniel Drake
@ 2015-09-21 16:17     ` Dmitry Torokhov
  2015-09-21 16:21       ` Dmitry Torokhov
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Torokhov @ 2015-09-21 16:17 UTC (permalink / raw)
  To: Daniel Drake; +Cc: DusonLin, João Paulo Rechi Vita, linux-input

On Mon, Sep 21, 2015 at 08:28:17AM -0600, Daniel Drake wrote:
> On Sat, Sep 19, 2015 at 11:10 AM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
> > I do not like the fact that the fact that the version of IAP is unknown
> > is not known to the driver until we try to flash the firmware. I'd
> > rather we check it upfront and warn user.
> >
> > How about the version of the patch below?
> 
> That looks fine and I also confirmed that the new patch is working as described.

Great, I am applying this then.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] elan_i2c - Don't require known iap version
  2015-09-21 16:17     ` Dmitry Torokhov
@ 2015-09-21 16:21       ` Dmitry Torokhov
  2015-09-21 23:47         ` DusonLin
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Torokhov @ 2015-09-21 16:21 UTC (permalink / raw)
  To: Daniel Drake; +Cc: DusonLin, João Paulo Rechi Vita, linux-input

On Mon, Sep 21, 2015 at 09:17:40AM -0700, Dmitry Torokhov wrote:
> On Mon, Sep 21, 2015 at 08:28:17AM -0600, Daniel Drake wrote:
> > On Sat, Sep 19, 2015 at 11:10 AM, Dmitry Torokhov
> > <dmitry.torokhov@gmail.com> wrote:
> > > I do not like the fact that the fact that the version of IAP is unknown
> > > is not known to the driver until we try to flash the firmware. I'd
> > > rather we check it upfront and warn user.
> > >
> > > How about the version of the patch below?
> > 
> > That looks fine and I also confirmed that the new patch is working as described.
> 
> Great, I am applying this then.

Duson, by the way, what is the FW parameters for iap 0x0e? Could you
send me a patch?

Thanks!

-- 
Dmitry

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH v2] elan_i2c - Don't require known iap version
  2015-09-21 16:21       ` Dmitry Torokhov
@ 2015-09-21 23:47         ` DusonLin
  0 siblings, 0 replies; 6+ messages in thread
From: DusonLin @ 2015-09-21 23:47 UTC (permalink / raw)
  To: 'Dmitry Torokhov', 'Daniel Drake'
  Cc: 'João Paulo Rechi Vita', linux-input

Hi Dmitry,

Sure, not only 0x0E but also others, I will send you a patch.

Thank you,
Duson

-----Original Message-----
From: Dmitry Torokhov [mailto:dmitry.torokhov@gmail.com] 
Sent: Tuesday, September 22, 2015 12:21 AM
To: Daniel Drake
Cc: DusonLin; João Paulo Rechi Vita; linux-input@vger.kernel.org
Subject: Re: [PATCH v2] elan_i2c - Don't require known iap version

On Mon, Sep 21, 2015 at 09:17:40AM -0700, Dmitry Torokhov wrote:
> On Mon, Sep 21, 2015 at 08:28:17AM -0600, Daniel Drake wrote:
> > On Sat, Sep 19, 2015 at 11:10 AM, Dmitry Torokhov 
> > <dmitry.torokhov@gmail.com> wrote:
> > > I do not like the fact that the fact that the version of IAP is 
> > > unknown is not known to the driver until we try to flash the 
> > > firmware. I'd rather we check it upfront and warn user.
> > >
> > > How about the version of the patch below?
> > 
> > That looks fine and I also confirmed that the new patch is working as
described.
> 
> Great, I am applying this then.

Duson, by the way, what is the FW parameters for iap 0x0e? Could you send me
a patch?

Thanks!

--
Dmitry

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-09-21 23:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-18 13:38 [PATCH v2] elan_i2c - Don't require known iap version Daniel Drake
2015-09-19 17:10 ` Dmitry Torokhov
2015-09-21 14:28   ` Daniel Drake
2015-09-21 16:17     ` Dmitry Torokhov
2015-09-21 16:21       ` Dmitry Torokhov
2015-09-21 23:47         ` DusonLin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).