From: "Jean-François Dagenais" <jeff.dagenais@gmail.com>
To: michael.hennerich@analog.com
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org,
device-drivers-devel@blackfin.uclinux.org,
"Jean-François Dagenais" <jeff.dagenais@gmail.com>,
"Jean-François Dagenais" <dagenaisj@sonatest.com>
Subject: [PATCH 1/2] input: ad714x - fix divide by 0 error in wheel cal_abs_pos
Date: Thu, 26 Apr 2012 13:17:18 -0400 [thread overview]
Message-ID: <1335460639-1362-1-git-send-email-jeff.dagenais@gmail.com> (raw)
V2: added comment, removed "BUG_ON" check and fixed >80 col line
As discussed with Michael Hennerich <michael.hennerich@analog.com>,
another divide by 0 happens when the user is lifting the finger
when all the sensors are back below ambient but we are in case
"ACTIVE".
Signed-off-by: Jean-François Dagenais <dagenaisj@sonatest.com>
Signed-off-by: Jean-François Dagenais <jeff.dagenais@gmail.com>
---
drivers/input/misc/ad714x.c | 16 ++++++++++++----
1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/drivers/input/misc/ad714x.c b/drivers/input/misc/ad714x.c
index ca42c7d..2cf26e5 100644
--- a/drivers/input/misc/ad714x.c
+++ b/drivers/input/misc/ad714x.c
@@ -418,10 +418,15 @@ static void ad714x_wheel_cal_highest_stage(struct ad714x_chip *ad714x, int idx)
sw->highest_stage);
}
-static void ad714x_wheel_cal_sensor_val(struct ad714x_chip *ad714x, int idx)
+/**
+ * Calculates the sensor value for each stages of the given wheel idx.
+ * Returns true if a sensor detects being touched, false otherwise.
+ */
+static bool ad714x_wheel_cal_sensor_val(struct ad714x_chip *ad714x, int idx)
{
struct ad714x_wheel_plat *hw = &ad714x->hw->wheel[idx];
int i;
+ bool touched = false;
ad714x->read(ad714x, CDC_RESULT_S0 + hw->start_stage,
&ad714x->adc_reg[hw->start_stage],
@@ -430,12 +435,15 @@ static void ad714x_wheel_cal_sensor_val(struct ad714x_chip *ad714x, int idx)
for (i = hw->start_stage; i <= hw->end_stage; i++) {
ad714x->read(ad714x, STAGE0_AMBIENT + i * PER_STAGE_REG_NUM,
&ad714x->amb_reg[i], 1);
- if (ad714x->adc_reg[i] > ad714x->amb_reg[i])
+ if (ad714x->adc_reg[i] > ad714x->amb_reg[i]) {
ad714x->sensor_val[i] =
ad714x->adc_reg[i] - ad714x->amb_reg[i];
+ touched = true;
+ }
else
ad714x->sensor_val[i] = 0;
}
+ return touched;
}
/*
@@ -544,8 +552,8 @@ static void ad714x_wheel_state_machine(struct ad714x_chip *ad714x, int idx)
case ACTIVE:
if (c_state == mask) {
- if (h_state) {
- ad714x_wheel_cal_sensor_val(ad714x, idx);
+ if (h_state &&
+ ad714x_wheel_cal_sensor_val(ad714x, idx)) {
ad714x_wheel_cal_highest_stage(ad714x, idx);
ad714x_wheel_cal_abs_pos(ad714x, idx);
ad714x_wheel_cal_flt_pos(ad714x, idx);
--
1.7.9
--
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
next reply other threads:[~2012-04-26 17:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-26 17:17 Jean-François Dagenais [this message]
2012-04-26 17:17 ` [PATCH 2/2] input: ad714x - use stage qty to split max_coord for wheel algo Jean-François Dagenais
2012-04-27 1:33 ` Jean-François Dagenais
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1335460639-1362-1-git-send-email-jeff.dagenais@gmail.com \
--to=jeff.dagenais@gmail.com \
--cc=dagenaisj@sonatest.com \
--cc=device-drivers-devel@blackfin.uclinux.org \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=michael.hennerich@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).