From cf77093219d276399ade58f45e4cb05e6f4f4604 Mon Sep 17 00:00:00 2001 From: lyx Date: Tue, 24 May 2011 01:49:21 -0700 Subject: [PATCH] add boardconfig for gsensor orientation --- arch/arm/mach-rk29/board-rk29-a22.c | 4 ++++ arch/arm/mach-rk29/include/mach/board.h | 2 ++ drivers/input/gsensor/mma8452.c | 22 +++++++++++++++++----- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/arch/arm/mach-rk29/board-rk29-a22.c b/arch/arm/mach-rk29/board-rk29-a22.c index 3044a2af0dc8..aa0116d6996c 100755 --- a/arch/arm/mach-rk29/board-rk29-a22.c +++ b/arch/arm/mach-rk29/board-rk29-a22.c @@ -477,6 +477,10 @@ static int mma8452_init_platform_hw(void) static struct mma8452_platform_data mma8452_info = { .model= 8452, .swap_xy = 0, + .swap_xyz = 1, + .orientation = {0,1,0, + 0,0,-1, + 1,0,0}, .init_platform_hw= mma8452_init_platform_hw, }; diff --git a/arch/arm/mach-rk29/include/mach/board.h b/arch/arm/mach-rk29/include/mach/board.h index 7d3654e176dd..a761ee53520e 100755 --- a/arch/arm/mach-rk29/include/mach/board.h +++ b/arch/arm/mach-rk29/include/mach/board.h @@ -184,6 +184,8 @@ struct synaptics_platform_data { struct mma8452_platform_data { u16 model; u16 swap_xy; + u16 swap_xyz; + signed char orientation[9]; int (*get_pendown_state)(void); int (*init_platform_hw)(void); int (*mma8452_platform_sleep)(void); diff --git a/drivers/input/gsensor/mma8452.c b/drivers/input/gsensor/mma8452.c index ffa42b1aba98..cbcf6f5f4ecf 100755 --- a/drivers/input/gsensor/mma8452.c +++ b/drivers/input/gsensor/mma8452.c @@ -358,6 +358,7 @@ static int mma8452_get_data(struct i2c_client *client) struct mma8452_data* mma8452 = i2c_get_clientdata(client); char buffer[6]; int ret; + int x,y,z; struct mma8452_axis axis; struct mma8452_platform_data *pdata = pdata = client->dev.platform_data; @@ -371,11 +372,22 @@ static int mma8452_get_data(struct i2c_client *client) } while (0); mmaprintkd("0x%02x 0x%02x 0x%02x \n",buffer[0],buffer[1],buffer[2]); - - axis.x = mma8452_convert_to_int(buffer[0]); - axis.y = mma8452_convert_to_int(buffer[1]); - axis.z = mma8452_convert_to_int(buffer[2]); - + + x = mma8452_convert_to_int(buffer[0]); + y = mma8452_convert_to_int(buffer[1]); + z = mma8452_convert_to_int(buffer[2]); + + if (pdata->swap_xyz) { + axis.x = (pdata->orientation[0])*x + (pdata->orientation[1])*y + (pdata->orientation[2])*z; + axis.y = (pdata->orientation[3])*x + (pdata->orientation[4])*y + (pdata->orientation[5])*z; + axis.z = (pdata->orientation[6])*x + (pdata->orientation[7])*y + (pdata->orientation[8])*z; + } + else { + axis.x = x; + axis.y = y; + axis.z = z; + } + if(pdata->swap_xy) { axis.y = -axis.y; -- 2.34.1