diff options
author | Alex Gonzalez <alex.gonzalez@digi.com> | 2012-02-21 17:24:47 +0100 |
---|---|---|
committer | Alex Gonzalez <alex.gonzalez@digi.com> | 2012-02-21 17:24:47 +0100 |
commit | 80e108e8230ff1055aea30dfe9835f2b2e51e8f5 (patch) | |
tree | 189966c7ce9a730d1bbe98de1c1d94faa12a0bfc | |
parent | cea890c5f590c29e7c72cf033806461e59fca3b8 (diff) |
mma7455: Fix sign extension for 10bits read.
When reading a 10bits number, the 2s complement MSB is the sign. This bit
cannot be just shifted to bit 16, the number has to be sign extended.
0abcdefghij => 00000abcdefghij
1abcdefghij => 11111abcdefghij
Signed-off-by: Alex Gonzalez <alex.gonzalez@digi.com>
-rw-r--r-- | drivers/input/misc/mma7455l.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/drivers/input/misc/mma7455l.c b/drivers/input/misc/mma7455l.c index e01ecb7847c6..f8e80f1f6728 100644 --- a/drivers/input/misc/mma7455l.c +++ b/drivers/input/misc/mma7455l.c @@ -218,11 +218,16 @@ static u_int8_t reg_read(struct mma7455l_info *mma, u_int8_t reg) static s16 __reg_read_10(struct mma7455l_info *mma, u8 reg1, u8 reg2) { u8 v1, v2; + s16 ret; v1 = __reg_read(mma, reg1); v2 = __reg_read(mma, reg2); - return (v2 & 0x4) << 13 | (v2 & 0x3) << 8 | v1; + // ret is 11bits, 3 MSB from v2 and 8 LSB from v1. + ret = (((v2 & 0x7) << 8 | v1) & 0x7FF) << 5; + // Sign extension. Being ret signed, this will fill the MSBs with + // either 0s o 1s depending on whether bit10 is 0 or 1. + return (ret >>= 5); } static int reg_write(struct mma7455l_info *mma, u_int8_t reg, u_int8_t val) |