ps4dshock.c (16079c7233be8bd6c88e3421a70c7ca87cfea370) ps4dshock.c (51b2216114546bb13b13002b29fb1263e600a0fc)
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2020 Vladimir Kondratyev <wulf@FreeBSD.org>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 36 unchanged lines hidden (view full) ---

45#include <sys/module.h>
46#include <sys/sx.h>
47#include <sys/sysctl.h>
48
49#include <dev/evdev/input.h>
50#include <dev/evdev/evdev.h>
51
52#define HID_DEBUG_VAR ps4dshock_debug
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2020 Vladimir Kondratyev <wulf@FreeBSD.org>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 36 unchanged lines hidden (view full) ---

45#include <sys/module.h>
46#include <sys/sx.h>
47#include <sys/sysctl.h>
48
49#include <dev/evdev/input.h>
50#include <dev/evdev/evdev.h>
51
52#define HID_DEBUG_VAR ps4dshock_debug
53#include <dev/hid/hgame.h>
53#include <dev/hid/hid.h>
54#include <dev/hid/hidbus.h>
55#include <dev/hid/hidquirk.h>
56#include <dev/hid/hidmap.h>
57#include "usbdevs.h"
58
59#ifdef HID_DEBUG
60static int ps4dshock_debug = 1;

--- 522 unchanged lines hidden (view full) ---

583
584#define PS4DS_GYRO_RES_PER_DEG_S 1024
585#define PS4DS_ACC_RES_PER_G 8192
586#define PS4DS_MAX_TOUCHPAD_PACKETS 4
587#define PS4DS_FEATURE_REPORT2_SIZE 37
588#define PS4DS_OUTPUT_REPORT5_SIZE 32
589#define PS4DS_OUTPUT_REPORT11_SIZE 78
590
54#include <dev/hid/hid.h>
55#include <dev/hid/hidbus.h>
56#include <dev/hid/hidquirk.h>
57#include <dev/hid/hidmap.h>
58#include "usbdevs.h"
59
60#ifdef HID_DEBUG
61static int ps4dshock_debug = 1;

--- 522 unchanged lines hidden (view full) ---

584
585#define PS4DS_GYRO_RES_PER_DEG_S 1024
586#define PS4DS_ACC_RES_PER_G 8192
587#define PS4DS_MAX_TOUCHPAD_PACKETS 4
588#define PS4DS_FEATURE_REPORT2_SIZE 37
589#define PS4DS_OUTPUT_REPORT5_SIZE 32
590#define PS4DS_OUTPUT_REPORT11_SIZE 78
591
591static hidmap_cb_t ps4dshock_hat_switch_cb;
592static hidmap_cb_t ps4dshock_final_cb;
593static hidmap_cb_t ps4dsacc_data_cb;
594static hidmap_cb_t ps4dsacc_tstamp_cb;
595static hidmap_cb_t ps4dsacc_final_cb;
596static hidmap_cb_t ps4dsmtp_data_cb;
597static hidmap_cb_t ps4dsmtp_npackets_cb;
598static hidmap_cb_t ps4dsmtp_final_cb;
599

--- 138 unchanged lines hidden (view full) ---

738 PS4DS_MAP_BTN(8, BTN_TR2),
739 PS4DS_MAP_BTN(9, BTN_SELECT),
740 PS4DS_MAP_BTN(10, BTN_START),
741 PS4DS_MAP_BTN(11, BTN_THUMBL),
742 PS4DS_MAP_BTN(12, BTN_THUMBR),
743 PS4DS_MAP_BTN(13, BTN_MODE),
744 /* Click button is handled by touchpad driver */
745 /* PS4DS_MAP_BTN(14, BTN_LEFT), */
592static hidmap_cb_t ps4dshock_final_cb;
593static hidmap_cb_t ps4dsacc_data_cb;
594static hidmap_cb_t ps4dsacc_tstamp_cb;
595static hidmap_cb_t ps4dsacc_final_cb;
596static hidmap_cb_t ps4dsmtp_data_cb;
597static hidmap_cb_t ps4dsmtp_npackets_cb;
598static hidmap_cb_t ps4dsmtp_final_cb;
599

--- 138 unchanged lines hidden (view full) ---

