{"thread":{"id":"17712","subject":"[PATCH] lis3lv02d: support both one- and two-byte sensors","startedAt":"2009-02-11T00:01:59Z","lastAt":"2009-02-11T11:22:41Z","messageCount":3,"participants":["Giuseppe Bilotta","Michael J Gruber"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"104124","messageId":"1234310519-14230-1-git-send-email-giuseppe.bilotta@gmail.com","threadId":"17712","inReplyTo":null,"subject":"[PATCH] lis3lv02d: support both one- and two-byte sensors","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-02-11T00:01:59Z","receivedAt":"2009-02-11T00:01:59Z","isPatch":true,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Sensors responding with 0x3B to WHO_AM_I only have one data register per\ndirection, thus returning a signed byte from the position which is\noccupied by the MSB in sensors responding with 0x3A.\n\nWe support both kind of sensors by checking for the sensor type on init\nand defining appropriate data-access routines and sensor limits (for the\njoystick) depending on what we find.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\nAs pointed out by Eric, there's no need to jump through hoops to obtain\na signed 16-bit number from a signed 8-bit number.\n\nThis patch is good for -mm\n\nNote also that this patch is only about 8 vs 16 bit data, so the axis\norientation for HP notebooks still has to be fixed in a separate patch,\nbut at least now I should be able to check it out properly.\n\n drivers/hwmon/lis3lv02d.c |   41 ++++++++++++++++++++++++++++++-----------\n drivers/hwmon/lis3lv02d.h |   12 +++++++++++-\n 2 files changed, 41 insertions(+), 12 deletions(-)\n\ndiff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c\nindex 3afa3af..0f6528f 100644\n--- a/drivers/hwmon/lis3lv02d.c\n+++ b/drivers/hwmon/lis3lv02d.c\n@@ -53,9 +53,6 @@\n  * joystick.\n  */\n \n-/* Maximum value our axis may get for the input device (signed 12 bits) */\n-#define MDPS_MAX_VAL 2048\n-\n struct acpi_lis3lv02d adev = {\n \t.misc_wait   = __WAIT_QUEUE_HEAD_INITIALIZER(adev.misc_wait),\n };\n@@ -68,12 +65,19 @@ static s16 lis3lv02d_read_16(acpi_handle handle, int reg)\n {\n \tu8 lo, hi;\n \n-\tadev.read(handle, reg, &lo);\n-\tadev.read(handle, reg + 1, &hi);\n+\tadev.read(handle, reg - 1, &lo);\n+\tadev.read(handle, reg, &hi);\n \t/* In \"12 bit right justified\" mode, bit 6, bit 7, bit 8 = bit 5 */\n \treturn (s16)((hi << 8) | lo);\n }\n \n+static s16 lis3lv02d_read_8(acpi_handle handle, int reg)\n+{\n+\ts8 lo;\n+\tadev.read(handle, reg, &lo);\n+\treturn lo;\n+}\n+\n /**\n  * lis3lv02d_get_axis - For the given axis, give the value converted\n  * @axis:      1,2,3 - can also be negative\n@@ -102,9 +106,9 @@ static void lis3lv02d_get_xyz(acpi_handle handle, int *x, int *y, int *z)\n {\n \tint position[3];\n \n-\tposition[0] = lis3lv02d_read_16(handle, OUTX_L);\n-\tposition[1] = lis3lv02d_read_16(handle, OUTY_L);\n-\tposition[2] = lis3lv02d_read_16(handle, OUTZ_L);\n+\tposition[0] = adev.lis3lv02d_read(handle, OUTX);\n+\tposition[1] = adev.lis3lv02d_read(handle, OUTY);\n+\tposition[2] = adev.lis3lv02d_read(handle, OUTZ);\n \n \t*x = lis3lv02d_get_axis(adev.ac.x, position);\n \t*y = lis3lv02d_get_axis(adev.ac.y, position);\n@@ -121,6 +125,21 @@ void lis3lv02d_poweron(acpi_handle handle)\n {\n \tadev.is_on = 1;\n \tadev.init(handle);\n+\tadev.read(handle, WHO_AM_I, &adev.whoami);\n+\t/* Tell apart LISxLV02Dy from LISx02Dy family by checking the LSB\n+\t * (0x3A vs 0x3B). TODO More sophisticated checks on other registers\n+\t * could be implemented, for example to see if we have 2 or 3 axes, and\n+\t * configure the joystick accordingly.\n+\t */\n+\tif (adev.whoami & 1) {\n+\t\tprintk(KERN_INFO DRIVER_NAME \": 1-byte sensor found\\n\");\n+\t\tadev.lis3lv02d_read = lis3lv02d_read_8;\n+\t\tadev.mdps_max_val = 128;\n+\t} else {\n+\t\tprintk(KERN_INFO DRIVER_NAME \": 2-byte sensor found\\n\");\n+\t\tadev.lis3lv02d_read = lis3lv02d_read_16;\n+\t\tadev.mdps_max_val = 2048;\n+\t}\n }\n EXPORT_SYMBOL_GPL(lis3lv02d_poweron);\n \n@@ -355,9 +374,9 @@ int lis3lv02d_joystick_enable(void)\n \tadev.idev->close      = lis3lv02d_joystick_close;\n \n \tset_bit(EV_ABS, adev.idev->evbit);\n-\tinput_set_abs_params(adev.idev, ABS_X, -MDPS_MAX_VAL, MDPS_MAX_VAL, 3, 3);\n-\tinput_set_abs_params(adev.idev, ABS_Y, -MDPS_MAX_VAL, MDPS_MAX_VAL, 3, 3);\n-\tinput_set_abs_params(adev.idev, ABS_Z, -MDPS_MAX_VAL, MDPS_MAX_VAL, 3, 3);\n+\tinput_set_abs_params(adev.idev, ABS_X, -adev.mdps_max_val, adev.mdps_max_val, 3, 3);\n+\tinput_set_abs_params(adev.idev, ABS_Y, -adev.mdps_max_val, adev.mdps_max_val, 3, 3);\n+\tinput_set_abs_params(adev.idev, ABS_Z, -adev.mdps_max_val, adev.mdps_max_val, 3, 3);\n \n \terr = input_register_device(adev.idev);\n \tif (err) {\ndiff --git a/drivers/hwmon/lis3lv02d.h b/drivers/hwmon/lis3lv02d.h\nindex 2e7597c..cd0e838 100644\n--- a/drivers/hwmon/lis3lv02d.h\n+++ b/drivers/hwmon/lis3lv02d.h\n@@ -22,11 +22,14 @@\n /*\n  * The actual chip is STMicroelectronics LIS3LV02DL or LIS3LV02DQ that seems to\n  * be connected via SPI. There exists also several similar chips (such as LIS302DL or\n- * LIS3L02DQ) but not in the HP laptops and they have slightly different registers.\n+ * LIS3L02DQ) and they have slightly different registers, but we can provide a\n+ * common interface for all of them.\n  * They can also be connected via IÂ²C.\n  */\n \n+/* 2-byte registers */\n #define LIS3LV02DL_ID\t0x3A /* Also the LIS3LV02DQ */\n+/* 1-byte registers */\n #define LIS302DL_ID\t0x3B /* Also the LIS202DL! */\n \n enum lis3lv02d_reg {\n@@ -44,10 +47,13 @@ enum lis3lv02d_reg {\n \tSTATUS_REG\t= 0x27,\n \tOUTX_L\t\t= 0x28,\n \tOUTX_H\t\t= 0x29,\n+\tOUTX\t\t= 0x29,\n \tOUTY_L\t\t= 0x2A,\n \tOUTY_H\t\t= 0x2B,\n+\tOUTY\t\t= 0x2B,\n \tOUTZ_L\t\t= 0x2C,\n \tOUTZ_H\t\t= 0x2D,\n+\tOUTZ\t\t= 0x2D,\n \tFF_WU_CFG\t= 0x30,\n \tFF_WU_SRC\t= 0x31,\n \tFF_WU_ACK\t= 0x32,\n@@ -159,6 +165,10 @@ struct acpi_lis3lv02d {\n \tacpi_status (*write) (acpi_handle handle, int reg, u8 val);\n \tacpi_status (*read) (acpi_handle handle, int reg, u8 *ret);\n \n+\tu8\t\t\twhoami;    /* 3Ah: 2-byte registries, 3Bh: 1-byte registries */\n+\ts16 (*lis3lv02d_read) (acpi_handle handle, int reg);\n+\tint\t\t\tmdps_max_val;\n+\n \tstruct input_dev\t*idev;     /* input device */\n \tstruct task_struct\t*kthread;  /* kthread for input */\n \tstruct mutex            lock;\n-- \n1.6.2.rc0.173.g5e148\n"},{"id":"104175","messageId":"4992B393.8070808@drmicha.warpmail.net","threadId":"17712","inReplyTo":"1234310519-14230-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [PATCH] lis3lv02d: support both one- and two-byte sensors","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2009-02-11T11:16:35Z","receivedAt":"2009-02-11T11:16:35Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Giuseppe,\n\nyou may prefer sending this to the kernel mailing list rather than the\ngit list. But we can tell you the patch is formatted as a proper git\npatch ;)\n\nCheers,\nMichael\n"},{"id":"104176","messageId":"gmuce1$i20$1@ger.gmane.org","threadId":"17712","inReplyTo":"4992B393.8070808@drmicha.warpmail.net","subject":"Re: [PATCH] lis3lv02d: support both one- and two-byte sensors","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-02-11T11:22:41Z","receivedAt":"2009-02-11T11:22:41Z","isPatch":true,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"On Wednesday 11 February 2009 12:16, Michael J Gruber wrote:\n\n> Giuseppe,\n> \n> you may prefer sending this to the kernel mailing list rather than the\n> git list. But we can tell you the patch is formatted as a proper git\n> patch ;)\n\nI know, I'm terribly sorry for the spamming I did. Fingers automatically went\nfor 'git@vger' instead of 'linux-kernel@vger' ... I'm so much more used to\nsending patches to this list that it goes on automatically 8-/\n\nI'll try not to repeat the mistake in the future 8-)\n\n-- \nGiuseppe \"Oblomov\" Bilotta\n"}]}