Skip to content

Commit 6016153

Browse files
flukejonesKyleGospo
authored andcommitted
[FOR-UPSTREAM] hid-asus-ally: add anti-deadzones
Signed-off-by: Luke D. Jones <luke@ljones.dev>
1 parent a0d13c7 commit 6016153

2 files changed

Lines changed: 112 additions & 0 deletions

File tree

drivers/hid/hid-asus-ally.c

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ struct ally_gamepad_cfg {
283283
struct deadzone rs_dz; // right stick
284284
struct deadzone lt_dz; // left trigger
285285
struct deadzone rt_dz; // right trigger
286+
/* anti-deadzones */
287+
u8 ls_adz; // left stick
288+
u8 rs_adz; // right stick
286289
};
287290

288291
/* The hatswitch outputs integers, we use them to index this X|Y pair */
@@ -616,7 +619,109 @@ ALLY_DEADZONES(axis_xy_right, rs_dz);
616619
ALLY_DEADZONES(axis_z_left, lt_dz);
617620
ALLY_DEADZONES(axis_z_right, rt_dz);
618621

622+
/* ANTI-DEADZONES *********************************************************************************/
623+
static ssize_t _gamepad_apply_js_ADZ(struct hid_device *hdev,
624+
struct ally_gamepad_cfg *ally_cfg)
625+
{
626+
u8 *hidbuf;
627+
int ret;
628+
629+
hidbuf = kzalloc(FEATURE_ROG_ALLY_REPORT_SIZE, GFP_KERNEL);
630+
if (!hidbuf)
631+
return -ENOMEM;
632+
633+
hidbuf[0] = FEATURE_ROG_ALLY_REPORT_ID;
634+
hidbuf[1] = FEATURE_ROG_ALLY_CODE_PAGE;
635+
hidbuf[2] = xpad_cmd_set_adz;
636+
hidbuf[3] = xpad_cmd_len_adz;
637+
hidbuf[4] = ally_cfg->ls_adz;
638+
hidbuf[5] = ally_cfg->rs_adz;
639+
640+
ret = ally_gamepad_check_ready(hdev);
641+
if (ret < 0)
642+
goto report_fail;
643+
644+
ret = asus_dev_set_report(hdev, hidbuf, FEATURE_ROG_ALLY_REPORT_SIZE);
645+
if (ret < 0)
646+
goto report_fail;
647+
648+
report_fail:
649+
kfree(hidbuf);
650+
return ret;
651+
}
652+
653+
static void _gamepad_set_anti_deadzones_default(struct ally_gamepad_cfg *ally_cfg)
654+
{
655+
ally_cfg->ls_adz = 0x00;
656+
ally_cfg->rs_adz = 0x00;
657+
}
658+
659+
static ssize_t _gamepad_js_ADZ_store(struct device *dev, const char *buf, u8 *adz)
660+
{
661+
int ret, val;
662+
663+
ret = kstrtoint(buf, 0, &val);
664+
if (ret)
665+
return ret;
666+
667+
if (val < 0 || val > 32)
668+
return -EINVAL;
669+
670+
*adz = val;
671+
672+
return ret;
673+
}
674+
675+
static ssize_t axis_xy_left_anti_deadzone_show(struct device *dev,
676+
struct device_attribute *attr,
677+
char *buf)
678+
{
679+
struct ally_gamepad_cfg *ally_cfg = drvdata.gamepad_cfg;
680+
681+
return sysfs_emit(buf, "%d\n", ally_cfg->ls_adz);
682+
}
683+
684+
static ssize_t axis_xy_left_anti_deadzone_store(struct device *dev,
685+
struct device_attribute *attr,
686+
const char *buf, size_t count)
687+
{
688+
struct ally_gamepad_cfg *ally_cfg = drvdata.gamepad_cfg;
689+
int ret;
690+
691+
ret = _gamepad_js_ADZ_store(dev, buf, &ally_cfg->ls_adz);
692+
if (ret)
693+
return ret;
694+
695+
return count;
696+
}
697+
ALLY_DEVICE_ATTR_RW(axis_xy_left_anti_deadzone, anti_deadzone);
698+
699+
static ssize_t axis_xy_right_anti_deadzone_show(struct device *dev,
700+
struct device_attribute *attr,
701+
char *buf)
702+
{
703+
struct ally_gamepad_cfg *ally_cfg = drvdata.gamepad_cfg;
704+
705+
return sysfs_emit(buf, "%d\n", ally_cfg->rs_adz);
706+
}
707+
708+
static ssize_t axis_xy_right_anti_deadzone_store(struct device *dev,
709+
struct device_attribute *attr,
710+
const char *buf, size_t count)
711+
{
712+
struct ally_gamepad_cfg *ally_cfg = drvdata.gamepad_cfg;
713+
int ret;
714+
715+
ret = _gamepad_js_ADZ_store(dev, buf, &ally_cfg->rs_adz);
716+
if (ret)
717+
return ret;
718+
719+
return count;
720+
}
721+
ALLY_DEVICE_ATTR_RW(axis_xy_right_anti_deadzone, anti_deadzone);
722+
619723
static struct attribute *axis_xy_left_attrs[] = {
724+
&dev_attr_axis_xy_left_anti_deadzone.attr,
620725
&dev_attr_axis_xy_left_deadzone.attr,
621726
&dev_attr_axis_xyz_deadzone_index.attr,
622727
NULL
@@ -627,6 +732,7 @@ static const struct attribute_group axis_xy_left_attr_group = {
627732
};
628733

629734
static struct attribute *axis_xy_right_attrs[] = {
735+
&dev_attr_axis_xy_right_anti_deadzone.attr,
630736
&dev_attr_axis_xy_right_deadzone.attr,
631737
&dev_attr_axis_xyz_deadzone_index.attr,
632738
NULL
@@ -821,6 +927,9 @@ static ssize_t _gamepad_apply_all(struct hid_device *hdev, struct ally_gamepad_c
821927
if (ret < 0)
822928
return ret;
823929
ret = _gamepad_apply_deadzones(hdev, ally_cfg);
930+
if (ret < 0)
931+
return ret;
932+
ret = _gamepad_apply_js_ADZ(hdev, ally_cfg);
824933
if (ret < 0)
825934
return ret;
826935

@@ -1067,6 +1176,7 @@ static struct ally_gamepad_cfg *ally_gamepad_cfg_create(struct hid_device *hdev)
10671176
ally_cfg->vibration_intensity[0] = 0x64;
10681177
ally_cfg->vibration_intensity[1] = 0x64;
10691178
_gamepad_set_deadzones_default(ally_cfg);
1179+
_gamepad_set_anti_deadzones_default(ally_cfg);
10701180

10711181
drvdata.gamepad_cfg = ally_cfg; // Must asign before attr group setup
10721182
if (sysfs_create_groups(&hdev->dev.kobj, gamepad_device_attr_groups)) {

drivers/hid/hid-asus-ally.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ enum xpad_cmd {
2828
xpad_cmd_set_leds = 0x08,
2929
xpad_cmd_check_ready = 0x0A,
3030
xpad_cmd_set_turbo = 0x0F,
31+
xpad_cmd_set_adz = 0x18,
3132
};
3233

3334
/* the xpad_cmd determines which feature is set or queried */
@@ -38,6 +39,7 @@ enum xpad_cmd_len {
3839
xpad_cmd_len_vibe_intensity = 0x02,
3940
xpad_cmd_len_leds = 0x0C,
4041
xpad_cmd_len_turbo = 0x20,
42+
xpad_cmd_len_adz = 0x02,
4143
};
4244

4345
/* Values correspond to the actual HID byte value required */

0 commit comments

Comments
 (0)