738 PS4DS_MAP_BTN(8, BTN_TR2),
739 PS4DS_MAP_BTN(9, BTN_SELECT),
740 PS4DS_MAP_BTN(10, BTN_START),
741 PS4DS_MAP_BTN(11, BTN_THUMBL),
742 PS4DS_MAP_BTN(12, BTN_THUMBR),
743 PS4DS_MAP_BTN(13, BTN_MODE),
744 /* Click button is handled by touchpad driver */
745 /* PS4DS_MAP_BTN(14, BTN_LEFT), */
746 PS4DS_MAP_GCB(HAT_SWITCH, ps4dshock_hat_switch_cb),
746 PS4DS_MAP_GCB(HAT_SWITCH, hgame_hat_switch_cb),
747 PS4DS_FINALCB( ps4dshock_final_cb),
748};
749static const struct hidmap_item ps4dsacc_map[] = {
750 PS4DS_MAP_GCB(X, ps4dsacc_data_cb),
751 PS4DS_MAP_GCB(Y, ps4dsacc_data_cb),
752 PS4DS_MAP_GCB(Z, ps4dsacc_data_cb),
753 PS4DS_MAP_GCB(RX, ps4dsacc_data_cb),
754 PS4DS_MAP_GCB(RY, ps4dsacc_data_cb),

--- 28 unchanged lines hidden (view full) ---

783 HID_TLC(HUP_CONSUMER, HUC_HEADPHONE) },
784};
785static const struct hid_device_id ps4dsmtp_devs[] = {
786 { HID_BVP(BUS_USB, USB_VENDOR_SONY, 0x9cc),
787 HID_TLC(HUP_DIGITIZERS, HUD_TOUCHPAD) },
788};
789
790static int
747 PS4DS_FINALCB( ps4dshock_final_cb),
748};
749static const struct hidmap_item ps4dsacc_map[] = {
750 PS4DS_MAP_GCB(X, ps4dsacc_data_cb),
751 PS4DS_MAP_GCB(Y, ps4dsacc_data_cb),
752 PS4DS_MAP_GCB(Z, ps4dsacc_data_cb),
753 PS4DS_MAP_GCB(RX, ps4dsacc_data_cb),
754 PS4DS_MAP_GCB(RY, ps4dsacc_data_cb),

--- 28 unchanged lines hidden (view full) ---

783 HID_TLC(HUP_CONSUMER, HUC_HEADPHONE) },
784};
785static const struct hid_device_id ps4dsmtp_devs[] = {
786 { HID_BVP(BUS_USB, USB_VENDOR_SONY, 0x9cc),
787 HID_TLC(HUP_DIGITIZERS, HUD_TOUCHPAD) },
788};
789
790static int
791ps4dshock_hat_switch_cb(HIDMAP_CB_ARGS)
792{
793 static const struct { int32_t x; int32_t y; } hat_switch_map[] = {
794 {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0},
795 {-1, -1},{0, 0}
796 };
797 struct evdev_dev *evdev = HIDMAP_CB_GET_EVDEV();
798 u_int idx;
799
800 switch (HIDMAP_CB_GET_STATE()) {
801 case HIDMAP_CB_IS_ATTACHING:
802 evdev_support_event(evdev, EV_ABS);
803 evdev_support_abs(evdev, ABS_HAT0X, -1, 1, 0, 0, 0);
804 evdev_support_abs(evdev, ABS_HAT0Y, -1, 1, 0, 0, 0);
805 break;
806
807 case HIDMAP_CB_IS_RUNNING:
808 idx = MIN(nitems(hat_switch_map) - 1, (u_int)ctx.data);
809 evdev_push_abs(evdev, ABS_HAT0X, hat_switch_map[idx].x);
810 evdev_push_abs(evdev, ABS_HAT0Y, hat_switch_map[idx].y);
811 break;
812
813 default:
814 break;
815 }
816
817 return (0);
818}
819
820static int
821ps4dshock_final_cb(HIDMAP_CB_ARGS)
822{
823 struct evdev_dev *evdev = HIDMAP_CB_GET_EVDEV();
824
825 if (HIDMAP_CB_GET_STATE() == HIDMAP_CB_IS_ATTACHING)
826 evdev_support_prop(evdev, INPUT_PROP_DIRECT);
827
828 /* Do not execute callback at interrupt handler and detach */

--- 580 unchanged lines hidden (view full) ---

1409DRIVER_MODULE(ps4dsmtp, hidbus, ps4dsmtp_driver, ps4dsmtp_devclass, NULL, 0);
1410DEFINE_CLASS_0(ps4dshock, ps4dshock_driver, ps4dshock_methods,
1411 sizeof(struct ps4dshock_softc));
1412DRIVER_MODULE(ps4dshock, hidbus, ps4dshock_driver, ps4dshock_devclass, NULL, 0);
1413
1414MODULE_DEPEND(ps4dshock, hid, 1, 1, 1);
1415MODULE_DEPEND(ps4dshock, hidbus, 1, 1, 1);
1416MODULE_DEPEND(ps4dshock, hidmap, 1, 1, 1);
791ps4dshock_final_cb(HIDMAP_CB_ARGS)
792{
793 struct evdev_dev *evdev = HIDMAP_CB_GET_EVDEV();
794
795 if (HIDMAP_CB_GET_STATE() == HIDMAP_CB_IS_ATTACHING)
796 evdev_support_prop(evdev, INPUT_PROP_DIRECT);
797
798 /* Do not execute callback at interrupt handler and detach */

--- 580 unchanged lines hidden (view full) ---

1379DRIVER_MODULE(ps4dsmtp, hidbus, ps4dsmtp_driver, ps4dsmtp_devclass, NULL, 0);
1380DEFINE_CLASS_0(ps4dshock, ps4dshock_driver, ps4dshock_methods,
1381 sizeof(struct ps4dshock_softc));
1382DRIVER_MODULE(ps4dshock, hidbus, ps4dshock_driver, ps4dshock_devclass, NULL, 0);
1383
1384MODULE_DEPEND(ps4dshock, hid, 1, 1, 1);
1385MODULE_DEPEND(ps4dshock, hidbus, 1, 1, 1);
1386MODULE_DEPEND(ps4dshock, hidmap, 1, 1, 1);
1387MODULE_DEPEND(ps4dshock, hgame, 1, 1, 1);
1417MODULE_DEPEND(ps4dshock, evdev, 1, 1, 1);
1418MODULE_VERSION(ps4dshock, 1);
1419HID_PNP_INFO(ps4dshock_devs);
1388MODULE_DEPEND(ps4dshock, evdev, 1, 1, 1);
1389MODULE_VERSION(ps4dshock, 1);
1390HID_PNP_INFO(ps4dshock_devs);