Commit 2c6ecbba authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: synaptics - add synaptics_query_int()

Factor out querying and parsing 3-byte response into an integer value.
Reviewed-by: default avatarBenjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent a716a026
...@@ -190,6 +190,22 @@ static int synaptics_send_cmd(struct psmouse *psmouse, ...@@ -190,6 +190,22 @@ static int synaptics_send_cmd(struct psmouse *psmouse,
return 0; return 0;
} }
static int synaptics_query_int(struct psmouse *psmouse, u8 query_cmd, u32 *val)
{
int error;
union {
__be32 be_val;
char buf[4];
} resp = { 0 };
error = synaptics_send_cmd(psmouse, query_cmd, resp.buf + 1);
if (error)
return error;
*val = be32_to_cpu(resp.be_val);
return 0;
}
/* /*
* Identify Touchpad * Identify Touchpad
* See also the SYN_ID_* macros * See also the SYN_ID_* macros
...@@ -197,14 +213,12 @@ static int synaptics_send_cmd(struct psmouse *psmouse, ...@@ -197,14 +213,12 @@ static int synaptics_send_cmd(struct psmouse *psmouse,
static int synaptics_identify(struct psmouse *psmouse, static int synaptics_identify(struct psmouse *psmouse,
struct synaptics_device_info *info) struct synaptics_device_info *info)
{ {
unsigned char id[3];
int error; int error;
error = synaptics_send_cmd(psmouse, SYN_QUE_IDENTIFY, id); error = synaptics_query_int(psmouse, SYN_QUE_IDENTIFY, &info->identity);
if (error) if (error)
return error; return error;
info->identity = (id[0] << 16) | (id[1] << 8) | id[2];
return SYN_ID_IS_SYNAPTICS(info->identity) ? 0 : -ENXIO; return SYN_ID_IS_SYNAPTICS(info->identity) ? 0 : -ENXIO;
} }
...@@ -215,15 +229,7 @@ static int synaptics_identify(struct psmouse *psmouse, ...@@ -215,15 +229,7 @@ static int synaptics_identify(struct psmouse *psmouse,
static int synaptics_model_id(struct psmouse *psmouse, static int synaptics_model_id(struct psmouse *psmouse,
struct synaptics_device_info *info) struct synaptics_device_info *info)
{ {
unsigned char mi[3]; return synaptics_query_int(psmouse, SYN_QUE_MODEL, &info->model_id);
int error;
error = synaptics_send_cmd(psmouse, SYN_QUE_MODEL, mi);
if (error)
return error;
info->model_id = (mi[0] << 16) | (mi[1] << 8) | mi[2];
return 0;
} }
/* /*
...@@ -232,29 +238,8 @@ static int synaptics_model_id(struct psmouse *psmouse, ...@@ -232,29 +238,8 @@ static int synaptics_model_id(struct psmouse *psmouse,
static int synaptics_firmware_id(struct psmouse *psmouse, static int synaptics_firmware_id(struct psmouse *psmouse,
struct synaptics_device_info *info) struct synaptics_device_info *info)
{ {
unsigned char fwid[3]; return synaptics_query_int(psmouse, SYN_QUE_FIRMWARE_ID,
int error; &info->firmware_id);
error = synaptics_send_cmd(psmouse, SYN_QUE_FIRMWARE_ID, fwid);
if (error)
return error;
info->firmware_id = (fwid[0] << 16) | (fwid[1] << 8) | fwid[2];
return 0;
}
static int synaptics_more_extended_queries(struct psmouse *psmouse,
struct synaptics_device_info *info)
{
unsigned char buf[3];
int error;
error = synaptics_send_cmd(psmouse, SYN_QUE_MEXT_CAPAB_10, buf);
if (error)
return error;
info->ext_cap_10 = (buf[0] << 16) | (buf[1] << 8) | buf[2];
return 0;
} }
/* /*
...@@ -278,7 +263,8 @@ static int synaptics_query_modes(struct psmouse *psmouse, ...@@ -278,7 +263,8 @@ static int synaptics_query_modes(struct psmouse *psmouse,
info->board_id = ((bid[0] & 0xfc) << 6) | bid[1]; info->board_id = ((bid[0] & 0xfc) << 6) | bid[1];
if (SYN_MEXT_CAP_BIT(bid[0])) if (SYN_MEXT_CAP_BIT(bid[0]))
return synaptics_more_extended_queries(psmouse, info); return synaptics_query_int(psmouse, SYN_QUE_MEXT_CAPAB_10,
&info->ext_cap_10);
return 0; return 0;
} }
...@@ -290,14 +276,13 @@ static int synaptics_query_modes(struct psmouse *psmouse, ...@@ -290,14 +276,13 @@ static int synaptics_query_modes(struct psmouse *psmouse,
static int synaptics_capability(struct psmouse *psmouse, static int synaptics_capability(struct psmouse *psmouse,
struct synaptics_device_info *info) struct synaptics_device_info *info)
{ {
unsigned char cap[3];
int error; int error;
error = synaptics_send_cmd(psmouse, SYN_QUE_CAPABILITIES, cap); error = synaptics_query_int(psmouse, SYN_QUE_CAPABILITIES,
&info->capabilities);
if (error) if (error)
return error; return error;
info->capabilities = (cap[0] << 16) | (cap[1] << 8) | cap[2];
info->ext_cap = info->ext_cap_0c = 0; info->ext_cap = info->ext_cap_0c = 0;
/* /*
...@@ -315,29 +300,27 @@ static int synaptics_capability(struct psmouse *psmouse, ...@@ -315,29 +300,27 @@ static int synaptics_capability(struct psmouse *psmouse,
info->capabilities = 0; info->capabilities = 0;
if (SYN_EXT_CAP_REQUESTS(info->capabilities) >= 1) { if (SYN_EXT_CAP_REQUESTS(info->capabilities) >= 1) {
if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB, cap)) { error = synaptics_query_int(psmouse, SYN_QUE_EXT_CAPAB,
&info->ext_cap);
if (error) {
psmouse_warn(psmouse, psmouse_warn(psmouse,
"device claims to have extended capabilities, but I'm not able to read them.\n"); "device claims to have extended capabilities, but I'm not able to read them.\n");
} else { } else {
info->ext_cap = (cap[0] << 16) | (cap[1] << 8) | cap[2];
/* /*
* if nExtBtn is greater than 8 it should be considered * if nExtBtn is greater than 8 it should be considered
* invalid and treated as 0 * invalid and treated as 0
*/ */
if (SYN_CAP_MULTI_BUTTON_NO(info->ext_cap) > 8) if (SYN_CAP_MULTI_BUTTON_NO(info->ext_cap) > 8)
info->ext_cap &= 0xff0fff; info->ext_cap &= ~SYN_CAP_MB_MASK;
} }
} }
if (SYN_EXT_CAP_REQUESTS(info->capabilities) >= 4) { if (SYN_EXT_CAP_REQUESTS(info->capabilities) >= 4) {
error = synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB_0C, cap); error = synaptics_query_int(psmouse, SYN_QUE_EXT_CAPAB_0C,
&info->ext_cap_0c);
if (error) if (error)
psmouse_warn(psmouse, psmouse_warn(psmouse,
"device claims to have extended capability 0x0c, but I'm not able to read it.\n"); "device claims to have extended capability 0x0c, but I'm not able to read it.\n");
else
info->ext_cap_0c =
(cap[0] << 16) | (cap[1] << 8) | cap[2];
} }
return 0; return 0;
......
...@@ -52,7 +52,8 @@ ...@@ -52,7 +52,8 @@
#define SYN_CAP_PALMDETECT(c) ((c) & (1 << 0)) #define SYN_CAP_PALMDETECT(c) ((c) & (1 << 0))
#define SYN_CAP_SUBMODEL_ID(c) (((c) & 0x00ff00) >> 8) #define SYN_CAP_SUBMODEL_ID(c) (((c) & 0x00ff00) >> 8)
#define SYN_EXT_CAP_REQUESTS(c) (((c) & 0x700000) >> 20) #define SYN_EXT_CAP_REQUESTS(c) (((c) & 0x700000) >> 20)
#define SYN_CAP_MULTI_BUTTON_NO(ec) (((ec) & 0x00f000) >> 12) #define SYN_CAP_MB_MASK GENMASK(15, 12)
#define SYN_CAP_MULTI_BUTTON_NO(ec) (((ec) & SYN_CAP_MB_MASK) >> 12)
#define SYN_CAP_PRODUCT_ID(ec) (((ec) & 0xff0000) >> 16) #define SYN_CAP_PRODUCT_ID(ec) (((ec) & 0xff0000) >> 16)
#define SYN_MEXT_CAP_BIT(m) ((m) & (1 << 1)) #define SYN_MEXT_CAP_BIT(m) ((m) & (1 << 1))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment