Lines Matching +full:motion +full:- +full:sensors
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"
101 /* PS/3 Motion controller */
328 * -------------------
449 struct sixaxis_led led[4]; /* LEDx at (4 - x) */
469 #define SENSOR_SUFFIX " Motion Sensors"
527 spin_lock_irqsave(&sc->lock, flags); in sony_schedule_work()
528 if (!sc->defer_initialization && sc->state_worker_initialized) in sony_schedule_work()
529 schedule_work(&sc->state_worker); in sony_schedule_work()
530 spin_unlock_irqrestore(&sc->lock, flags); in sony_schedule_work()
537 struct sony_sc *sc = urb->context; in ghl_magic_poke_cb()
539 if (urb->status < 0) in ghl_magic_poke_cb()
540 hid_err(sc->hdev, "URB transfer failed : %d", urb->status); in ghl_magic_poke_cb()
542 mod_timer(&sc->ghl_poke_timer, jiffies + GHL_GUITAR_POKE_INTERVAL*HZ); in ghl_magic_poke_cb()
550 ret = usb_submit_urb(sc->ghl_urb, GFP_ATOMIC); in ghl_magic_poke()
552 hid_err(sc->hdev, "usb_submit_urb failed: %d", ret); in ghl_magic_poke()
565 cr = devm_kzalloc(&sc->hdev->dev, sizeof(*cr), GFP_ATOMIC); in ghl_init_urb()
567 return -ENOMEM; in ghl_init_urb()
569 databuf = devm_kzalloc(&sc->hdev->dev, poke_size, GFP_ATOMIC); in ghl_init_urb()
571 return -ENOMEM; in ghl_init_urb()
573 cr->bRequestType = in ghl_init_urb()
575 cr->bRequest = USB_REQ_SET_CONFIGURATION; in ghl_init_urb()
576 cr->wValue = cpu_to_le16(ghl_magic_value); in ghl_init_urb()
577 cr->wIndex = 0; in ghl_init_urb()
578 cr->wLength = cpu_to_le16(poke_size); in ghl_init_urb()
581 sc->ghl_urb, usbdev, pipe, in ghl_init_urb()
591 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR) { in guitar_mapping()
592 unsigned int abs = usage->hid & HID_USAGE; in guitar_mapping()
620 unsigned int key = usage->hid & HID_USAGE; in ps3remote_mapping()
622 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) in ps3remote_mapping()
623 return -1; in ps3remote_mapping()
625 switch (usage->collection_index) { in ps3remote_mapping()
628 return -1; in ps3remote_mapping()
632 return -1; in ps3remote_mapping()
636 return -1; in ps3remote_mapping()
640 return -1; in ps3remote_mapping()
643 return -1; in ps3remote_mapping()
654 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) { in navigation_mapping()
655 unsigned int key = usage->hid & HID_USAGE; in navigation_mapping()
658 return -1; in navigation_mapping()
662 return -1; in navigation_mapping()
666 } else if (usage->hid == HID_GD_POINTER) { in navigation_mapping()
672 switch (usage->usage_index) { in navigation_mapping()
674 usage->hid = HID_GD_Z; in navigation_mapping()
677 return -1; in navigation_mapping()
680 hid_map_usage_clear(hi, usage, bit, max, EV_ABS, usage->hid & 0xf); in navigation_mapping()
682 } else if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK) { in navigation_mapping()
683 unsigned int abs = usage->hid & HID_USAGE; in navigation_mapping()
686 return -1; in navigation_mapping()
694 return -1; in navigation_mapping()
702 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) { in sixaxis_mapping()
703 unsigned int key = usage->hid & HID_USAGE; in sixaxis_mapping()
706 return -1; in sixaxis_mapping()
711 } else if (usage->hid == HID_GD_POINTER) { in sixaxis_mapping()
718 switch (usage->usage_index) { in sixaxis_mapping()
720 usage->hid = HID_GD_Z; in sixaxis_mapping()
723 usage->hid = HID_GD_RZ; in sixaxis_mapping()
726 return -1; in sixaxis_mapping()
729 hid_map_usage_clear(hi, usage, bit, max, EV_ABS, usage->hid & 0xf); in sixaxis_mapping()
731 } else if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK) { in sixaxis_mapping()
732 unsigned int abs = usage->hid & HID_USAGE; in sixaxis_mapping()
735 return -1; in sixaxis_mapping()
743 return -1; in sixaxis_mapping()
751 if (sc->quirks & (SINO_LITE_CONTROLLER | FUTUREMAX_DANCE_MAT)) in sony_report_fixup()
756 * a constant non-data variable. in sony_report_fixup()
758 if ((sc->quirks & VAIO_RDESC_CONSTANT) && *rsize >= 56 && in sony_report_fixup()
770 if (sc->quirks & MOTION_CONTROLLER) in sony_report_fixup()
773 if (sc->quirks & PS3REMOTE) in sony_report_fixup()
777 * Some knock-off USB dongles incorrectly report their button count in sony_report_fixup()
778 * as 13 instead of 16 causing three non-functional buttons. in sony_report_fixup()
780 if ((sc->quirks & SIXAXIS_CONTROLLER_USB) && *rsize >= 45 && in sony_report_fixup()
810 offset = (sc->quirks & MOTION_CONTROLLER) ? 12 : 30; in sixaxis_parse_report()
821 spin_lock_irqsave(&sc->lock, flags); in sixaxis_parse_report()
822 sc->battery_capacity = battery_capacity; in sixaxis_parse_report()
823 sc->battery_status = battery_status; in sixaxis_parse_report()
824 spin_unlock_irqrestore(&sc->lock, flags); in sixaxis_parse_report()
826 if (sc->quirks & SIXAXIS_CONTROLLER) { in sixaxis_parse_report()
830 val = ((rd[offset+1] << 8) | rd[offset]) - 511; in sixaxis_parse_report()
831 input_report_abs(sc->sensor_dev, ABS_X, val); in sixaxis_parse_report()
834 val = 511 - ((rd[offset+5] << 8) | rd[offset+4]); in sixaxis_parse_report()
835 input_report_abs(sc->sensor_dev, ABS_Y, val); in sixaxis_parse_report()
837 val = 511 - ((rd[offset+3] << 8) | rd[offset+2]); in sixaxis_parse_report()
838 input_report_abs(sc->sensor_dev, ABS_Z, val); in sixaxis_parse_report()
840 input_sync(sc->sensor_dev); in sixaxis_parse_report()
850 * The NSG-MRxU multi-touch trackpad data starts at offset 1 and in nsg_mrxu_parse_report()
851 * the touch-related data starts at offset 2. in nsg_mrxu_parse_report()
861 * Bits 0-4=X (width), bits 5-7=Y (length). in nsg_mrxu_parse_report()
863 * The bytes at offset 7-9 are the second touch X/Y coordinates. in nsg_mrxu_parse_report()
869 input_report_key(sc->touchpad, BTN_LEFT, rd[offset] & 0x0F); in nsg_mrxu_parse_report()
872 rely = ((s8) rd[offset+10]) * -1; in nsg_mrxu_parse_report()
883 input_mt_slot(sc->touchpad, n); in nsg_mrxu_parse_report()
884 input_mt_report_slot_state(sc->touchpad, MT_TOOL_FINGER, active & 0x03); in nsg_mrxu_parse_report()
889 input_report_abs(sc->touchpad, ABS_MT_TOUCH_MAJOR, in nsg_mrxu_parse_report()
891 input_report_abs(sc->touchpad, ABS_MT_TOUCH_MINOR, in nsg_mrxu_parse_report()
893 input_report_abs(sc->touchpad, ABS_MT_ORIENTATION, in nsg_mrxu_parse_report()
895 input_report_abs(sc->touchpad, ABS_MT_POSITION_X, x); in nsg_mrxu_parse_report()
896 input_report_abs(sc->touchpad, ABS_MT_POSITION_Y, in nsg_mrxu_parse_report()
897 NSG_MRXU_MAX_Y - y); in nsg_mrxu_parse_report()
904 input_report_rel(sc->touchpad, REL_X, relx); in nsg_mrxu_parse_report()
905 input_report_rel(sc->touchpad, REL_Y, rely); in nsg_mrxu_parse_report()
913 input_mt_sync_frame(sc->touchpad); in nsg_mrxu_parse_report()
915 input_sync(sc->touchpad); in nsg_mrxu_parse_report()
927 if ((sc->quirks & SIXAXIS_CONTROLLER) && rd[0] == 0x01 && size == 49) { in sony_raw_event()
937 return -EINVAL; in sony_raw_event()
945 } else if ((sc->quirks & MOTION_CONTROLLER_BT) && rd[0] == 0x01 && size == 49) { in sony_raw_event()
947 } else if ((sc->quirks & NAVIGATION_CONTROLLER) && rd[0] == 0x01 && in sony_raw_event()
950 } else if ((sc->quirks & NSG_MRXU_REMOTE) && rd[0] == 0x02) { in sony_raw_event()
955 if (sc->defer_initialization) { in sony_raw_event()
956 sc->defer_initialization = 0; in sony_raw_event()
969 if (sc->quirks & BUZZ_CONTROLLER) { in sony_mapping()
970 unsigned int key = usage->hid & HID_USAGE; in sony_mapping()
972 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) in sony_mapping()
973 return -1; in sony_mapping()
975 switch (usage->collection_index) { in sony_mapping()
978 return -1; in sony_mapping()
982 return -1; in sony_mapping()
985 return -1; in sony_mapping()
992 if (sc->quirks & PS3REMOTE) in sony_mapping()
995 if (sc->quirks & NAVIGATION_CONTROLLER) in sony_mapping()
998 if (sc->quirks & SIXAXIS_CONTROLLER) in sony_mapping()
1001 if (sc->quirks & GH_GUITAR_CONTROLLER) in sony_mapping()
1004 /* Let hid-core decide for the others */ in sony_mapping()
1015 sc->touchpad = devm_input_allocate_device(&sc->hdev->dev); in sony_register_touchpad()
1016 if (!sc->touchpad) in sony_register_touchpad()
1017 return -ENOMEM; in sony_register_touchpad()
1019 input_set_drvdata(sc->touchpad, sc); in sony_register_touchpad()
1020 sc->touchpad->dev.parent = &sc->hdev->dev; in sony_register_touchpad()
1021 sc->touchpad->phys = sc->hdev->phys; in sony_register_touchpad()
1022 sc->touchpad->uniq = sc->hdev->uniq; in sony_register_touchpad()
1023 sc->touchpad->id.bustype = sc->hdev->bus; in sony_register_touchpad()
1024 sc->touchpad->id.vendor = sc->hdev->vendor; in sony_register_touchpad()
1025 sc->touchpad->id.product = sc->hdev->product; in sony_register_touchpad()
1026 sc->touchpad->id.version = sc->hdev->version; in sony_register_touchpad()
1028 /* This suffix was originally apended when hid-sony also in sony_register_touchpad()
1034 name_sz = strlen(sc->hdev->name) + sizeof(TOUCHPAD_SUFFIX); in sony_register_touchpad()
1035 name = devm_kzalloc(&sc->hdev->dev, name_sz, GFP_KERNEL); in sony_register_touchpad()
1037 return -ENOMEM; in sony_register_touchpad()
1038 snprintf(name, name_sz, "%s" TOUCHPAD_SUFFIX, sc->hdev->name); in sony_register_touchpad()
1039 sc->touchpad->name = name; in sony_register_touchpad()
1042 __set_bit(EV_KEY, sc->touchpad->evbit); in sony_register_touchpad()
1043 __set_bit(BTN_LEFT, sc->touchpad->keybit); in sony_register_touchpad()
1044 __set_bit(INPUT_PROP_BUTTONPAD, sc->touchpad->propbit); in sony_register_touchpad()
1046 input_set_abs_params(sc->touchpad, ABS_MT_POSITION_X, 0, w, 0, 0); in sony_register_touchpad()
1047 input_set_abs_params(sc->touchpad, ABS_MT_POSITION_Y, 0, h, 0, 0); in sony_register_touchpad()
1050 input_set_abs_params(sc->touchpad, ABS_MT_TOUCH_MAJOR, in sony_register_touchpad()
1053 input_set_abs_params(sc->touchpad, ABS_MT_TOUCH_MINOR, in sony_register_touchpad()
1056 input_set_abs_params(sc->touchpad, ABS_MT_ORIENTATION, in sony_register_touchpad()
1060 if (sc->quirks & NSG_MRXU_REMOTE) { in sony_register_touchpad()
1061 __set_bit(EV_REL, sc->touchpad->evbit); in sony_register_touchpad()
1064 ret = input_mt_init_slots(sc->touchpad, touch_count, INPUT_MT_POINTER); in sony_register_touchpad()
1068 ret = input_register_device(sc->touchpad); in sony_register_touchpad()
1081 sc->sensor_dev = devm_input_allocate_device(&sc->hdev->dev); in sony_register_sensors()
1082 if (!sc->sensor_dev) in sony_register_sensors()
1083 return -ENOMEM; in sony_register_sensors()
1085 input_set_drvdata(sc->sensor_dev, sc); in sony_register_sensors()
1086 sc->sensor_dev->dev.parent = &sc->hdev->dev; in sony_register_sensors()
1087 sc->sensor_dev->phys = sc->hdev->phys; in sony_register_sensors()
1088 sc->sensor_dev->uniq = sc->hdev->uniq; in sony_register_sensors()
1089 sc->sensor_dev->id.bustype = sc->hdev->bus; in sony_register_sensors()
1090 sc->sensor_dev->id.vendor = sc->hdev->vendor; in sony_register_sensors()
1091 sc->sensor_dev->id.product = sc->hdev->product; in sony_register_sensors()
1092 sc->sensor_dev->id.version = sc->hdev->version; in sony_register_sensors()
1095 * DS4 compatible non-Sony devices with different names. in sony_register_sensors()
1097 name_sz = strlen(sc->hdev->name) + sizeof(SENSOR_SUFFIX); in sony_register_sensors()
1098 name = devm_kzalloc(&sc->hdev->dev, name_sz, GFP_KERNEL); in sony_register_sensors()
1100 return -ENOMEM; in sony_register_sensors()
1101 snprintf(name, name_sz, "%s" SENSOR_SUFFIX, sc->hdev->name); in sony_register_sensors()
1102 sc->sensor_dev->name = name; in sony_register_sensors()
1104 if (sc->quirks & SIXAXIS_CONTROLLER) { in sony_register_sensors()
1107 * a 1-axis gyro, but it is very difficult to manage from within in sony_register_sensors()
1111 input_set_abs_params(sc->sensor_dev, ABS_X, -512, 511, 4, 0); in sony_register_sensors()
1112 input_set_abs_params(sc->sensor_dev, ABS_Y, -512, 511, 4, 0); in sony_register_sensors()
1113 input_set_abs_params(sc->sensor_dev, ABS_Z, -512, 511, 4, 0); in sony_register_sensors()
1114 input_abs_set_res(sc->sensor_dev, ABS_X, SIXAXIS_ACC_RES_PER_G); in sony_register_sensors()
1115 input_abs_set_res(sc->sensor_dev, ABS_Y, SIXAXIS_ACC_RES_PER_G); in sony_register_sensors()
1116 input_abs_set_res(sc->sensor_dev, ABS_Z, SIXAXIS_ACC_RES_PER_G); in sony_register_sensors()
1119 __set_bit(INPUT_PROP_ACCELEROMETER, sc->sensor_dev->propbit); in sony_register_sensors()
1121 ret = input_register_device(sc->sensor_dev); in sony_register_sensors()
1143 return -ENOMEM; in sixaxis_set_operational_usb()
1165 * start rumbling non-stop, so skip step 3 for these controllers. in sixaxis_set_operational_usb()
1167 if (sc->quirks & SHANWAN_GAMEPAD) in sixaxis_set_operational_usb()
1190 return -ENOMEM; in sixaxis_set_operational_bt()
1215 int id = sc->device_id; in sixaxis_set_leds_from_id()
1223 memcpy(sc->led_state, sixaxis_leds[id], sizeof(sixaxis_leds[id])); in sixaxis_set_leds_from_id()
1228 struct hid_device *hdev = sc->hdev; in buzz_set_leds()
1230 &hdev->report_enum[HID_OUTPUT_REPORT].report_list; in buzz_set_leds()
1231 struct hid_report *report = list_entry(report_list->next, in buzz_set_leds()
1233 s32 *value = report->field[0]->value; in buzz_set_leds()
1238 value[1] = sc->led_state[0] ? 0xff : 0x00; in buzz_set_leds()
1239 value[2] = sc->led_state[1] ? 0xff : 0x00; in buzz_set_leds()
1240 value[3] = sc->led_state[2] ? 0xff : 0x00; in buzz_set_leds()
1241 value[4] = sc->led_state[3] ? 0xff : 0x00; in buzz_set_leds()
1249 if (!(sc->quirks & BUZZ_CONTROLLER)) in sony_set_leds()
1258 struct device *dev = led->dev->parent; in sony_led_set_brightness()
1278 force_update = !!(drv_data->quirks & SIXAXIS_CONTROLLER_USB); in sony_led_set_brightness()
1280 for (n = 0; n < drv_data->led_count; n++) { in sony_led_set_brightness()
1281 if (led == drv_data->leds[n] && (force_update || in sony_led_set_brightness()
1282 (value != drv_data->led_state[n] || in sony_led_set_brightness()
1283 drv_data->led_delay_on[n] || in sony_led_set_brightness()
1284 drv_data->led_delay_off[n]))) { in sony_led_set_brightness()
1286 drv_data->led_state[n] = value; in sony_led_set_brightness()
1289 drv_data->led_delay_on[n] = 0; in sony_led_set_brightness()
1290 drv_data->led_delay_off[n] = 0; in sony_led_set_brightness()
1300 struct device *dev = led->dev->parent; in sony_led_get_brightness()
1312 for (n = 0; n < drv_data->led_count; n++) { in sony_led_get_brightness()
1313 if (led == drv_data->leds[n]) in sony_led_get_brightness()
1314 return drv_data->led_state[n]; in sony_led_get_brightness()
1323 struct device *dev = led->dev->parent; in sony_led_blink_set()
1331 return -EINVAL; in sony_led_blink_set()
1347 for (n = 0; n < drv_data->led_count; n++) { in sony_led_blink_set()
1348 if (led == drv_data->leds[n]) in sony_led_blink_set()
1353 if (n >= drv_data->led_count) in sony_led_blink_set()
1354 return -EINVAL; in sony_led_blink_set()
1357 if (new_on != drv_data->led_delay_on[n] || in sony_led_blink_set()
1358 new_off != drv_data->led_delay_off[n]) { in sony_led_blink_set()
1359 drv_data->led_delay_on[n] = new_on; in sony_led_blink_set()
1360 drv_data->led_delay_off[n] = new_off; in sony_led_blink_set()
1369 struct hid_device *hdev = sc->hdev; in sony_leds_init()
1379 u8 max_brightness[MAX_LEDS] = { [0 ... (MAX_LEDS - 1)] = 1 }; in sony_leds_init()
1382 BUG_ON(!(sc->quirks & SONY_LED_SUPPORT)); in sony_leds_init()
1384 if (sc->quirks & BUZZ_CONTROLLER) { in sony_leds_init()
1385 sc->led_count = 4; in sony_leds_init()
1391 return -ENODEV; in sony_leds_init()
1392 } else if (sc->quirks & MOTION_CONTROLLER) { in sony_leds_init()
1393 sc->led_count = 3; in sony_leds_init()
1398 } else if (sc->quirks & NAVIGATION_CONTROLLER) { in sony_leds_init()
1401 memcpy(sc->led_state, navigation_leds, sizeof(navigation_leds)); in sony_leds_init()
1402 sc->led_count = 1; in sony_leds_init()
1409 sc->led_count = 4; in sony_leds_init()
1423 name_sz = strlen(dev_name(&hdev->dev)) + name_len + 1; in sony_leds_init()
1425 for (n = 0; n < sc->led_count; n++) { in sony_leds_init()
1428 name_sz = strlen(dev_name(&hdev->dev)) + strlen(color_name_str[n]) + 2; in sony_leds_init()
1430 led = devm_kzalloc(&hdev->dev, sizeof(struct led_classdev) + name_sz, GFP_KERNEL); in sony_leds_init()
1433 return -ENOMEM; in sony_leds_init()
1438 snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), in sony_leds_init()
1441 snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), n + 1); in sony_leds_init()
1442 led->name = name; in sony_leds_init()
1443 led->brightness = sc->led_state[n]; in sony_leds_init()
1444 led->max_brightness = max_brightness[n]; in sony_leds_init()
1445 led->flags = LED_CORE_SUSPENDRESUME; in sony_leds_init()
1446 led->brightness_get = sony_led_get_brightness; in sony_leds_init()
1447 led->brightness_set = sony_led_set_brightness; in sony_leds_init()
1450 led->blink_set = sony_led_blink_set; in sony_leds_init()
1452 sc->leds[n] = led; in sony_leds_init()
1454 ret = devm_led_classdev_register(&hdev->dev, led); in sony_leds_init()
1479 (struct sixaxis_output_report *)sc->output_report_dmabuf; in sixaxis_send_output_report()
1486 report->rumble.right_motor_on = sc->right ? 1 : 0; in sixaxis_send_output_report()
1487 report->rumble.left_motor_force = sc->left; in sixaxis_send_output_report()
1490 report->leds_bitmap |= sc->led_state[0] << 1; in sixaxis_send_output_report()
1491 report->leds_bitmap |= sc->led_state[1] << 2; in sixaxis_send_output_report()
1492 report->leds_bitmap |= sc->led_state[2] << 3; in sixaxis_send_output_report()
1493 report->leds_bitmap |= sc->led_state[3] << 4; in sixaxis_send_output_report()
1496 if ((report->leds_bitmap & 0x1E) == 0) in sixaxis_send_output_report()
1497 report->leds_bitmap |= 0x20; in sixaxis_send_output_report()
1509 if (sc->led_delay_on[n] || sc->led_delay_off[n]) { in sixaxis_send_output_report()
1510 report->led[3 - n].duty_off = sc->led_delay_off[n]; in sixaxis_send_output_report()
1511 report->led[3 - n].duty_on = sc->led_delay_on[n]; in sixaxis_send_output_report()
1516 if (sc->quirks & SHANWAN_GAMEPAD) in sixaxis_send_output_report()
1517 hid_hw_output_report(sc->hdev, (u8 *)report, in sixaxis_send_output_report()
1520 hid_hw_raw_request(sc->hdev, report->report_id, (u8 *)report, in sixaxis_send_output_report()
1527 struct hid_device *hdev = sc->hdev; in motion_send_output_report()
1529 (struct motion_output_report_02 *)sc->output_report_dmabuf; in motion_send_output_report()
1533 report->type = 0x02; /* set leds */ in motion_send_output_report()
1534 report->r = sc->led_state[0]; in motion_send_output_report()
1535 report->g = sc->led_state[1]; in motion_send_output_report()
1536 report->b = sc->led_state[2]; in motion_send_output_report()
1539 report->rumble = max(sc->right, sc->left); in motion_send_output_report()
1548 if (sc->send_output_report) in sony_send_output_report()
1549 sc->send_output_report(sc); in sony_send_output_report()
1557 sc->send_output_report(sc); in sony_state_worker()
1562 if ((sc->quirks & SIXAXIS_CONTROLLER) || in sony_allocate_output_report()
1563 (sc->quirks & NAVIGATION_CONTROLLER)) in sony_allocate_output_report()
1564 sc->output_report_dmabuf = in sony_allocate_output_report()
1565 devm_kmalloc(&sc->hdev->dev, in sony_allocate_output_report()
1568 else if (sc->quirks & MOTION_CONTROLLER) in sony_allocate_output_report()
1569 sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev, in sony_allocate_output_report()
1575 if (!sc->output_report_dmabuf) in sony_allocate_output_report()
1576 return -ENOMEM; in sony_allocate_output_report()
1588 if (effect->type != FF_RUMBLE) in sony_play_effect()
1591 sc->left = effect->u.rumble.strong_magnitude / 256; in sony_play_effect()
1592 sc->right = effect->u.rumble.weak_magnitude / 256; in sony_play_effect()
1603 if (list_empty(&sc->hdev->inputs)) { in sony_init_ff()
1604 hid_err(sc->hdev, "no inputs found\n"); in sony_init_ff()
1605 return -ENODEV; in sony_init_ff()
1607 hidinput = list_entry(sc->hdev->inputs.next, struct hid_input, list); in sony_init_ff()
1608 input_dev = hidinput->input; in sony_init_ff()
1632 spin_lock_irqsave(&sc->lock, flags); in sony_battery_get_property()
1633 battery_capacity = sc->battery_capacity; in sony_battery_get_property()
1634 battery_status = sc->battery_status; in sony_battery_get_property()
1635 spin_unlock_irqrestore(&sc->lock, flags); in sony_battery_get_property()
1639 val->intval = 1; in sony_battery_get_property()
1642 val->intval = POWER_SUPPLY_SCOPE_DEVICE; in sony_battery_get_property()
1645 val->intval = battery_capacity; in sony_battery_get_property()
1648 val->intval = battery_status; in sony_battery_get_property()
1651 ret = -EINVAL; in sony_battery_get_property()
1663 struct hid_device *hdev = sc->hdev; in sony_battery_probe()
1670 sc->battery_capacity = 100; in sony_battery_probe()
1672 sc->battery_desc.properties = sony_battery_props; in sony_battery_probe()
1673 sc->battery_desc.num_properties = ARRAY_SIZE(sony_battery_props); in sony_battery_probe()
1674 sc->battery_desc.get_property = sony_battery_get_property; in sony_battery_probe()
1675 sc->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; in sony_battery_probe()
1676 sc->battery_desc.use_for_apm = 0; in sony_battery_probe()
1677 sc->battery_desc.name = devm_kasprintf(&hdev->dev, GFP_KERNEL, in sony_battery_probe()
1678 battery_str_fmt, sc->mac_address, sc->device_id); in sony_battery_probe()
1679 if (!sc->battery_desc.name) in sony_battery_probe()
1680 return -ENOMEM; in sony_battery_probe()
1682 sc->battery = devm_power_supply_register(&hdev->dev, &sc->battery_desc, in sony_battery_probe()
1684 if (IS_ERR(sc->battery)) { in sony_battery_probe()
1685 ret = PTR_ERR(sc->battery); in sony_battery_probe()
1690 power_supply_powers(sc->battery, &hdev->dev); in sony_battery_probe()
1700 * Some USB-only devices masquerade as Sixaxis controllers and all have the
1708 const int sc0_not_bt = !(sc0->quirks & SONY_BT_DEVICE); in sony_compare_connection_type()
1709 const int sc1_not_bt = !(sc1->quirks & SONY_BT_DEVICE); in sony_compare_connection_type()
1723 ret = memcmp(sc->mac_address, entry->mac_address, in sony_check_add_dev_list()
1724 sizeof(sc->mac_address)); in sony_check_add_dev_list()
1729 ret = -EEXIST; in sony_check_add_dev_list()
1730 hid_info(sc->hdev, in sony_check_add_dev_list()
1732 sc->mac_address); in sony_check_add_dev_list()
1739 list_add(&(sc->list_node), &sony_device_list); in sony_check_add_dev_list()
1750 if (sc->list_node.next) { in sony_remove_dev_list()
1752 list_del(&(sc->list_node)); in sony_remove_dev_list()
1762 ret = strlen(sc->hdev->uniq); in sony_get_bt_devaddr()
1764 return -EINVAL; in sony_get_bt_devaddr()
1766 ret = sscanf(sc->hdev->uniq, in sony_get_bt_devaddr()
1768 &sc->mac_address[5], &sc->mac_address[4], &sc->mac_address[3], in sony_get_bt_devaddr()
1769 &sc->mac_address[2], &sc->mac_address[1], &sc->mac_address[0]); in sony_get_bt_devaddr()
1772 return -EINVAL; in sony_get_bt_devaddr()
1782 if ((sc->quirks & MOTION_CONTROLLER_BT) || in sony_check_add()
1783 (sc->quirks & NAVIGATION_CONTROLLER_BT) || in sony_check_add()
1784 (sc->quirks & SIXAXIS_CONTROLLER_BT)) { in sony_check_add()
1792 hid_warn(sc->hdev, "UNIQ does not contain a MAC address; duplicate check skipped\n"); in sony_check_add()
1795 } else if ((sc->quirks & SIXAXIS_CONTROLLER_USB) || in sony_check_add()
1796 (sc->quirks & NAVIGATION_CONTROLLER_USB)) { in sony_check_add()
1799 return -ENOMEM; in sony_check_add()
1806 ret = hid_hw_raw_request(sc->hdev, 0xf2, buf, in sony_check_add()
1811 hid_err(sc->hdev, "failed to retrieve feature report 0xf2 with the Sixaxis MAC address\n"); in sony_check_add()
1812 ret = ret < 0 ? ret : -EINVAL; in sony_check_add()
1817 * The Sixaxis device MAC in the report is big-endian and must in sony_check_add()
1818 * be byte-swapped. in sony_check_add()
1821 sc->mac_address[5-n] = buf[4+n]; in sony_check_add()
1823 snprintf(sc->hdev->uniq, sizeof(sc->hdev->uniq), in sony_check_add()
1824 "%pMR", sc->mac_address); in sony_check_add()
1844 * All others are set to -1. in sony_set_device_id()
1846 if (sc->quirks & SIXAXIS_CONTROLLER) { in sony_set_device_id()
1849 sc->device_id = -1; in sony_set_device_id()
1852 sc->device_id = ret; in sony_set_device_id()
1854 sc->device_id = -1; in sony_set_device_id()
1862 if (sc->device_id >= 0) { in sony_release_device_id()
1863 ida_free(&sony_device_id_allocator, sc->device_id); in sony_release_device_id()
1864 sc->device_id = -1; in sony_release_device_id()
1871 sc->send_output_report = send_output_report; in sony_init_output_report()
1873 if (!sc->state_worker_initialized) in sony_init_output_report()
1874 INIT_WORK(&sc->state_worker, sony_state_worker); in sony_init_output_report()
1876 sc->state_worker_initialized = 1; in sony_init_output_report()
1883 if (sc->state_worker_initialized) { in sony_cancel_work_sync()
1884 spin_lock_irqsave(&sc->lock, flags); in sony_cancel_work_sync()
1885 sc->state_worker_initialized = 0; in sony_cancel_work_sync()
1886 spin_unlock_irqrestore(&sc->lock, flags); in sony_cancel_work_sync()
1887 cancel_work_sync(&sc->state_worker); in sony_cancel_work_sync()
1914 if (sc->quirks & NAVIGATION_CONTROLLER_USB) { in sony_input_configured()
1931 hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP; in sony_input_configured()
1932 hdev->quirks |= HID_QUIRK_SKIP_OUTPUT_REPORT_ID; in sony_input_configured()
1933 sc->defer_initialization = 1; in sony_input_configured()
1942 } else if (sc->quirks & NAVIGATION_CONTROLLER_BT) { in sony_input_configured()
1947 hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP; in sony_input_configured()
1956 } else if (sc->quirks & SIXAXIS_CONTROLLER_USB) { in sony_input_configured()
1963 hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP; in sony_input_configured()
1964 hdev->quirks |= HID_QUIRK_SKIP_OUTPUT_REPORT_ID; in sony_input_configured()
1965 sc->defer_initialization = 1; in sony_input_configured()
1975 hid_err(sc->hdev, in sony_input_configured()
1976 "Unable to initialize motion sensors: %d\n", ret); in sony_input_configured()
1981 } else if (sc->quirks & SIXAXIS_CONTROLLER_BT) { in sony_input_configured()
1986 hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP; in sony_input_configured()
1996 hid_err(sc->hdev, in sony_input_configured()
1997 "Unable to initialize motion sensors: %d\n", ret); in sony_input_configured()
2002 } else if (sc->quirks & NSG_MRXU_REMOTE) { in sony_input_configured()
2004 * The NSG-MRxU touchpad supports 2 touches and has a in sony_input_configured()
2010 hid_err(sc->hdev, in sony_input_configured()
2011 "Unable to initialize multi-touch slots: %d\n", in sony_input_configured()
2016 } else if (sc->quirks & MOTION_CONTROLLER) { in sony_input_configured()
2020 if (sc->quirks & SONY_LED_SUPPORT) { in sony_input_configured()
2026 if (sc->quirks & SONY_BATTERY_SUPPORT) { in sony_input_configured()
2039 if (sc->quirks & SONY_FF_SUPPORT) { in sony_input_configured()
2058 unsigned long quirks = id->driver_data; in sony_probe()
2063 if (!strcmp(hdev->name, "FutureMax Dance Mat")) in sony_probe()
2066 if (!strcmp(hdev->name, "SHANWAN PS3 GamePad") || in sony_probe()
2067 !strcmp(hdev->name, "ShanWan PS(R) Ga`epad")) in sony_probe()
2070 sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL); in sony_probe()
2073 return -ENOMEM; in sony_probe()
2076 spin_lock_init(&sc->lock); in sony_probe()
2078 sc->quirks = quirks; in sony_probe()
2080 sc->hdev = hdev; in sony_probe()
2088 if (sc->quirks & VAIO_RDESC_CONSTANT) in sony_probe()
2090 else if (sc->quirks & SIXAXIS_CONTROLLER) in sony_probe()
2099 if (sc->quirks & SIXAXIS_CONTROLLER) in sony_probe()
2100 hdev->version |= 0x8000; in sony_probe()
2116 if (!(hdev->claimed & HID_CLAIMED_INPUT)) { in sony_probe()
2118 ret = -ENODEV; in sony_probe()
2122 if (sc->quirks & (GHL_GUITAR_PS3WIIU | GHL_GUITAR_PS4)) { in sony_probe()
2124 ret = -EINVAL; in sony_probe()
2128 usbdev = to_usb_device(sc->hdev->dev.parent->parent); in sony_probe()
2130 sc->ghl_urb = usb_alloc_urb(0, GFP_ATOMIC); in sony_probe()
2131 if (!sc->ghl_urb) { in sony_probe()
2132 ret = -ENOMEM; in sony_probe()
2136 if (sc->quirks & GHL_GUITAR_PS3WIIU) in sony_probe()
2139 else if (sc->quirks & GHL_GUITAR_PS4) in sony_probe()
2147 timer_setup(&sc->ghl_poke_timer, ghl_magic_poke, 0); in sony_probe()
2148 mod_timer(&sc->ghl_poke_timer, in sony_probe()
2155 usb_free_urb(sc->ghl_urb); in sony_probe()
2165 if (sc->quirks & (GHL_GUITAR_PS3WIIU | GHL_GUITAR_PS4)) { in sony_remove()
2166 del_timer_sync(&sc->ghl_poke_timer); in sony_remove()
2167 usb_free_urb(sc->ghl_urb); in sony_remove()
2187 /* On suspend stop any running force-feedback events */ in sony_suspend()
2191 sc->left = sc->right = 0; in sony_suspend()
2207 if ((sc->quirks & SIXAXIS_CONTROLLER_USB) || in sony_resume()
2208 (sc->quirks & NAVIGATION_CONTROLLER_USB)) { in sony_resume()
2209 sixaxis_set_operational_usb(sc->hdev); in sony_resume()
2210 sc->defer_initialization = 1; in sony_resume()
2249 /* SMK-Link PS3 BD Remote Control */
2255 /* SMK-Link NSG-MR5U Remote Control */
2258 /* SMK-Link NSG-MR7U Remote Control */