Lines Matching full:ds
541 static inline void dualsense_schedule_work(struct dualsense *ds);
543 static void dualsense_set_lightbar(struct dualsense *ds, uint8_t red, uint8_t green, uint8_t blue);
952 static int dualsense_get_calibration_data(struct dualsense *ds) in dualsense_get_calibration_data() argument
954 struct hid_device *hdev = ds->base.hdev; in dualsense_get_calibration_data()
972 ret = ps_get_report(ds->base.hdev, DS_FEATURE_REPORT_CALIBRATION, buf, in dualsense_get_calibration_data()
975 hid_err(ds->base.hdev, "Failed to retrieve DualSense calibration info: %d\n", ret); in dualsense_get_calibration_data()
1002 ds->gyro_calib_data[0].abs_code = ABS_RX; in dualsense_get_calibration_data()
1003 ds->gyro_calib_data[0].bias = 0; in dualsense_get_calibration_data()
1004 ds->gyro_calib_data[0].sens_numer = speed_2x*DS_GYRO_RES_PER_DEG_S; in dualsense_get_calibration_data()
1005 ds->gyro_calib_data[0].sens_denom = abs(gyro_pitch_plus - gyro_pitch_bias) + in dualsense_get_calibration_data()
1008 ds->gyro_calib_data[1].abs_code = ABS_RY; in dualsense_get_calibration_data()
1009 ds->gyro_calib_data[1].bias = 0; in dualsense_get_calibration_data()
1010 ds->gyro_calib_data[1].sens_numer = speed_2x*DS_GYRO_RES_PER_DEG_S; in dualsense_get_calibration_data()
1011 ds->gyro_calib_data[1].sens_denom = abs(gyro_yaw_plus - gyro_yaw_bias) + in dualsense_get_calibration_data()
1014 ds->gyro_calib_data[2].abs_code = ABS_RZ; in dualsense_get_calibration_data()
1015 ds->gyro_calib_data[2].bias = 0; in dualsense_get_calibration_data()
1016 ds->gyro_calib_data[2].sens_numer = speed_2x*DS_GYRO_RES_PER_DEG_S; in dualsense_get_calibration_data()
1017 ds->gyro_calib_data[2].sens_denom = abs(gyro_roll_plus - gyro_roll_bias) + in dualsense_get_calibration_data()
1025 for (i = 0; i < ARRAY_SIZE(ds->gyro_calib_data); i++) { in dualsense_get_calibration_data()
1026 if (ds->gyro_calib_data[i].sens_denom == 0) { in dualsense_get_calibration_data()
1028 ds->gyro_calib_data[i].abs_code); in dualsense_get_calibration_data()
1029 ds->gyro_calib_data[i].bias = 0; in dualsense_get_calibration_data()
1030 ds->gyro_calib_data[i].sens_numer = DS_GYRO_RANGE; in dualsense_get_calibration_data()
1031 ds->gyro_calib_data[i].sens_denom = S16_MAX; in dualsense_get_calibration_data()
1040 ds->accel_calib_data[0].abs_code = ABS_X; in dualsense_get_calibration_data()
1041 ds->accel_calib_data[0].bias = acc_x_plus - range_2g / 2; in dualsense_get_calibration_data()
1042 ds->accel_calib_data[0].sens_numer = 2*DS_ACC_RES_PER_G; in dualsense_get_calibration_data()
1043 ds->accel_calib_data[0].sens_denom = range_2g; in dualsense_get_calibration_data()
1046 ds->accel_calib_data[1].abs_code = ABS_Y; in dualsense_get_calibration_data()
1047 ds->accel_calib_data[1].bias = acc_y_plus - range_2g / 2; in dualsense_get_calibration_data()
1048 ds->accel_calib_data[1].sens_numer = 2*DS_ACC_RES_PER_G; in dualsense_get_calibration_data()
1049 ds->accel_calib_data[1].sens_denom = range_2g; in dualsense_get_calibration_data()
1052 ds->accel_calib_data[2].abs_code = ABS_Z; in dualsense_get_calibration_data()
1053 ds->accel_calib_data[2].bias = acc_z_plus - range_2g / 2; in dualsense_get_calibration_data()
1054 ds->accel_calib_data[2].sens_numer = 2*DS_ACC_RES_PER_G; in dualsense_get_calibration_data()
1055 ds->accel_calib_data[2].sens_denom = range_2g; in dualsense_get_calibration_data()
1062 for (i = 0; i < ARRAY_SIZE(ds->accel_calib_data); i++) { in dualsense_get_calibration_data()
1063 if (ds->accel_calib_data[i].sens_denom == 0) { in dualsense_get_calibration_data()
1065 ds->accel_calib_data[i].abs_code); in dualsense_get_calibration_data()
1066 ds->accel_calib_data[i].bias = 0; in dualsense_get_calibration_data()
1067 ds->accel_calib_data[i].sens_numer = DS_ACC_RANGE; in dualsense_get_calibration_data()
1068 ds->accel_calib_data[i].sens_denom = S16_MAX; in dualsense_get_calibration_data()
1078 static int dualsense_get_firmware_info(struct dualsense *ds) in dualsense_get_firmware_info() argument
1087 ret = ps_get_report(ds->base.hdev, DS_FEATURE_REPORT_FIRMWARE_INFO, buf, in dualsense_get_firmware_info()
1090 hid_err(ds->base.hdev, "Failed to retrieve DualSense firmware info: %d\n", ret); in dualsense_get_firmware_info()
1094 ds->base.hw_version = get_unaligned_le32(&buf[24]); in dualsense_get_firmware_info()
1095 ds->base.fw_version = get_unaligned_le32(&buf[28]); in dualsense_get_firmware_info()
1104 ds->update_version = get_unaligned_le16(&buf[44]); in dualsense_get_firmware_info()
1111 static int dualsense_get_mac_address(struct dualsense *ds) in dualsense_get_mac_address() argument
1120 ret = ps_get_report(ds->base.hdev, DS_FEATURE_REPORT_PAIRING_INFO, buf, in dualsense_get_mac_address()
1123 hid_err(ds->base.hdev, "Failed to retrieve DualSense pairing info: %d\n", ret); in dualsense_get_mac_address()
1127 memcpy(ds->base.mac_address, &buf[1], sizeof(ds->base.mac_address)); in dualsense_get_mac_address()
1138 struct dualsense *ds = container_of(mc_cdev, struct dualsense, lightbar); in dualsense_lightbar_set_brightness() local
1146 dualsense_set_lightbar(ds, red, green, blue); in dualsense_lightbar_set_brightness()
1153 struct dualsense *ds = hid_get_drvdata(hdev); in dualsense_player_led_get_brightness() local
1155 return !!(ds->player_leds_state & BIT(led - ds->player_leds)); in dualsense_player_led_get_brightness()
1161 struct dualsense *ds = hid_get_drvdata(hdev); in dualsense_player_led_set_brightness() local
1165 spin_lock_irqsave(&ds->base.lock, flags); in dualsense_player_led_set_brightness()
1167 led_index = led - ds->player_leds; in dualsense_player_led_set_brightness()
1169 ds->player_leds_state &= ~BIT(led_index); in dualsense_player_led_set_brightness()
1171 ds->player_leds_state |= BIT(led_index); in dualsense_player_led_set_brightness()
1173 ds->update_player_leds = true; in dualsense_player_led_set_brightness()
1174 spin_unlock_irqrestore(&ds->base.lock, flags); in dualsense_player_led_set_brightness()
1176 dualsense_schedule_work(ds); in dualsense_player_led_set_brightness()
1181 static void dualsense_init_output_report(struct dualsense *ds, struct dualsense_output_report *rp, in dualsense_init_output_report() argument
1184 struct hid_device *hdev = ds->base.hdev; in dualsense_init_output_report()
1197 bt->seq_tag = (ds->output_seq << 4) | 0x0; in dualsense_init_output_report()
1198 if (++ds->output_seq == 16) in dualsense_init_output_report()
1199 ds->output_seq = 0; in dualsense_init_output_report()
1220 static inline void dualsense_schedule_work(struct dualsense *ds) in dualsense_schedule_work() argument
1224 spin_lock_irqsave(&ds->base.lock, flags); in dualsense_schedule_work()
1225 if (ds->output_worker_initialized) in dualsense_schedule_work()
1226 schedule_work(&ds->output_worker); in dualsense_schedule_work()
1227 spin_unlock_irqrestore(&ds->base.lock, flags); in dualsense_schedule_work()
1234 static void dualsense_send_output_report(struct dualsense *ds, in dualsense_send_output_report() argument
1237 struct hid_device *hdev = ds->base.hdev; in dualsense_send_output_report()
1255 struct dualsense *ds = container_of(work, struct dualsense, output_worker); in dualsense_output_worker() local
1260 dualsense_init_output_report(ds, &report, ds->output_report_dmabuf); in dualsense_output_worker()
1263 spin_lock_irqsave(&ds->base.lock, flags); in dualsense_output_worker()
1265 if (ds->update_rumble) { in dualsense_output_worker()
1268 if (ds->use_vibration_v2) in dualsense_output_worker()
1272 common->motor_left = ds->motor_left; in dualsense_output_worker()
1273 common->motor_right = ds->motor_right; in dualsense_output_worker()
1274 ds->update_rumble = false; in dualsense_output_worker()
1277 if (ds->update_lightbar) { in dualsense_output_worker()
1279 common->lightbar_red = ds->lightbar_red; in dualsense_output_worker()
1280 common->lightbar_green = ds->lightbar_green; in dualsense_output_worker()
1281 common->lightbar_blue = ds->lightbar_blue; in dualsense_output_worker()
1283 ds->update_lightbar = false; in dualsense_output_worker()
1286 if (ds->update_player_leds) { in dualsense_output_worker()
1288 common->player_leds = ds->player_leds_state; in dualsense_output_worker()
1290 ds->update_player_leds = false; in dualsense_output_worker()
1293 if (ds->update_mic_mute) { in dualsense_output_worker()
1295 common->mute_button_led = ds->mic_muted; in dualsense_output_worker()
1297 if (ds->mic_muted) { in dualsense_output_worker()
1307 ds->update_mic_mute = false; in dualsense_output_worker()
1310 spin_unlock_irqrestore(&ds->base.lock, flags); in dualsense_output_worker()
1312 dualsense_send_output_report(ds, &report); in dualsense_output_worker()
1319 struct dualsense *ds = container_of(ps_dev, struct dualsense, base); in dualsense_parse_report() local
1352 input_report_abs(ds->gamepad, ABS_X, ds_report->x); in dualsense_parse_report()
1353 input_report_abs(ds->gamepad, ABS_Y, ds_report->y); in dualsense_parse_report()
1354 input_report_abs(ds->gamepad, ABS_RX, ds_report->rx); in dualsense_parse_report()
1355 input_report_abs(ds->gamepad, ABS_RY, ds_report->ry); in dualsense_parse_report()
1356 input_report_abs(ds->gamepad, ABS_Z, ds_report->z); in dualsense_parse_report()
1357 input_report_abs(ds->gamepad, ABS_RZ, ds_report->rz); in dualsense_parse_report()
1362 input_report_abs(ds->gamepad, ABS_HAT0X, ps_gamepad_hat_mapping[value].x); in dualsense_parse_report()
1363 input_report_abs(ds->gamepad, ABS_HAT0Y, ps_gamepad_hat_mapping[value].y); in dualsense_parse_report()
1365 input_report_key(ds->gamepad, BTN_WEST, ds_report->buttons[0] & DS_BUTTONS0_SQUARE); in dualsense_parse_report()
1366 input_report_key(ds->gamepad, BTN_SOUTH, ds_report->buttons[0] & DS_BUTTONS0_CROSS); in dualsense_parse_report()
1367 input_report_key(ds->gamepad, BTN_EAST, ds_report->buttons[0] & DS_BUTTONS0_CIRCLE); in dualsense_parse_report()
1368 input_report_key(ds->gamepad, BTN_NORTH, ds_report->buttons[0] & DS_BUTTONS0_TRIANGLE); in dualsense_parse_report()
1369 input_report_key(ds->gamepad, BTN_TL, ds_report->buttons[1] & DS_BUTTONS1_L1); in dualsense_parse_report()
1370 input_report_key(ds->gamepad, BTN_TR, ds_report->buttons[1] & DS_BUTTONS1_R1); in dualsense_parse_report()
1371 input_report_key(ds->gamepad, BTN_TL2, ds_report->buttons[1] & DS_BUTTONS1_L2); in dualsense_parse_report()
1372 input_report_key(ds->gamepad, BTN_TR2, ds_report->buttons[1] & DS_BUTTONS1_R2); in dualsense_parse_report()
1373 input_report_key(ds->gamepad, BTN_SELECT, ds_report->buttons[1] & DS_BUTTONS1_CREATE); in dualsense_parse_report()
1374 input_report_key(ds->gamepad, BTN_START, ds_report->buttons[1] & DS_BUTTONS1_OPTIONS); in dualsense_parse_report()
1375 input_report_key(ds->gamepad, BTN_THUMBL, ds_report->buttons[1] & DS_BUTTONS1_L3); in dualsense_parse_report()
1376 input_report_key(ds->gamepad, BTN_THUMBR, ds_report->buttons[1] & DS_BUTTONS1_R3); in dualsense_parse_report()
1377 input_report_key(ds->gamepad, BTN_MODE, ds_report->buttons[2] & DS_BUTTONS2_PS_HOME); in dualsense_parse_report()
1378 input_sync(ds->gamepad); in dualsense_parse_report()
1386 if (btn_mic_state && !ds->last_btn_mic_state) { in dualsense_parse_report()
1388 ds->update_mic_mute = true; in dualsense_parse_report()
1389 ds->mic_muted = !ds->mic_muted; /* toggle */ in dualsense_parse_report()
1393 dualsense_schedule_work(ds); in dualsense_parse_report()
1395 ds->last_btn_mic_state = btn_mic_state; in dualsense_parse_report()
1400 int calib_data = mult_frac(ds->gyro_calib_data[i].sens_numer, in dualsense_parse_report()
1401 raw_data, ds->gyro_calib_data[i].sens_denom); in dualsense_parse_report()
1403 input_report_abs(ds->sensors, ds->gyro_calib_data[i].abs_code, calib_data); in dualsense_parse_report()
1409 int calib_data = mult_frac(ds->accel_calib_data[i].sens_numer, in dualsense_parse_report()
1410 raw_data - ds->accel_calib_data[i].bias, in dualsense_parse_report()
1411 ds->accel_calib_data[i].sens_denom); in dualsense_parse_report()
1413 input_report_abs(ds->sensors, ds->accel_calib_data[i].abs_code, calib_data); in dualsense_parse_report()
1418 if (!ds->sensor_timestamp_initialized) { in dualsense_parse_report()
1419 ds->sensor_timestamp_us = DIV_ROUND_CLOSEST(sensor_timestamp, 3); in dualsense_parse_report()
1420 ds->sensor_timestamp_initialized = true; in dualsense_parse_report()
1424 if (ds->prev_sensor_timestamp > sensor_timestamp) in dualsense_parse_report()
1425 delta = (U32_MAX - ds->prev_sensor_timestamp + sensor_timestamp + 1); in dualsense_parse_report()
1427 delta = sensor_timestamp - ds->prev_sensor_timestamp; in dualsense_parse_report()
1428 ds->sensor_timestamp_us += DIV_ROUND_CLOSEST(delta, 3); in dualsense_parse_report()
1430 ds->prev_sensor_timestamp = sensor_timestamp; in dualsense_parse_report()
1431 input_event(ds->sensors, EV_MSC, MSC_TIMESTAMP, ds->sensor_timestamp_us); in dualsense_parse_report()
1432 input_sync(ds->sensors); in dualsense_parse_report()
1438 input_mt_slot(ds->touchpad, i); in dualsense_parse_report()
1439 input_mt_report_slot_state(ds->touchpad, MT_TOOL_FINGER, active); in dualsense_parse_report()
1445 input_report_abs(ds->touchpad, ABS_MT_POSITION_X, x); in dualsense_parse_report()
1446 input_report_abs(ds->touchpad, ABS_MT_POSITION_Y, y); in dualsense_parse_report()
1449 input_mt_sync_frame(ds->touchpad); in dualsense_parse_report()
1450 input_report_key(ds->touchpad, BTN_LEFT, ds_report->buttons[2] & DS_BUTTONS2_TOUCHPAD); in dualsense_parse_report()
1451 input_sync(ds->touchpad); in dualsense_parse_report()
1495 struct dualsense *ds = hid_get_drvdata(hdev); in dualsense_play_effect() local
1501 spin_lock_irqsave(&ds->base.lock, flags); in dualsense_play_effect()
1502 ds->update_rumble = true; in dualsense_play_effect()
1503 ds->motor_left = effect->u.rumble.strong_magnitude / 256; in dualsense_play_effect()
1504 ds->motor_right = effect->u.rumble.weak_magnitude / 256; in dualsense_play_effect()
1505 spin_unlock_irqrestore(&ds->base.lock, flags); in dualsense_play_effect()
1507 dualsense_schedule_work(ds); in dualsense_play_effect()
1513 struct dualsense *ds = container_of(ps_dev, struct dualsense, base); in dualsense_remove() local
1516 spin_lock_irqsave(&ds->base.lock, flags); in dualsense_remove()
1517 ds->output_worker_initialized = false; in dualsense_remove()
1518 spin_unlock_irqrestore(&ds->base.lock, flags); in dualsense_remove()
1520 cancel_work_sync(&ds->output_worker); in dualsense_remove()
1523 static int dualsense_reset_leds(struct dualsense *ds) in dualsense_reset_leds() argument
1532 dualsense_init_output_report(ds, &report, buf); in dualsense_reset_leds()
1542 dualsense_send_output_report(ds, &report); in dualsense_reset_leds()
1548 static void dualsense_set_lightbar(struct dualsense *ds, uint8_t red, uint8_t green, uint8_t blue) in dualsense_set_lightbar() argument
1552 spin_lock_irqsave(&ds->base.lock, flags); in dualsense_set_lightbar()
1553 ds->update_lightbar = true; in dualsense_set_lightbar()
1554 ds->lightbar_red = red; in dualsense_set_lightbar()
1555 ds->lightbar_green = green; in dualsense_set_lightbar()
1556 ds->lightbar_blue = blue; in dualsense_set_lightbar()
1557 spin_unlock_irqrestore(&ds->base.lock, flags); in dualsense_set_lightbar()
1559 dualsense_schedule_work(ds); in dualsense_set_lightbar()
1562 static void dualsense_set_player_leds(struct dualsense *ds) in dualsense_set_player_leds() argument
1578 uint8_t player_id = ds->base.player_id % ARRAY_SIZE(player_ids); in dualsense_set_player_leds()
1580 ds->update_player_leds = true; in dualsense_set_player_leds()
1581 ds->player_leds_state = player_ids[player_id]; in dualsense_set_player_leds()
1582 dualsense_schedule_work(ds); in dualsense_set_player_leds()
1587 struct dualsense *ds; in dualsense_create() local
1605 ds = devm_kzalloc(&hdev->dev, sizeof(*ds), GFP_KERNEL); in dualsense_create()
1606 if (!ds) in dualsense_create()
1615 ps_dev = &ds->base; in dualsense_create()
1622 INIT_WORK(&ds->output_worker, dualsense_output_worker); in dualsense_create()
1623 ds->output_worker_initialized = true; in dualsense_create()
1624 hid_set_drvdata(hdev, ds); in dualsense_create()
1627 ds->output_report_dmabuf = devm_kzalloc(&hdev->dev, max_output_report_size, GFP_KERNEL); in dualsense_create()
1628 if (!ds->output_report_dmabuf) in dualsense_create()
1631 ret = dualsense_get_mac_address(ds); in dualsense_create()
1636 snprintf(hdev->uniq, sizeof(hdev->uniq), "%pMR", ds->base.mac_address); in dualsense_create()
1638 ret = dualsense_get_firmware_info(ds); in dualsense_create()
1654 ds->use_vibration_v2 = ds->update_version >= DS_FEATURE_VERSION(2, 21); in dualsense_create()
1656 ds->use_vibration_v2 = true; in dualsense_create()
1663 ret = dualsense_get_calibration_data(ds); in dualsense_create()
1669 ds->gamepad = ps_gamepad_create(hdev, dualsense_play_effect); in dualsense_create()
1670 if (IS_ERR(ds->gamepad)) { in dualsense_create()
1671 ret = PTR_ERR(ds->gamepad); in dualsense_create()
1675 ps_dev->input_dev_name = dev_name(&ds->gamepad->dev); in dualsense_create()
1677 ds->sensors = ps_sensors_create(hdev, DS_ACC_RANGE, DS_ACC_RES_PER_G, in dualsense_create()
1679 if (IS_ERR(ds->sensors)) { in dualsense_create()
1680 ret = PTR_ERR(ds->sensors); in dualsense_create()
1684 ds->touchpad = ps_touchpad_create(hdev, DS_TOUCHPAD_WIDTH, DS_TOUCHPAD_HEIGHT, 2); in dualsense_create()
1685 if (IS_ERR(ds->touchpad)) { in dualsense_create()
1686 ret = PTR_ERR(ds->touchpad); in dualsense_create()
1699 ret = dualsense_reset_leds(ds); in dualsense_create()
1703 ret = ps_lightbar_register(ps_dev, &ds->lightbar, dualsense_lightbar_set_brightness); in dualsense_create()
1708 dualsense_set_lightbar(ds, 0, 0, 128); /* blue */ in dualsense_create()
1713 ret = ps_led_register(ps_dev, &ds->player_leds[i], led_info); in dualsense_create()
1725 dualsense_set_player_leds(ds); in dualsense_create()
1732 ds->base.hw_version, ds->base.fw_version); in dualsense_create()
1734 return &ds->base; in dualsense_create()