Skip to content

Commit 8640229

Browse files
JoseExpositoJiri Kosina
authored andcommitted
HID: uclogic: Refactor UGEE v2 frame initialization
At the moment, the driver only supports UGEE v2 devices that have buttons in their frames. In order to support other types of frames in the future, move the code used to initialize this kind of frames to its own function. Tested-by: Jouke Witteveen <[email protected]> Signed-off-by: José Expósito <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent a64cbf3 commit 8640229

File tree

1 file changed

+38
-18
lines changed

1 file changed

+38
-18
lines changed

drivers/hid/hid-uclogic-params.c

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,41 @@ static int uclogic_params_parse_ugee_v2_desc(const __u8 *str_desc,
11121112
return 0;
11131113
}
11141114

1115+
/**
1116+
* uclogic_params_ugee_v2_init_frame_buttons() - initialize a UGEE v2 frame with
1117+
* buttons.
1118+
* @p: Parameters to fill in, cannot be NULL.
1119+
* @desc_params: Device description params list.
1120+
* @desc_params_size: Size of the description params list.
1121+
*
1122+
* Returns:
1123+
* Zero, if successful. A negative errno code on error.
1124+
*/
1125+
static int uclogic_params_ugee_v2_init_frame_buttons(struct uclogic_params *p,
1126+
const s32 *desc_params,
1127+
size_t desc_params_size)
1128+
{
1129+
__u8 *rdesc_frame = NULL;
1130+
int rc = 0;
1131+
1132+
if (!p || desc_params_size != UCLOGIC_RDESC_PH_ID_NUM)
1133+
return -EINVAL;
1134+
1135+
rdesc_frame = uclogic_rdesc_template_apply(
1136+
uclogic_rdesc_ugee_v2_frame_btn_template_arr,
1137+
uclogic_rdesc_ugee_v2_frame_btn_template_size,
1138+
desc_params, UCLOGIC_RDESC_PH_ID_NUM);
1139+
if (!rdesc_frame)
1140+
return -ENOMEM;
1141+
1142+
rc = uclogic_params_frame_init_with_desc(&p->frame_list[0],
1143+
rdesc_frame,
1144+
uclogic_rdesc_ugee_v2_frame_btn_template_size,
1145+
UCLOGIC_RDESC_V1_FRAME_ID);
1146+
kfree(rdesc_frame);
1147+
return rc;
1148+
}
1149+
11151150
/**
11161151
* uclogic_params_ugee_v2_init() - initialize a UGEE graphics tablets by
11171152
* discovering their parameters.
@@ -1140,7 +1175,6 @@ static int uclogic_params_ugee_v2_init(struct uclogic_params *params,
11401175
const int str_desc_len = 12;
11411176
__u8 *str_desc = NULL;
11421177
__u8 *rdesc_pen = NULL;
1143-
__u8 *rdesc_frame = NULL;
11441178
s32 desc_params[UCLOGIC_RDESC_PH_ID_NUM];
11451179
__u8 magic_arr[] = {
11461180
0x02, 0xb0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
@@ -1209,24 +1243,10 @@ static int uclogic_params_ugee_v2_init(struct uclogic_params *params,
12091243
p.pen.subreport_list[0].id = UCLOGIC_RDESC_V1_FRAME_ID;
12101244

12111245
/* Initialize the frame interface */
1212-
rdesc_frame = uclogic_rdesc_template_apply(
1213-
uclogic_rdesc_ugee_v2_frame_btn_template_arr,
1214-
uclogic_rdesc_ugee_v2_frame_btn_template_size,
1215-
desc_params, ARRAY_SIZE(desc_params));
1216-
if (!rdesc_frame) {
1217-
rc = -ENOMEM;
1246+
rc = uclogic_params_ugee_v2_init_frame_buttons(&p, desc_params,
1247+
ARRAY_SIZE(desc_params));
1248+
if (rc)
12181249
goto cleanup;
1219-
}
1220-
1221-
rc = uclogic_params_frame_init_with_desc(&p.frame_list[0],
1222-
rdesc_frame,
1223-
uclogic_rdesc_ugee_v2_frame_btn_template_size,
1224-
UCLOGIC_RDESC_V1_FRAME_ID);
1225-
kfree(rdesc_frame);
1226-
if (rc) {
1227-
uclogic_params_init_invalid(&p);
1228-
goto output;
1229-
}
12301250

12311251
output:
12321252
/* Output parameters */

0 commit comments

Comments
 (0)