Lines Matching +full:3 +full:- +full:axis +full:- +full:digital +full:- +full:gyroscope
1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
7 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
10 * Copyright (c) 2006-2013 Jiri Kosina
12 * Copyright (c) 2014-2016 Frank Praznik <frank.praznik@gmail.com>
14 * Copyright (c) 2020-2021 Pascal Giard <pascal.giard@etsmtl.ca>
45 #include "hid-ids.h"
50 #define BUZZ_CONTROLLER BIT(3)
111 /* PS/3 Motion controller */
150 0x95, 0x03, /* Report Count (3), * 3x Accels */
156 0x95, 0x03, /* Report Count (3), * Skip Accels 2nd frame */
160 0x95, 0x03, /* Report Count (3), * 3x Gyros */
163 0x95, 0x03, /* Report Count (3), * Skip Gyros 2nd frame */
338 * -------------------
342 * Green 3
350 [3] = BTN_TRIGGER_HAPPY3,
372 * are physically present. We use the same axis and button mapping as
457 {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1},
489 struct sixaxis_led led[4]; /* LEDx at (4 - x) */
624 spin_lock_irqsave(&sc->lock, flags); in sony_schedule_work()
625 if (!sc->defer_initialization && sc->state_worker_initialized) in sony_schedule_work()
626 schedule_work(&sc->state_worker); in sony_schedule_work()
627 spin_unlock_irqrestore(&sc->lock, flags); in sony_schedule_work()
630 if (sc->hotplug_worker_initialized) in sony_schedule_work()
631 schedule_work(&sc->hotplug_worker); in sony_schedule_work()
638 struct sony_sc *sc = urb->context; in ghl_magic_poke_cb()
640 if (urb->status < 0) in ghl_magic_poke_cb()
641 hid_err(sc->hdev, "URB transfer failed : %d", urb->status); in ghl_magic_poke_cb()
643 mod_timer(&sc->ghl_poke_timer, jiffies + GHL_GUITAR_POKE_INTERVAL*HZ); in ghl_magic_poke_cb()
651 ret = usb_submit_urb(sc->ghl_urb, GFP_ATOMIC); in ghl_magic_poke()
653 hid_err(sc->hdev, "usb_submit_urb failed: %d", ret); in ghl_magic_poke()
666 cr = devm_kzalloc(&sc->hdev->dev, sizeof(*cr), GFP_ATOMIC); in ghl_init_urb()
668 return -ENOMEM; in ghl_init_urb()
670 databuf = devm_kzalloc(&sc->hdev->dev, poke_size, GFP_ATOMIC); in ghl_init_urb()
672 return -ENOMEM; in ghl_init_urb()
674 cr->bRequestType = in ghl_init_urb()
676 cr->bRequest = USB_REQ_SET_CONFIGURATION; in ghl_init_urb()
677 cr->wValue = cpu_to_le16(ghl_magic_value); in ghl_init_urb()
678 cr->wIndex = 0; in ghl_init_urb()
679 cr->wLength = cpu_to_le16(poke_size); in ghl_init_urb()
682 sc->ghl_urb, usbdev, pipe, in ghl_init_urb()
692 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR) { in guitar_mapping()
693 unsigned int abs = usage->hid & HID_USAGE; in guitar_mapping()
710 return snprintf(buf, PAGE_SIZE, "%i\n", sc->ds4_bt_poll_interval); in ds4_show_poll_interval()
723 return -EINVAL; in ds4_store_poll_interval()
726 return -EINVAL; in ds4_store_poll_interval()
728 spin_lock_irqsave(&sc->lock, flags); in ds4_store_poll_interval()
729 sc->ds4_bt_poll_interval = interval; in ds4_store_poll_interval()
730 spin_unlock_irqrestore(&sc->lock, flags); in ds4_store_poll_interval()
747 return snprintf(buf, PAGE_SIZE, "0x%04x\n", sc->fw_version); in sony_show_firmware_version()
759 return snprintf(buf, PAGE_SIZE, "0x%04x\n", sc->hw_version); in sony_show_hardware_version()
782 unsigned int key = usage->hid & HID_USAGE; in ps3remote_mapping()
784 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) in ps3remote_mapping()
785 return -1; in ps3remote_mapping()
787 switch (usage->collection_index) { in ps3remote_mapping()
790 return -1; in ps3remote_mapping()
794 return -1; in ps3remote_mapping()
798 return -1; in ps3remote_mapping()
802 return -1; in ps3remote_mapping()
805 return -1; in ps3remote_mapping()
816 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) { in navigation_mapping()
817 unsigned int key = usage->hid & HID_USAGE; in navigation_mapping()
820 return -1; in navigation_mapping()
824 return -1; in navigation_mapping()
828 } else if (usage->hid == HID_GD_POINTER) { in navigation_mapping()
832 * support digital buttons. in navigation_mapping()
834 switch (usage->usage_index) { in navigation_mapping()
836 usage->hid = HID_GD_Z; in navigation_mapping()
839 return -1; in navigation_mapping()
842 hid_map_usage_clear(hi, usage, bit, max, EV_ABS, usage->hid & 0xf); in navigation_mapping()
844 } else if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK) { in navigation_mapping()
845 unsigned int abs = usage->hid & HID_USAGE; in navigation_mapping()
848 return -1; in navigation_mapping()
856 return -1; in navigation_mapping()
864 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) { in sixaxis_mapping()
865 unsigned int key = usage->hid & HID_USAGE; in sixaxis_mapping()
868 return -1; in sixaxis_mapping()
873 } else if (usage->hid == HID_GD_POINTER) { in sixaxis_mapping()
880 switch (usage->usage_index) { in sixaxis_mapping()
882 usage->hid = HID_GD_Z; in sixaxis_mapping()
885 usage->hid = HID_GD_RZ; in sixaxis_mapping()
888 return -1; in sixaxis_mapping()
891 hid_map_usage_clear(hi, usage, bit, max, EV_ABS, usage->hid & 0xf); in sixaxis_mapping()
893 } else if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK) { in sixaxis_mapping()
894 unsigned int abs = usage->hid & HID_USAGE; in sixaxis_mapping()
897 return -1; in sixaxis_mapping()
905 return -1; in sixaxis_mapping()
912 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) { in ds4_mapping()
913 unsigned int key = usage->hid & HID_USAGE; in ds4_mapping()
916 return -1; in ds4_mapping()
921 } else if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK) { in ds4_mapping()
922 unsigned int abs = usage->hid & HID_USAGE; in ds4_mapping()
925 if (usage->hid == HID_GD_HATSWITCH) in ds4_mapping()
929 return -1; in ds4_mapping()
944 if (sc->quirks & (SINO_LITE_CONTROLLER | FUTUREMAX_DANCE_MAT)) in sony_report_fixup()
949 * a constant non-data variable. in sony_report_fixup()
951 if ((sc->quirks & VAIO_RDESC_CONSTANT) && *rsize >= 56 && in sony_report_fixup()
955 rdesc[2] == 0x09 && rdesc[3] == 0x02 && in sony_report_fixup()
963 if (sc->quirks & MOTION_CONTROLLER) in sony_report_fixup()
966 if (sc->quirks & PS3REMOTE) in sony_report_fixup()
970 * Some knock-off USB dongles incorrectly report their button count in sony_report_fixup()
971 * as 13 instead of 16 causing three non-functional buttons. in sony_report_fixup()
973 if ((sc->quirks & SIXAXIS_CONTROLLER_USB) && *rsize >= 45 && in sony_report_fixup()
978 /* Report Count (3) */ in sony_report_fixup()
1003 offset = (sc->quirks & MOTION_CONTROLLER) ? 12 : 30; in sixaxis_parse_report()
1014 spin_lock_irqsave(&sc->lock, flags); in sixaxis_parse_report()
1015 sc->battery_capacity = battery_capacity; in sixaxis_parse_report()
1016 sc->battery_status = battery_status; in sixaxis_parse_report()
1017 spin_unlock_irqrestore(&sc->lock, flags); in sixaxis_parse_report()
1019 if (sc->quirks & SIXAXIS_CONTROLLER) { in sixaxis_parse_report()
1023 val = ((rd[offset+1] << 8) | rd[offset]) - 511; in sixaxis_parse_report()
1024 input_report_abs(sc->sensor_dev, ABS_X, val); in sixaxis_parse_report()
1027 val = 511 - ((rd[offset+5] << 8) | rd[offset+4]); in sixaxis_parse_report()
1028 input_report_abs(sc->sensor_dev, ABS_Y, val); in sixaxis_parse_report()
1030 val = 511 - ((rd[offset+3] << 8) | rd[offset+2]); in sixaxis_parse_report()
1031 input_report_abs(sc->sensor_dev, ABS_Z, val); in sixaxis_parse_report()
1033 input_sync(sc->sensor_dev); in sixaxis_parse_report()
1039 struct hid_input *hidinput = list_entry(sc->hdev->inputs.next, in dualshock4_parse_report()
1041 struct input_dev *input_dev = hidinput->input; in dualshock4_parse_report()
1049 int data_offset = (sc->quirks & DUALSHOCK4_CONTROLLER_BT) ? 2 : 0; in dualshock4_parse_report()
1053 input_report_key(sc->touchpad, BTN_LEFT, rd[offset+2] & 0x2); in dualshock4_parse_report()
1076 input_report_abs(input_dev, ABS_RY, rd[offset+3]); in dualshock4_parse_report()
1109 if (!sc->timestamp_initialized) { in dualshock4_parse_report()
1110 sc->timestamp_us = ((unsigned int)timestamp * 16) / 3; in dualshock4_parse_report()
1111 sc->timestamp_initialized = true; in dualshock4_parse_report()
1115 if (sc->prev_timestamp > timestamp) in dualshock4_parse_report()
1116 delta = (U16_MAX - sc->prev_timestamp + timestamp + 1); in dualshock4_parse_report()
1118 delta = timestamp - sc->prev_timestamp; in dualshock4_parse_report()
1119 sc->timestamp_us += (delta * 16) / 3; in dualshock4_parse_report()
1121 sc->prev_timestamp = timestamp; in dualshock4_parse_report()
1122 input_event(sc->sensor_dev, EV_MSC, MSC_TIMESTAMP, sc->timestamp_us); in dualshock4_parse_report()
1128 struct ds4_calibration_data *calib = &sc->ds4_calib_data[n]; in dualshock4_parse_report()
1131 * calibrated values are within 32-bit. in dualshock4_parse_report()
1133 * precision reasons so we don't need 64-bit. in dualshock4_parse_report()
1135 int calib_data = mult_frac(calib->sens_numer, in dualshock4_parse_report()
1136 raw_data - calib->bias, in dualshock4_parse_report()
1137 calib->sens_denom); in dualshock4_parse_report()
1139 input_report_abs(sc->sensor_dev, calib->abs_code, calib_data); in dualshock4_parse_report()
1142 input_sync(sc->sensor_dev); in dualshock4_parse_report()
1154 * - 0:10: percentage in units of 10%. in dualshock4_parse_report()
1156 * - 0-10: percentage in units of 10%. in dualshock4_parse_report()
1157 * - 11: battery is full in dualshock4_parse_report()
1158 * - 14: not charging due to Voltage or temperature error in dualshock4_parse_report()
1159 * - 15: charge error in dualshock4_parse_report()
1165 /* Take the mid-point for each battery capacity value, in dualshock4_parse_report()
1166 * because on the hardware side 0 = 0-9%, 1=10-19%, etc. in dualshock4_parse_report()
1193 spin_lock_irqsave(&sc->lock, flags); in dualshock4_parse_report()
1194 sc->battery_capacity = battery_capacity; in dualshock4_parse_report()
1195 sc->battery_status = battery_status; in dualshock4_parse_report()
1196 spin_unlock_irqrestore(&sc->lock, flags); in dualshock4_parse_report()
1199 * The Dualshock 4 multi-touch trackpad data starts at offset 33 on USB in dualshock4_parse_report()
1205 max_touch_data = (sc->quirks & DUALSHOCK4_CONTROLLER_BT) ? 4 : 3; in dualshock4_parse_report()
1220 * The next 3 bytes are two 12 bit touch coordinates, X and Y. in dualshock4_parse_report()
1229 y = ((rd[offset+2] & 0xF0) >> 4) | (rd[offset+3] << 4); in dualshock4_parse_report()
1232 input_mt_slot(sc->touchpad, n); in dualshock4_parse_report()
1233 input_mt_report_slot_state(sc->touchpad, MT_TOOL_FINGER, active); in dualshock4_parse_report()
1236 input_report_abs(sc->touchpad, ABS_MT_POSITION_X, x); in dualshock4_parse_report()
1237 input_report_abs(sc->touchpad, ABS_MT_POSITION_Y, y); in dualshock4_parse_report()
1242 input_mt_sync_frame(sc->touchpad); in dualshock4_parse_report()
1243 input_sync(sc->touchpad); in dualshock4_parse_report()
1253 * The NSG-MRxU multi-touch trackpad data starts at offset 1 and in nsg_mrxu_parse_report()
1254 * the touch-related data starts at offset 2. in nsg_mrxu_parse_report()
1262 * The next 3 bytes are two 12 bit X/Y coordinates for the first touch. in nsg_mrxu_parse_report()
1264 * Bits 0-4=X (width), bits 5-7=Y (length). in nsg_mrxu_parse_report()
1266 * The bytes at offset 7-9 are the second touch X/Y coordinates. in nsg_mrxu_parse_report()
1272 input_report_key(sc->touchpad, BTN_LEFT, rd[offset] & 0x0F); in nsg_mrxu_parse_report()
1275 rely = ((s8) rd[offset+10]) * -1; in nsg_mrxu_parse_report()
1286 input_mt_slot(sc->touchpad, n); in nsg_mrxu_parse_report()
1287 input_mt_report_slot_state(sc->touchpad, MT_TOOL_FINGER, active & 0x03); in nsg_mrxu_parse_report()
1290 contactx = rd[offset+3] & 0x0F; in nsg_mrxu_parse_report()
1291 contacty = rd[offset+3] >> 4; in nsg_mrxu_parse_report()
1292 input_report_abs(sc->touchpad, ABS_MT_TOUCH_MAJOR, in nsg_mrxu_parse_report()
1294 input_report_abs(sc->touchpad, ABS_MT_TOUCH_MINOR, in nsg_mrxu_parse_report()
1296 input_report_abs(sc->touchpad, ABS_MT_ORIENTATION, in nsg_mrxu_parse_report()
1298 input_report_abs(sc->touchpad, ABS_MT_POSITION_X, x); in nsg_mrxu_parse_report()
1299 input_report_abs(sc->touchpad, ABS_MT_POSITION_Y, in nsg_mrxu_parse_report()
1300 NSG_MRXU_MAX_Y - y); in nsg_mrxu_parse_report()
1307 input_report_rel(sc->touchpad, REL_X, relx); in nsg_mrxu_parse_report()
1308 input_report_rel(sc->touchpad, REL_Y, rely); in nsg_mrxu_parse_report()
1316 input_mt_sync_frame(sc->touchpad); in nsg_mrxu_parse_report()
1318 input_sync(sc->touchpad); in nsg_mrxu_parse_report()
1330 if ((sc->quirks & SIXAXIS_CONTROLLER) && rd[0] == 0x01 && size == 49) { in sony_raw_event()
1340 return -EINVAL; in sony_raw_event()
1348 } else if ((sc->quirks & MOTION_CONTROLLER_BT) && rd[0] == 0x01 && size == 49) { in sony_raw_event()
1350 } else if ((sc->quirks & NAVIGATION_CONTROLLER) && rd[0] == 0x01 && in sony_raw_event()
1353 } else if ((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && rd[0] == 0x01 && in sony_raw_event()
1356 } else if (((sc->quirks & DUALSHOCK4_CONTROLLER_BT) && rd[0] == 0x11 && in sony_raw_event()
1364 crc = ~crc32_le(crc, rd, DS4_INPUT_REPORT_0x11_SIZE-4); in sony_raw_event()
1365 report_crc = get_unaligned_le32(&rd[DS4_INPUT_REPORT_0x11_SIZE-4]); in sony_raw_event()
1367 hid_dbg(sc->hdev, "DualShock 4 input report's CRC check failed, received crc 0x%0x != 0x%0x\n", in sony_raw_event()
1369 return -EILSEQ; in sony_raw_event()
1373 } else if ((sc->quirks & DUALSHOCK4_DONGLE) && rd[0] == 0x01 && in sony_raw_event()
1381 * For non-dongle, this bit is always 0 (connected). in sony_raw_event()
1385 spin_lock_irqsave(&sc->lock, flags); in sony_raw_event()
1386 dongle_state = sc->ds4_dongle_state; in sony_raw_event()
1387 spin_unlock_irqrestore(&sc->lock, flags); in sony_raw_event()
1398 hid_info(sc->hdev, "DualShock 4 USB dongle: controller connected\n"); in sony_raw_event()
1401 spin_lock_irqsave(&sc->lock, flags); in sony_raw_event()
1402 sc->ds4_dongle_state = DONGLE_CALIBRATING; in sony_raw_event()
1403 spin_unlock_irqrestore(&sc->lock, flags); in sony_raw_event()
1413 hid_info(sc->hdev, "DualShock 4 USB dongle: controller disconnected\n"); in sony_raw_event()
1415 spin_lock_irqsave(&sc->lock, flags); in sony_raw_event()
1416 sc->ds4_dongle_state = DONGLE_DISCONNECTED; in sony_raw_event()
1417 spin_unlock_irqrestore(&sc->lock, flags); in sony_raw_event()
1430 } else if ((sc->quirks & NSG_MRXU_REMOTE) && rd[0] == 0x02) { in sony_raw_event()
1435 if (sc->defer_initialization) { in sony_raw_event()
1436 sc->defer_initialization = 0; in sony_raw_event()
1449 if (sc->quirks & BUZZ_CONTROLLER) { in sony_mapping()
1450 unsigned int key = usage->hid & HID_USAGE; in sony_mapping()
1452 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) in sony_mapping()
1453 return -1; in sony_mapping()
1455 switch (usage->collection_index) { in sony_mapping()
1458 return -1; in sony_mapping()
1462 return -1; in sony_mapping()
1465 return -1; in sony_mapping()
1472 if (sc->quirks & PS3REMOTE) in sony_mapping()
1475 if (sc->quirks & NAVIGATION_CONTROLLER) in sony_mapping()
1478 if (sc->quirks & SIXAXIS_CONTROLLER) in sony_mapping()
1481 if (sc->quirks & DUALSHOCK4_CONTROLLER) in sony_mapping()
1484 if (sc->quirks & GH_GUITAR_CONTROLLER) in sony_mapping()
1487 /* Let hid-core decide for the others */ in sony_mapping()
1498 sc->touchpad = devm_input_allocate_device(&sc->hdev->dev); in sony_register_touchpad()
1499 if (!sc->touchpad) in sony_register_touchpad()
1500 return -ENOMEM; in sony_register_touchpad()
1502 input_set_drvdata(sc->touchpad, sc); in sony_register_touchpad()
1503 sc->touchpad->dev.parent = &sc->hdev->dev; in sony_register_touchpad()
1504 sc->touchpad->phys = sc->hdev->phys; in sony_register_touchpad()
1505 sc->touchpad->uniq = sc->hdev->uniq; in sony_register_touchpad()
1506 sc->touchpad->id.bustype = sc->hdev->bus; in sony_register_touchpad()
1507 sc->touchpad->id.vendor = sc->hdev->vendor; in sony_register_touchpad()
1508 sc->touchpad->id.product = sc->hdev->product; in sony_register_touchpad()
1509 sc->touchpad->id.version = sc->hdev->version; in sony_register_touchpad()
1512 * DS4 compatible non-Sony devices with different names. in sony_register_touchpad()
1514 name_sz = strlen(sc->hdev->name) + sizeof(DS4_TOUCHPAD_SUFFIX); in sony_register_touchpad()
1515 name = devm_kzalloc(&sc->hdev->dev, name_sz, GFP_KERNEL); in sony_register_touchpad()
1517 return -ENOMEM; in sony_register_touchpad()
1518 snprintf(name, name_sz, "%s" DS4_TOUCHPAD_SUFFIX, sc->hdev->name); in sony_register_touchpad()
1519 sc->touchpad->name = name; in sony_register_touchpad()
1522 __set_bit(EV_KEY, sc->touchpad->evbit); in sony_register_touchpad()
1523 __set_bit(BTN_LEFT, sc->touchpad->keybit); in sony_register_touchpad()
1524 __set_bit(INPUT_PROP_BUTTONPAD, sc->touchpad->propbit); in sony_register_touchpad()
1526 input_set_abs_params(sc->touchpad, ABS_MT_POSITION_X, 0, w, 0, 0); in sony_register_touchpad()
1527 input_set_abs_params(sc->touchpad, ABS_MT_POSITION_Y, 0, h, 0, 0); in sony_register_touchpad()
1530 input_set_abs_params(sc->touchpad, ABS_MT_TOUCH_MAJOR, in sony_register_touchpad()
1533 input_set_abs_params(sc->touchpad, ABS_MT_TOUCH_MINOR, in sony_register_touchpad()
1536 input_set_abs_params(sc->touchpad, ABS_MT_ORIENTATION, in sony_register_touchpad()
1540 if (sc->quirks & NSG_MRXU_REMOTE) { in sony_register_touchpad()
1541 __set_bit(EV_REL, sc->touchpad->evbit); in sony_register_touchpad()
1544 ret = input_mt_init_slots(sc->touchpad, touch_count, INPUT_MT_POINTER); in sony_register_touchpad()
1548 ret = input_register_device(sc->touchpad); in sony_register_touchpad()
1562 sc->sensor_dev = devm_input_allocate_device(&sc->hdev->dev); in sony_register_sensors()
1563 if (!sc->sensor_dev) in sony_register_sensors()
1564 return -ENOMEM; in sony_register_sensors()
1566 input_set_drvdata(sc->sensor_dev, sc); in sony_register_sensors()
1567 sc->sensor_dev->dev.parent = &sc->hdev->dev; in sony_register_sensors()
1568 sc->sensor_dev->phys = sc->hdev->phys; in sony_register_sensors()
1569 sc->sensor_dev->uniq = sc->hdev->uniq; in sony_register_sensors()
1570 sc->sensor_dev->id.bustype = sc->hdev->bus; in sony_register_sensors()
1571 sc->sensor_dev->id.vendor = sc->hdev->vendor; in sony_register_sensors()
1572 sc->sensor_dev->id.product = sc->hdev->product; in sony_register_sensors()
1573 sc->sensor_dev->id.version = sc->hdev->version; in sony_register_sensors()
1576 * DS4 compatible non-Sony devices with different names. in sony_register_sensors()
1578 name_sz = strlen(sc->hdev->name) + sizeof(SENSOR_SUFFIX); in sony_register_sensors()
1579 name = devm_kzalloc(&sc->hdev->dev, name_sz, GFP_KERNEL); in sony_register_sensors()
1581 return -ENOMEM; in sony_register_sensors()
1582 snprintf(name, name_sz, "%s" SENSOR_SUFFIX, sc->hdev->name); in sony_register_sensors()
1583 sc->sensor_dev->name = name; in sony_register_sensors()
1585 if (sc->quirks & SIXAXIS_CONTROLLER) { in sony_register_sensors()
1588 * a 1-axis gyro, but it is very difficult to manage from within in sony_register_sensors()
1592 input_set_abs_params(sc->sensor_dev, ABS_X, -512, 511, 4, 0); in sony_register_sensors()
1593 input_set_abs_params(sc->sensor_dev, ABS_Y, -512, 511, 4, 0); in sony_register_sensors()
1594 input_set_abs_params(sc->sensor_dev, ABS_Z, -512, 511, 4, 0); in sony_register_sensors()
1595 input_abs_set_res(sc->sensor_dev, ABS_X, SIXAXIS_ACC_RES_PER_G); in sony_register_sensors()
1596 input_abs_set_res(sc->sensor_dev, ABS_Y, SIXAXIS_ACC_RES_PER_G); in sony_register_sensors()
1597 input_abs_set_res(sc->sensor_dev, ABS_Z, SIXAXIS_ACC_RES_PER_G); in sony_register_sensors()
1598 } else if (sc->quirks & DUALSHOCK4_CONTROLLER) { in sony_register_sensors()
1600 input_set_abs_params(sc->sensor_dev, ABS_X, -range, range, 16, 0); in sony_register_sensors()
1601 input_set_abs_params(sc->sensor_dev, ABS_Y, -range, range, 16, 0); in sony_register_sensors()
1602 input_set_abs_params(sc->sensor_dev, ABS_Z, -range, range, 16, 0); in sony_register_sensors()
1603 input_abs_set_res(sc->sensor_dev, ABS_X, DS4_ACC_RES_PER_G); in sony_register_sensors()
1604 input_abs_set_res(sc->sensor_dev, ABS_Y, DS4_ACC_RES_PER_G); in sony_register_sensors()
1605 input_abs_set_res(sc->sensor_dev, ABS_Z, DS4_ACC_RES_PER_G); in sony_register_sensors()
1608 input_set_abs_params(sc->sensor_dev, ABS_RX, -range, range, 16, 0); in sony_register_sensors()
1609 input_set_abs_params(sc->sensor_dev, ABS_RY, -range, range, 16, 0); in sony_register_sensors()
1610 input_set_abs_params(sc->sensor_dev, ABS_RZ, -range, range, 16, 0); in sony_register_sensors()
1611 input_abs_set_res(sc->sensor_dev, ABS_RX, DS4_GYRO_RES_PER_DEG_S); in sony_register_sensors()
1612 input_abs_set_res(sc->sensor_dev, ABS_RY, DS4_GYRO_RES_PER_DEG_S); in sony_register_sensors()
1613 input_abs_set_res(sc->sensor_dev, ABS_RZ, DS4_GYRO_RES_PER_DEG_S); in sony_register_sensors()
1615 __set_bit(EV_MSC, sc->sensor_dev->evbit); in sony_register_sensors()
1616 __set_bit(MSC_TIMESTAMP, sc->sensor_dev->mscbit); in sony_register_sensors()
1619 __set_bit(INPUT_PROP_ACCELEROMETER, sc->sensor_dev->propbit); in sony_register_sensors()
1621 ret = input_register_device(sc->sensor_dev); in sony_register_sensors()
1643 return -ENOMEM; in sixaxis_set_operational_usb()
1665 * start rumbling non-stop, so skip step 3 for these controllers. in sixaxis_set_operational_usb()
1667 if (sc->quirks & SHANWAN_GAMEPAD) in sixaxis_set_operational_usb()
1672 hid_info(hdev, "can't set operational mode: step 3, ignoring\n"); in sixaxis_set_operational_usb()
1690 return -ENOMEM; in sixaxis_set_operational_bt()
1722 if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE)) { in dualshock4_get_calibration_data()
1727 return -ENOMEM; in dualshock4_get_calibration_data()
1735 for (retries = 0; retries < 3; retries++) { in dualshock4_get_calibration_data()
1736 ret = hid_hw_raw_request(sc->hdev, 0x02, buf, in dualshock4_get_calibration_data()
1745 hid_warn(sc->hdev, "Retrying DualShock 4 get calibration report (0x02) request\n"); in dualshock4_get_calibration_data()
1748 ret = -EILSEQ; in dualshock4_get_calibration_data()
1763 return -ENOMEM; in dualshock4_get_calibration_data()
1765 for (retries = 0; retries < 3; retries++) { in dualshock4_get_calibration_data()
1766 ret = hid_hw_raw_request(sc->hdev, 0x05, buf, in dualshock4_get_calibration_data()
1775 crc = ~crc32_le(crc, buf, DS4_FEATURE_REPORT_0x05_SIZE-4); in dualshock4_get_calibration_data()
1776 report_crc = get_unaligned_le32(&buf[DS4_FEATURE_REPORT_0x05_SIZE-4]); in dualshock4_get_calibration_data()
1778 …hid_warn(sc->hdev, "DualShock 4 calibration report's CRC check failed, received crc 0x%0x != 0x%0x… in dualshock4_get_calibration_data()
1781 hid_warn(sc->hdev, "Retrying DualShock 4 get calibration report request\n"); in dualshock4_get_calibration_data()
1784 ret = -EILSEQ; in dualshock4_get_calibration_data()
1794 gyro_yaw_bias = get_unaligned_le16(&buf[3]); in dualshock4_get_calibration_data()
1796 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) { in dualshock4_get_calibration_data()
1821 /* Set gyroscope calibration and normalization parameters. in dualshock4_get_calibration_data()
1825 sc->ds4_calib_data[0].abs_code = ABS_RX; in dualshock4_get_calibration_data()
1826 sc->ds4_calib_data[0].bias = gyro_pitch_bias; in dualshock4_get_calibration_data()
1827 sc->ds4_calib_data[0].sens_numer = speed_2x*DS4_GYRO_RES_PER_DEG_S; in dualshock4_get_calibration_data()
1828 sc->ds4_calib_data[0].sens_denom = gyro_pitch_plus - gyro_pitch_minus; in dualshock4_get_calibration_data()
1830 sc->ds4_calib_data[1].abs_code = ABS_RY; in dualshock4_get_calibration_data()
1831 sc->ds4_calib_data[1].bias = gyro_yaw_bias; in dualshock4_get_calibration_data()
1832 sc->ds4_calib_data[1].sens_numer = speed_2x*DS4_GYRO_RES_PER_DEG_S; in dualshock4_get_calibration_data()
1833 sc->ds4_calib_data[1].sens_denom = gyro_yaw_plus - gyro_yaw_minus; in dualshock4_get_calibration_data()
1835 sc->ds4_calib_data[2].abs_code = ABS_RZ; in dualshock4_get_calibration_data()
1836 sc->ds4_calib_data[2].bias = gyro_roll_bias; in dualshock4_get_calibration_data()
1837 sc->ds4_calib_data[2].sens_numer = speed_2x*DS4_GYRO_RES_PER_DEG_S; in dualshock4_get_calibration_data()
1838 sc->ds4_calib_data[2].sens_denom = gyro_roll_plus - gyro_roll_minus; in dualshock4_get_calibration_data()
1843 range_2g = acc_x_plus - acc_x_minus; in dualshock4_get_calibration_data()
1844 sc->ds4_calib_data[3].abs_code = ABS_X; in dualshock4_get_calibration_data()
1845 sc->ds4_calib_data[3].bias = acc_x_plus - range_2g / 2; in dualshock4_get_calibration_data()
1846 sc->ds4_calib_data[3].sens_numer = 2*DS4_ACC_RES_PER_G; in dualshock4_get_calibration_data()
1847 sc->ds4_calib_data[3].sens_denom = range_2g; in dualshock4_get_calibration_data()
1849 range_2g = acc_y_plus - acc_y_minus; in dualshock4_get_calibration_data()
1850 sc->ds4_calib_data[4].abs_code = ABS_Y; in dualshock4_get_calibration_data()
1851 sc->ds4_calib_data[4].bias = acc_y_plus - range_2g / 2; in dualshock4_get_calibration_data()
1852 sc->ds4_calib_data[4].sens_numer = 2*DS4_ACC_RES_PER_G; in dualshock4_get_calibration_data()
1853 sc->ds4_calib_data[4].sens_denom = range_2g; in dualshock4_get_calibration_data()
1855 range_2g = acc_z_plus - acc_z_minus; in dualshock4_get_calibration_data()
1856 sc->ds4_calib_data[5].abs_code = ABS_Z; in dualshock4_get_calibration_data()
1857 sc->ds4_calib_data[5].bias = acc_z_plus - range_2g / 2; in dualshock4_get_calibration_data()
1858 sc->ds4_calib_data[5].sens_numer = 2*DS4_ACC_RES_PER_G; in dualshock4_get_calibration_data()
1859 sc->ds4_calib_data[5].sens_denom = range_2g; in dualshock4_get_calibration_data()
1877 * dongle as disabled. We will re-enable the dongle if a new in dualshock4_calibration_work()
1881 hid_err(sc->hdev, "DualShock 4 USB dongle: calibration failed, disabling device\n"); in dualshock4_calibration_work()
1884 hid_info(sc->hdev, "DualShock 4 USB dongle: calibration completed\n"); in dualshock4_calibration_work()
1888 spin_lock_irqsave(&sc->lock, flags); in dualshock4_calibration_work()
1889 sc->ds4_dongle_state = dongle_state; in dualshock4_calibration_work()
1890 spin_unlock_irqrestore(&sc->lock, flags); in dualshock4_calibration_work()
1900 return -ENOMEM; in dualshock4_get_version_info()
1902 ret = hid_hw_raw_request(sc->hdev, 0xA3, buf, in dualshock4_get_version_info()
1911 sc->hw_version = get_unaligned_le16(&buf[35]); in dualshock4_get_version_info()
1912 sc->fw_version = get_unaligned_le16(&buf[41]); in dualshock4_get_version_info()
1933 int id = sc->device_id; in sixaxis_set_leds_from_id()
1941 memcpy(sc->led_state, sixaxis_leds[id], sizeof(sixaxis_leds[id])); in sixaxis_set_leds_from_id()
1947 static const u8 color_code[7][3] = { in dualshock4_set_leds_from_id()
1957 int id = sc->device_id; in dualshock4_set_leds_from_id()
1965 memcpy(sc->led_state, color_code[id], sizeof(color_code[id])); in dualshock4_set_leds_from_id()
1970 struct hid_device *hdev = sc->hdev; in buzz_set_leds()
1972 &hdev->report_enum[HID_OUTPUT_REPORT].report_list; in buzz_set_leds()
1973 struct hid_report *report = list_entry(report_list->next, in buzz_set_leds()
1975 s32 *value = report->field[0]->value; in buzz_set_leds()
1980 value[1] = sc->led_state[0] ? 0xff : 0x00; in buzz_set_leds()
1981 value[2] = sc->led_state[1] ? 0xff : 0x00; in buzz_set_leds()
1982 value[3] = sc->led_state[2] ? 0xff : 0x00; in buzz_set_leds()
1983 value[4] = sc->led_state[3] ? 0xff : 0x00; in buzz_set_leds()
1991 if (!(sc->quirks & BUZZ_CONTROLLER)) in sony_set_leds()
2000 struct device *dev = led->dev->parent; in sony_led_set_brightness()
2020 force_update = !!(drv_data->quirks & SIXAXIS_CONTROLLER_USB); in sony_led_set_brightness()
2022 for (n = 0; n < drv_data->led_count; n++) { in sony_led_set_brightness()
2023 if (led == drv_data->leds[n] && (force_update || in sony_led_set_brightness()
2024 (value != drv_data->led_state[n] || in sony_led_set_brightness()
2025 drv_data->led_delay_on[n] || in sony_led_set_brightness()
2026 drv_data->led_delay_off[n]))) { in sony_led_set_brightness()
2028 drv_data->led_state[n] = value; in sony_led_set_brightness()
2031 drv_data->led_delay_on[n] = 0; in sony_led_set_brightness()
2032 drv_data->led_delay_off[n] = 0; in sony_led_set_brightness()
2042 struct device *dev = led->dev->parent; in sony_led_get_brightness()
2054 for (n = 0; n < drv_data->led_count; n++) { in sony_led_get_brightness()
2055 if (led == drv_data->leds[n]) in sony_led_get_brightness()
2056 return drv_data->led_state[n]; in sony_led_get_brightness()
2065 struct device *dev = led->dev->parent; in sony_led_blink_set()
2073 return -EINVAL; in sony_led_blink_set()
2089 for (n = 0; n < drv_data->led_count; n++) { in sony_led_blink_set()
2090 if (led == drv_data->leds[n]) in sony_led_blink_set()
2095 if (n >= drv_data->led_count) in sony_led_blink_set()
2096 return -EINVAL; in sony_led_blink_set()
2099 if (new_on != drv_data->led_delay_on[n] || in sony_led_blink_set()
2100 new_off != drv_data->led_delay_off[n]) { in sony_led_blink_set()
2101 drv_data->led_delay_on[n] = new_on; in sony_led_blink_set()
2102 drv_data->led_delay_off[n] = new_off; in sony_led_blink_set()
2111 struct hid_device *hdev = sc->hdev; in sony_leds_init()
2121 u8 max_brightness[MAX_LEDS] = { [0 ... (MAX_LEDS - 1)] = 1 }; in sony_leds_init()
2124 BUG_ON(!(sc->quirks & SONY_LED_SUPPORT)); in sony_leds_init()
2126 if (sc->quirks & BUZZ_CONTROLLER) { in sony_leds_init()
2127 sc->led_count = 4; in sony_leds_init()
2133 return -ENODEV; in sony_leds_init()
2134 } else if (sc->quirks & DUALSHOCK4_CONTROLLER) { in sony_leds_init()
2136 sc->led_state[3] = 1; in sony_leds_init()
2137 sc->led_count = 4; in sony_leds_init()
2138 memset(max_brightness, 255, 3); in sony_leds_init()
2139 use_hw_blink[3] = 1; in sony_leds_init()
2143 } else if (sc->quirks & MOTION_CONTROLLER) { in sony_leds_init()
2144 sc->led_count = 3; in sony_leds_init()
2145 memset(max_brightness, 255, 3); in sony_leds_init()
2149 } else if (sc->quirks & NAVIGATION_CONTROLLER) { in sony_leds_init()
2152 memcpy(sc->led_state, navigation_leds, sizeof(navigation_leds)); in sony_leds_init()
2153 sc->led_count = 1; in sony_leds_init()
2160 sc->led_count = 4; in sony_leds_init()
2174 name_sz = strlen(dev_name(&hdev->dev)) + name_len + 1; in sony_leds_init()
2176 for (n = 0; n < sc->led_count; n++) { in sony_leds_init()
2179 name_sz = strlen(dev_name(&hdev->dev)) + strlen(ds4_name_str[n]) + 2; in sony_leds_init()
2181 led = devm_kzalloc(&hdev->dev, sizeof(struct led_classdev) + name_sz, GFP_KERNEL); in sony_leds_init()
2184 return -ENOMEM; in sony_leds_init()
2189 snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), in sony_leds_init()
2192 snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), n + 1); in sony_leds_init()
2193 led->name = name; in sony_leds_init()
2194 led->brightness = sc->led_state[n]; in sony_leds_init()
2195 led->max_brightness = max_brightness[n]; in sony_leds_init()
2196 led->flags = LED_CORE_SUSPENDRESUME; in sony_leds_init()
2197 led->brightness_get = sony_led_get_brightness; in sony_leds_init()
2198 led->brightness_set = sony_led_set_brightness; in sony_leds_init()
2201 led->blink_set = sony_led_blink_set; in sony_leds_init()
2203 sc->leds[n] = led; in sony_leds_init()
2205 ret = devm_led_classdev_register(&hdev->dev, led); in sony_leds_init()
2230 (struct sixaxis_output_report *)sc->output_report_dmabuf; in sixaxis_send_output_report()
2237 report->rumble.right_motor_on = sc->right ? 1 : 0; in sixaxis_send_output_report()
2238 report->rumble.left_motor_force = sc->left; in sixaxis_send_output_report()
2241 report->leds_bitmap |= sc->led_state[0] << 1; in sixaxis_send_output_report()
2242 report->leds_bitmap |= sc->led_state[1] << 2; in sixaxis_send_output_report()
2243 report->leds_bitmap |= sc->led_state[2] << 3; in sixaxis_send_output_report()
2244 report->leds_bitmap |= sc->led_state[3] << 4; in sixaxis_send_output_report()
2246 /* Set flag for all leds off, required for 3rd party INTEC controller */ in sixaxis_send_output_report()
2247 if ((report->leds_bitmap & 0x1E) == 0) in sixaxis_send_output_report()
2248 report->leds_bitmap |= 0x20; in sixaxis_send_output_report()
2253 * Index 0 = LED 4, index 1 = LED 3, etc... in sixaxis_send_output_report()
2260 if (sc->led_delay_on[n] || sc->led_delay_off[n]) { in sixaxis_send_output_report()
2261 report->led[3 - n].duty_off = sc->led_delay_off[n]; in sixaxis_send_output_report()
2262 report->led[3 - n].duty_on = sc->led_delay_on[n]; in sixaxis_send_output_report()
2267 if (sc->quirks & SHANWAN_GAMEPAD) in sixaxis_send_output_report()
2268 hid_hw_output_report(sc->hdev, (u8 *)report, in sixaxis_send_output_report()
2271 hid_hw_raw_request(sc->hdev, report->report_id, (u8 *)report, in sixaxis_send_output_report()
2278 struct hid_device *hdev = sc->hdev; in dualshock4_send_output_report()
2279 u8 *buf = sc->output_report_dmabuf; in dualshock4_send_output_report()
2285 * 0x00 - 1ms in dualshock4_send_output_report()
2286 * 0x01 - 1ms in dualshock4_send_output_report()
2287 * 0x02 - 2ms in dualshock4_send_output_report()
2288 * 0x3E - 62ms in dualshock4_send_output_report()
2289 * 0x3F - disabled in dualshock4_send_output_report()
2291 if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE)) { in dualshock4_send_output_report()
2299 buf[1] = 0xC0 /* HID + CRC */ | sc->ds4_bt_poll_interval; in dualshock4_send_output_report()
2300 buf[3] = 0x07; /* blink + LEDs + motor */ in dualshock4_send_output_report()
2305 buf[offset++] = sc->right; in dualshock4_send_output_report()
2306 buf[offset++] = sc->left; in dualshock4_send_output_report()
2311 /* LED 3 is the global control */ in dualshock4_send_output_report()
2312 if (sc->led_state[3]) { in dualshock4_send_output_report()
2313 buf[offset++] = sc->led_state[0]; in dualshock4_send_output_report()
2314 buf[offset++] = sc->led_state[1]; in dualshock4_send_output_report()
2315 buf[offset++] = sc->led_state[2]; in dualshock4_send_output_report()
2317 offset += 3; in dualshock4_send_output_report()
2321 buf[offset++] = sc->led_delay_on[3]; in dualshock4_send_output_report()
2322 buf[offset++] = sc->led_delay_off[3]; in dualshock4_send_output_report()
2324 if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE)) in dualshock4_send_output_report()
2332 crc = ~crc32_le(crc, buf, DS4_OUTPUT_REPORT_0x11_SIZE-4); in dualshock4_send_output_report()
2340 struct hid_device *hdev = sc->hdev; in motion_send_output_report()
2342 (struct motion_output_report_02 *)sc->output_report_dmabuf; in motion_send_output_report()
2346 report->type = 0x02; /* set leds */ in motion_send_output_report()
2347 report->r = sc->led_state[0]; in motion_send_output_report()
2348 report->g = sc->led_state[1]; in motion_send_output_report()
2349 report->b = sc->led_state[2]; in motion_send_output_report()
2352 report->rumble = max(sc->right, sc->left); in motion_send_output_report()
2360 if (sc->send_output_report) in sony_send_output_report()
2361 sc->send_output_report(sc); in sony_send_output_report()
2368 sc->send_output_report(sc); in sony_state_worker()
2373 if ((sc->quirks & SIXAXIS_CONTROLLER) || in sony_allocate_output_report()
2374 (sc->quirks & NAVIGATION_CONTROLLER)) in sony_allocate_output_report()
2375 sc->output_report_dmabuf = in sony_allocate_output_report()
2376 devm_kmalloc(&sc->hdev->dev, in sony_allocate_output_report()
2379 else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) in sony_allocate_output_report()
2380 sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev, in sony_allocate_output_report()
2383 else if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE)) in sony_allocate_output_report()
2384 sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev, in sony_allocate_output_report()
2387 else if (sc->quirks & MOTION_CONTROLLER) in sony_allocate_output_report()
2388 sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev, in sony_allocate_output_report()
2394 if (!sc->output_report_dmabuf) in sony_allocate_output_report()
2395 return -ENOMEM; in sony_allocate_output_report()
2407 if (effect->type != FF_RUMBLE) in sony_play_effect()
2410 sc->left = effect->u.rumble.strong_magnitude / 256; in sony_play_effect()
2411 sc->right = effect->u.rumble.weak_magnitude / 256; in sony_play_effect()
2422 if (list_empty(&sc->hdev->inputs)) { in sony_init_ff()
2423 hid_err(sc->hdev, "no inputs found\n"); in sony_init_ff()
2424 return -ENODEV; in sony_init_ff()
2426 hidinput = list_entry(sc->hdev->inputs.next, struct hid_input, list); in sony_init_ff()
2427 input_dev = hidinput->input; in sony_init_ff()
2451 spin_lock_irqsave(&sc->lock, flags); in sony_battery_get_property()
2452 battery_capacity = sc->battery_capacity; in sony_battery_get_property()
2453 battery_status = sc->battery_status; in sony_battery_get_property()
2454 spin_unlock_irqrestore(&sc->lock, flags); in sony_battery_get_property()
2458 val->intval = 1; in sony_battery_get_property()
2461 val->intval = POWER_SUPPLY_SCOPE_DEVICE; in sony_battery_get_property()
2464 val->intval = battery_capacity; in sony_battery_get_property()
2467 val->intval = battery_status; in sony_battery_get_property()
2470 ret = -EINVAL; in sony_battery_get_property()
2482 struct hid_device *hdev = sc->hdev; in sony_battery_probe()
2489 sc->battery_capacity = 100; in sony_battery_probe()
2491 sc->battery_desc.properties = sony_battery_props; in sony_battery_probe()
2492 sc->battery_desc.num_properties = ARRAY_SIZE(sony_battery_props); in sony_battery_probe()
2493 sc->battery_desc.get_property = sony_battery_get_property; in sony_battery_probe()
2494 sc->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; in sony_battery_probe()
2495 sc->battery_desc.use_for_apm = 0; in sony_battery_probe()
2496 sc->battery_desc.name = devm_kasprintf(&hdev->dev, GFP_KERNEL, in sony_battery_probe()
2497 battery_str_fmt, sc->mac_address, sc->device_id); in sony_battery_probe()
2498 if (!sc->battery_desc.name) in sony_battery_probe()
2499 return -ENOMEM; in sony_battery_probe()
2501 sc->battery = devm_power_supply_register(&hdev->dev, &sc->battery_desc, in sony_battery_probe()
2503 if (IS_ERR(sc->battery)) { in sony_battery_probe()
2504 ret = PTR_ERR(sc->battery); in sony_battery_probe()
2509 power_supply_powers(sc->battery, &hdev->dev); in sony_battery_probe()
2519 * Some USB-only devices masquerade as Sixaxis controllers and all have the
2527 const int sc0_not_bt = !(sc0->quirks & SONY_BT_DEVICE); in sony_compare_connection_type()
2528 const int sc1_not_bt = !(sc1->quirks & SONY_BT_DEVICE); in sony_compare_connection_type()
2542 ret = memcmp(sc->mac_address, entry->mac_address, in sony_check_add_dev_list()
2543 sizeof(sc->mac_address)); in sony_check_add_dev_list()
2548 ret = -EEXIST; in sony_check_add_dev_list()
2549 hid_info(sc->hdev, in sony_check_add_dev_list()
2551 sc->mac_address); in sony_check_add_dev_list()
2558 list_add(&(sc->list_node), &sony_device_list); in sony_check_add_dev_list()
2569 if (sc->list_node.next) { in sony_remove_dev_list()
2571 list_del(&(sc->list_node)); in sony_remove_dev_list()
2581 ret = strlen(sc->hdev->uniq); in sony_get_bt_devaddr()
2583 return -EINVAL; in sony_get_bt_devaddr()
2585 ret = sscanf(sc->hdev->uniq, in sony_get_bt_devaddr()
2587 &sc->mac_address[5], &sc->mac_address[4], &sc->mac_address[3], in sony_get_bt_devaddr()
2588 &sc->mac_address[2], &sc->mac_address[1], &sc->mac_address[0]); in sony_get_bt_devaddr()
2591 return -EINVAL; in sony_get_bt_devaddr()
2601 if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) || in sony_check_add()
2602 (sc->quirks & MOTION_CONTROLLER_BT) || in sony_check_add()
2603 (sc->quirks & NAVIGATION_CONTROLLER_BT) || in sony_check_add()
2604 (sc->quirks & SIXAXIS_CONTROLLER_BT)) { in sony_check_add()
2612 hid_warn(sc->hdev, "UNIQ does not contain a MAC address; duplicate check skipped\n"); in sony_check_add()
2615 } else if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE)) { in sony_check_add()
2618 return -ENOMEM; in sony_check_add()
2625 ret = hid_hw_raw_request(sc->hdev, 0x81, buf, in sony_check_add()
2630 hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n"); in sony_check_add()
2631 ret = ret < 0 ? ret : -EINVAL; in sony_check_add()
2635 memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address)); in sony_check_add()
2637 snprintf(sc->hdev->uniq, sizeof(sc->hdev->uniq), in sony_check_add()
2638 "%pMR", sc->mac_address); in sony_check_add()
2639 } else if ((sc->quirks & SIXAXIS_CONTROLLER_USB) || in sony_check_add()
2640 (sc->quirks & NAVIGATION_CONTROLLER_USB)) { in sony_check_add()
2643 return -ENOMEM; in sony_check_add()
2650 ret = hid_hw_raw_request(sc->hdev, 0xf2, buf, in sony_check_add()
2655 hid_err(sc->hdev, "failed to retrieve feature report 0xf2 with the Sixaxis MAC address\n"); in sony_check_add()
2656 ret = ret < 0 ? ret : -EINVAL; in sony_check_add()
2661 * The Sixaxis device MAC in the report is big-endian and must in sony_check_add()
2662 * be byte-swapped. in sony_check_add()
2665 sc->mac_address[5-n] = buf[4+n]; in sony_check_add()
2667 snprintf(sc->hdev->uniq, sizeof(sc->hdev->uniq), in sony_check_add()
2668 "%pMR", sc->mac_address); in sony_check_add()
2688 * All others are set to -1. in sony_set_device_id()
2690 if ((sc->quirks & SIXAXIS_CONTROLLER) || in sony_set_device_id()
2691 (sc->quirks & DUALSHOCK4_CONTROLLER)) { in sony_set_device_id()
2695 sc->device_id = -1; in sony_set_device_id()
2698 sc->device_id = ret; in sony_set_device_id()
2700 sc->device_id = -1; in sony_set_device_id()
2708 if (sc->device_id >= 0) { in sony_release_device_id()
2709 ida_simple_remove(&sony_device_id_allocator, sc->device_id); in sony_release_device_id()
2710 sc->device_id = -1; in sony_release_device_id()
2717 sc->send_output_report = send_output_report; in sony_init_output_report()
2719 if (!sc->state_worker_initialized) in sony_init_output_report()
2720 INIT_WORK(&sc->state_worker, sony_state_worker); in sony_init_output_report()
2722 sc->state_worker_initialized = 1; in sony_init_output_report()
2729 if (sc->hotplug_worker_initialized) in sony_cancel_work_sync()
2730 cancel_work_sync(&sc->hotplug_worker); in sony_cancel_work_sync()
2731 if (sc->state_worker_initialized) { in sony_cancel_work_sync()
2732 spin_lock_irqsave(&sc->lock, flags); in sony_cancel_work_sync()
2733 sc->state_worker_initialized = 0; in sony_cancel_work_sync()
2734 spin_unlock_irqrestore(&sc->lock, flags); in sony_cancel_work_sync()
2735 cancel_work_sync(&sc->state_worker); in sony_cancel_work_sync()
2762 if (sc->quirks & NAVIGATION_CONTROLLER_USB) { in sony_input_configured()
2779 hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP; in sony_input_configured()
2780 hdev->quirks |= HID_QUIRK_SKIP_OUTPUT_REPORT_ID; in sony_input_configured()
2781 sc->defer_initialization = 1; in sony_input_configured()
2790 } else if (sc->quirks & NAVIGATION_CONTROLLER_BT) { in sony_input_configured()
2795 hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP; in sony_input_configured()
2804 } else if (sc->quirks & SIXAXIS_CONTROLLER_USB) { in sony_input_configured()
2811 hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP; in sony_input_configured()
2812 hdev->quirks |= HID_QUIRK_SKIP_OUTPUT_REPORT_ID; in sony_input_configured()
2813 sc->defer_initialization = 1; in sony_input_configured()
2823 hid_err(sc->hdev, in sony_input_configured()
2829 } else if (sc->quirks & SIXAXIS_CONTROLLER_BT) { in sony_input_configured()
2834 hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP; in sony_input_configured()
2844 hid_err(sc->hdev, in sony_input_configured()
2850 } else if (sc->quirks & DUALSHOCK4_CONTROLLER) { in sony_input_configured()
2859 hid_err(sc->hdev, "Failed to get version data from Dualshock 4\n"); in sony_input_configured()
2863 ret = device_create_file(&sc->hdev->dev, &dev_attr_firmware_version); in sony_input_configured()
2865 hid_err(sc->hdev, "can't create sysfs firmware_version attribute err: %d\n", ret); in sony_input_configured()
2868 sc->fw_version_created = true; in sony_input_configured()
2870 ret = device_create_file(&sc->hdev->dev, &dev_attr_hardware_version); in sony_input_configured()
2872 hid_err(sc->hdev, "can't create sysfs hardware_version attribute err: %d\n", ret); in sony_input_configured()
2875 sc->hw_version_created = true; in sony_input_configured()
2883 hid_err(sc->hdev, in sony_input_configured()
2884 "Unable to initialize multi-touch slots: %d\n", in sony_input_configured()
2891 hid_err(sc->hdev, in sony_input_configured()
2896 if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) { in sony_input_configured()
2897 sc->ds4_bt_poll_interval = DS4_BT_DEFAULT_POLL_INTERVAL_MS; in sony_input_configured()
2898 ret = device_create_file(&sc->hdev->dev, &dev_attr_bt_poll_interval); in sony_input_configured()
2900 hid_warn(sc->hdev, in sony_input_configured()
2905 if (sc->quirks & DUALSHOCK4_DONGLE) { in sony_input_configured()
2906 INIT_WORK(&sc->hotplug_worker, dualshock4_calibration_work); in sony_input_configured()
2907 sc->hotplug_worker_initialized = 1; in sony_input_configured()
2908 sc->ds4_dongle_state = DONGLE_DISCONNECTED; in sony_input_configured()
2912 } else if (sc->quirks & NSG_MRXU_REMOTE) { in sony_input_configured()
2914 * The NSG-MRxU touchpad supports 2 touches and has a in sony_input_configured()
2920 hid_err(sc->hdev, in sony_input_configured()
2921 "Unable to initialize multi-touch slots: %d\n", in sony_input_configured()
2926 } else if (sc->quirks & MOTION_CONTROLLER) { in sony_input_configured()
2932 if (sc->quirks & SONY_LED_SUPPORT) { in sony_input_configured()
2938 if (sc->quirks & SONY_BATTERY_SUPPORT) { in sony_input_configured()
2951 if (sc->quirks & SONY_FF_SUPPORT) { in sony_input_configured()
2965 if (sc->ds4_bt_poll_interval) in sony_input_configured()
2966 device_remove_file(&sc->hdev->dev, &dev_attr_bt_poll_interval); in sony_input_configured()
2967 if (sc->fw_version_created) in sony_input_configured()
2968 device_remove_file(&sc->hdev->dev, &dev_attr_firmware_version); in sony_input_configured()
2969 if (sc->hw_version_created) in sony_input_configured()
2970 device_remove_file(&sc->hdev->dev, &dev_attr_hardware_version); in sony_input_configured()
2980 unsigned long quirks = id->driver_data; in sony_probe()
2985 if (!strcmp(hdev->name, "FutureMax Dance Mat")) in sony_probe()
2988 if (!strcmp(hdev->name, "SHANWAN PS3 GamePad") || in sony_probe()
2989 !strcmp(hdev->name, "ShanWan PS(R) Ga`epad")) in sony_probe()
2992 sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL); in sony_probe()
2995 return -ENOMEM; in sony_probe()
2998 spin_lock_init(&sc->lock); in sony_probe()
3000 sc->quirks = quirks; in sony_probe()
3002 sc->hdev = hdev; in sony_probe()
3010 if (sc->quirks & VAIO_RDESC_CONSTANT) in sony_probe()
3012 else if (sc->quirks & SIXAXIS_CONTROLLER) in sony_probe()
3021 if (sc->quirks & (SIXAXIS_CONTROLLER | DUALSHOCK4_CONTROLLER)) in sony_probe()
3022 hdev->version |= 0x8000; in sony_probe()
3038 if (!(hdev->claimed & HID_CLAIMED_INPUT)) { in sony_probe()
3040 ret = -ENODEV; in sony_probe()
3044 if (sc->quirks & (GHL_GUITAR_PS3WIIU | GHL_GUITAR_PS4)) { in sony_probe()
3046 ret = -EINVAL; in sony_probe()
3050 usbdev = to_usb_device(sc->hdev->dev.parent->parent); in sony_probe()
3052 sc->ghl_urb = usb_alloc_urb(0, GFP_ATOMIC); in sony_probe()
3053 if (!sc->ghl_urb) { in sony_probe()
3054 ret = -ENOMEM; in sony_probe()
3058 if (sc->quirks & GHL_GUITAR_PS3WIIU) in sony_probe()
3061 else if (sc->quirks & GHL_GUITAR_PS4) in sony_probe()
3069 timer_setup(&sc->ghl_poke_timer, ghl_magic_poke, 0); in sony_probe()
3070 mod_timer(&sc->ghl_poke_timer, in sony_probe()
3085 if (sc->quirks & (GHL_GUITAR_PS3WIIU | GHL_GUITAR_PS4)) { in sony_remove()
3086 del_timer_sync(&sc->ghl_poke_timer); in sony_remove()
3087 usb_free_urb(sc->ghl_urb); in sony_remove()
3092 if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) in sony_remove()
3093 device_remove_file(&sc->hdev->dev, &dev_attr_bt_poll_interval); in sony_remove()
3095 if (sc->fw_version_created) in sony_remove()
3096 device_remove_file(&sc->hdev->dev, &dev_attr_firmware_version); in sony_remove()
3098 if (sc->hw_version_created) in sony_remove()
3099 device_remove_file(&sc->hdev->dev, &dev_attr_hardware_version); in sony_remove()
3116 /* On suspend stop any running force-feedback events */ in sony_suspend()
3120 sc->left = sc->right = 0; in sony_suspend()
3136 if ((sc->quirks & SIXAXIS_CONTROLLER_USB) || in sony_resume()
3137 (sc->quirks & NAVIGATION_CONTROLLER_USB)) { in sony_resume()
3138 sixaxis_set_operational_usb(sc->hdev); in sony_resume()
3139 sc->defer_initialization = 1; in sony_resume()
3178 /* SMK-Link PS3 BD Remote Control */
3195 /* SMK-Link NSG-MR5U Remote Control */
3198 /* SMK-Link NSG-MR7U Remote Control */