Lines Matching full:ds
312 static inline void dualsense_schedule_work(struct dualsense *ds);
313 static void dualsense_set_lightbar(struct dualsense *ds, uint8_t red, uint8_t green, uint8_t blue);
713 static int dualsense_get_calibration_data(struct dualsense *ds) in dualsense_get_calibration_data() argument
731 ret = ps_get_report(ds->base.hdev, DS_FEATURE_REPORT_CALIBRATION, buf, in dualsense_get_calibration_data()
734 hid_err(ds->base.hdev, "Failed to retrieve DualSense calibration info: %d\n", ret); in dualsense_get_calibration_data()
761 ds->gyro_calib_data[0].abs_code = ABS_RX; in dualsense_get_calibration_data()
762 ds->gyro_calib_data[0].bias = gyro_pitch_bias; in dualsense_get_calibration_data()
763 ds->gyro_calib_data[0].sens_numer = speed_2x*DS_GYRO_RES_PER_DEG_S; in dualsense_get_calibration_data()
764 ds->gyro_calib_data[0].sens_denom = gyro_pitch_plus - gyro_pitch_minus; in dualsense_get_calibration_data()
766 ds->gyro_calib_data[1].abs_code = ABS_RY; in dualsense_get_calibration_data()
767 ds->gyro_calib_data[1].bias = gyro_yaw_bias; in dualsense_get_calibration_data()
768 ds->gyro_calib_data[1].sens_numer = speed_2x*DS_GYRO_RES_PER_DEG_S; in dualsense_get_calibration_data()
769 ds->gyro_calib_data[1].sens_denom = gyro_yaw_plus - gyro_yaw_minus; in dualsense_get_calibration_data()
771 ds->gyro_calib_data[2].abs_code = ABS_RZ; in dualsense_get_calibration_data()
772 ds->gyro_calib_data[2].bias = gyro_roll_bias; in dualsense_get_calibration_data()
773 ds->gyro_calib_data[2].sens_numer = speed_2x*DS_GYRO_RES_PER_DEG_S; in dualsense_get_calibration_data()
774 ds->gyro_calib_data[2].sens_denom = gyro_roll_plus - gyro_roll_minus; in dualsense_get_calibration_data()
781 ds->accel_calib_data[0].abs_code = ABS_X; in dualsense_get_calibration_data()
782 ds->accel_calib_data[0].bias = acc_x_plus - range_2g / 2; in dualsense_get_calibration_data()
783 ds->accel_calib_data[0].sens_numer = 2*DS_ACC_RES_PER_G; in dualsense_get_calibration_data()
784 ds->accel_calib_data[0].sens_denom = range_2g; in dualsense_get_calibration_data()
787 ds->accel_calib_data[1].abs_code = ABS_Y; in dualsense_get_calibration_data()
788 ds->accel_calib_data[1].bias = acc_y_plus - range_2g / 2; in dualsense_get_calibration_data()
789 ds->accel_calib_data[1].sens_numer = 2*DS_ACC_RES_PER_G; in dualsense_get_calibration_data()
790 ds->accel_calib_data[1].sens_denom = range_2g; in dualsense_get_calibration_data()
793 ds->accel_calib_data[2].abs_code = ABS_Z; in dualsense_get_calibration_data()
794 ds->accel_calib_data[2].bias = acc_z_plus - range_2g / 2; in dualsense_get_calibration_data()
795 ds->accel_calib_data[2].sens_numer = 2*DS_ACC_RES_PER_G; in dualsense_get_calibration_data()
796 ds->accel_calib_data[2].sens_denom = range_2g; in dualsense_get_calibration_data()
804 static int dualsense_get_firmware_info(struct dualsense *ds) in dualsense_get_firmware_info() argument
813 ret = ps_get_report(ds->base.hdev, DS_FEATURE_REPORT_FIRMWARE_INFO, buf, in dualsense_get_firmware_info()
816 hid_err(ds->base.hdev, "Failed to retrieve DualSense firmware info: %d\n", ret); in dualsense_get_firmware_info()
820 ds->base.hw_version = get_unaligned_le32(&buf[24]); in dualsense_get_firmware_info()
821 ds->base.fw_version = get_unaligned_le32(&buf[28]); in dualsense_get_firmware_info()
830 ds->update_version = get_unaligned_le16(&buf[44]); in dualsense_get_firmware_info()
837 static int dualsense_get_mac_address(struct dualsense *ds) in dualsense_get_mac_address() argument
846 ret = ps_get_report(ds->base.hdev, DS_FEATURE_REPORT_PAIRING_INFO, buf, in dualsense_get_mac_address()
849 hid_err(ds->base.hdev, "Failed to retrieve DualSense pairing info: %d\n", ret); in dualsense_get_mac_address()
853 memcpy(ds->base.mac_address, &buf[1], sizeof(ds->base.mac_address)); in dualsense_get_mac_address()
864 struct dualsense *ds = container_of(mc_cdev, struct dualsense, lightbar); in dualsense_lightbar_set_brightness() local
872 dualsense_set_lightbar(ds, red, green, blue); in dualsense_lightbar_set_brightness()
879 struct dualsense *ds = hid_get_drvdata(hdev); in dualsense_player_led_get_brightness() local
881 return !!(ds->player_leds_state & BIT(led - ds->player_leds)); in dualsense_player_led_get_brightness()
887 struct dualsense *ds = hid_get_drvdata(hdev); in dualsense_player_led_set_brightness() local
891 spin_lock_irqsave(&ds->base.lock, flags); in dualsense_player_led_set_brightness()
893 led_index = led - ds->player_leds; in dualsense_player_led_set_brightness()
895 ds->player_leds_state &= ~BIT(led_index); in dualsense_player_led_set_brightness()
897 ds->player_leds_state |= BIT(led_index); in dualsense_player_led_set_brightness()
899 ds->update_player_leds = true; in dualsense_player_led_set_brightness()
900 spin_unlock_irqrestore(&ds->base.lock, flags); in dualsense_player_led_set_brightness()
902 dualsense_schedule_work(ds); in dualsense_player_led_set_brightness()
907 static void dualsense_init_output_report(struct dualsense *ds, struct dualsense_output_report *rp, in dualsense_init_output_report() argument
910 struct hid_device *hdev = ds->base.hdev; in dualsense_init_output_report()
923 bt->seq_tag = (ds->output_seq << 4) | 0x0; in dualsense_init_output_report()
924 if (++ds->output_seq == 16) in dualsense_init_output_report()
925 ds->output_seq = 0; in dualsense_init_output_report()
946 static inline void dualsense_schedule_work(struct dualsense *ds) in dualsense_schedule_work() argument
950 spin_lock_irqsave(&ds->base.lock, flags); in dualsense_schedule_work()
951 if (ds->output_worker_initialized) in dualsense_schedule_work()
952 schedule_work(&ds->output_worker); in dualsense_schedule_work()
953 spin_unlock_irqrestore(&ds->base.lock, flags); in dualsense_schedule_work()
960 static void dualsense_send_output_report(struct dualsense *ds, in dualsense_send_output_report() argument
963 struct hid_device *hdev = ds->base.hdev; in dualsense_send_output_report()
981 struct dualsense *ds = container_of(work, struct dualsense, output_worker); in dualsense_output_worker() local
986 dualsense_init_output_report(ds, &report, ds->output_report_dmabuf); in dualsense_output_worker()
989 spin_lock_irqsave(&ds->base.lock, flags); in dualsense_output_worker()
991 if (ds->update_rumble) { in dualsense_output_worker()
994 if (ds->use_vibration_v2) in dualsense_output_worker()
998 common->motor_left = ds->motor_left; in dualsense_output_worker()
999 common->motor_right = ds->motor_right; in dualsense_output_worker()
1000 ds->update_rumble = false; in dualsense_output_worker()
1003 if (ds->update_lightbar) { in dualsense_output_worker()
1005 common->lightbar_red = ds->lightbar_red; in dualsense_output_worker()
1006 common->lightbar_green = ds->lightbar_green; in dualsense_output_worker()
1007 common->lightbar_blue = ds->lightbar_blue; in dualsense_output_worker()
1009 ds->update_lightbar = false; in dualsense_output_worker()
1012 if (ds->update_player_leds) { in dualsense_output_worker()
1014 common->player_leds = ds->player_leds_state; in dualsense_output_worker()
1016 ds->update_player_leds = false; in dualsense_output_worker()
1019 if (ds->update_mic_mute) { in dualsense_output_worker()
1021 common->mute_button_led = ds->mic_muted; in dualsense_output_worker()
1023 if (ds->mic_muted) { in dualsense_output_worker()
1033 ds->update_mic_mute = false; in dualsense_output_worker()
1036 spin_unlock_irqrestore(&ds->base.lock, flags); in dualsense_output_worker()
1038 dualsense_send_output_report(ds, &report); in dualsense_output_worker()
1045 struct dualsense *ds = container_of(ps_dev, struct dualsense, base); in dualsense_parse_report() local
1078 input_report_abs(ds->gamepad, ABS_X, ds_report->x); in dualsense_parse_report()
1079 input_report_abs(ds->gamepad, ABS_Y, ds_report->y); in dualsense_parse_report()
1080 input_report_abs(ds->gamepad, ABS_RX, ds_report->rx); in dualsense_parse_report()
1081 input_report_abs(ds->gamepad, ABS_RY, ds_report->ry); in dualsense_parse_report()
1082 input_report_abs(ds->gamepad, ABS_Z, ds_report->z); in dualsense_parse_report()
1083 input_report_abs(ds->gamepad, ABS_RZ, ds_report->rz); in dualsense_parse_report()
1088 input_report_abs(ds->gamepad, ABS_HAT0X, ps_gamepad_hat_mapping[value].x); in dualsense_parse_report()
1089 input_report_abs(ds->gamepad, ABS_HAT0Y, ps_gamepad_hat_mapping[value].y); in dualsense_parse_report()
1091 input_report_key(ds->gamepad, BTN_WEST, ds_report->buttons[0] & DS_BUTTONS0_SQUARE); in dualsense_parse_report()
1092 input_report_key(ds->gamepad, BTN_SOUTH, ds_report->buttons[0] & DS_BUTTONS0_CROSS); in dualsense_parse_report()
1093 input_report_key(ds->gamepad, BTN_EAST, ds_report->buttons[0] & DS_BUTTONS0_CIRCLE); in dualsense_parse_report()
1094 input_report_key(ds->gamepad, BTN_NORTH, ds_report->buttons[0] & DS_BUTTONS0_TRIANGLE); in dualsense_parse_report()
1095 input_report_key(ds->gamepad, BTN_TL, ds_report->buttons[1] & DS_BUTTONS1_L1); in dualsense_parse_report()
1096 input_report_key(ds->gamepad, BTN_TR, ds_report->buttons[1] & DS_BUTTONS1_R1); in dualsense_parse_report()
1097 input_report_key(ds->gamepad, BTN_TL2, ds_report->buttons[1] & DS_BUTTONS1_L2); in dualsense_parse_report()
1098 input_report_key(ds->gamepad, BTN_TR2, ds_report->buttons[1] & DS_BUTTONS1_R2); in dualsense_parse_report()
1099 input_report_key(ds->gamepad, BTN_SELECT, ds_report->buttons[1] & DS_BUTTONS1_CREATE); in dualsense_parse_report()
1100 input_report_key(ds->gamepad, BTN_START, ds_report->buttons[1] & DS_BUTTONS1_OPTIONS); in dualsense_parse_report()
1101 input_report_key(ds->gamepad, BTN_THUMBL, ds_report->buttons[1] & DS_BUTTONS1_L3); in dualsense_parse_report()
1102 input_report_key(ds->gamepad, BTN_THUMBR, ds_report->buttons[1] & DS_BUTTONS1_R3); in dualsense_parse_report()
1103 input_report_key(ds->gamepad, BTN_MODE, ds_report->buttons[2] & DS_BUTTONS2_PS_HOME); in dualsense_parse_report()
1104 input_sync(ds->gamepad); in dualsense_parse_report()
1112 if (btn_mic_state && !ds->last_btn_mic_state) { in dualsense_parse_report()
1114 ds->update_mic_mute = true; in dualsense_parse_report()
1115 ds->mic_muted = !ds->mic_muted; /* toggle */ in dualsense_parse_report()
1119 dualsense_schedule_work(ds); in dualsense_parse_report()
1121 ds->last_btn_mic_state = btn_mic_state; in dualsense_parse_report()
1126 int calib_data = mult_frac(ds->gyro_calib_data[i].sens_numer, in dualsense_parse_report()
1127 raw_data - ds->gyro_calib_data[i].bias, in dualsense_parse_report()
1128 ds->gyro_calib_data[i].sens_denom); in dualsense_parse_report()
1130 input_report_abs(ds->sensors, ds->gyro_calib_data[i].abs_code, calib_data); in dualsense_parse_report()
1136 int calib_data = mult_frac(ds->accel_calib_data[i].sens_numer, in dualsense_parse_report()
1137 raw_data - ds->accel_calib_data[i].bias, in dualsense_parse_report()
1138 ds->accel_calib_data[i].sens_denom); in dualsense_parse_report()
1140 input_report_abs(ds->sensors, ds->accel_calib_data[i].abs_code, calib_data); in dualsense_parse_report()
1145 if (!ds->sensor_timestamp_initialized) { in dualsense_parse_report()
1146 ds->sensor_timestamp_us = DIV_ROUND_CLOSEST(sensor_timestamp, 3); in dualsense_parse_report()
1147 ds->sensor_timestamp_initialized = true; in dualsense_parse_report()
1151 if (ds->prev_sensor_timestamp > sensor_timestamp) in dualsense_parse_report()
1152 delta = (U32_MAX - ds->prev_sensor_timestamp + sensor_timestamp + 1); in dualsense_parse_report()
1154 delta = sensor_timestamp - ds->prev_sensor_timestamp; in dualsense_parse_report()
1155 ds->sensor_timestamp_us += DIV_ROUND_CLOSEST(delta, 3); in dualsense_parse_report()
1157 ds->prev_sensor_timestamp = sensor_timestamp; in dualsense_parse_report()
1158 input_event(ds->sensors, EV_MSC, MSC_TIMESTAMP, ds->sensor_timestamp_us); in dualsense_parse_report()
1159 input_sync(ds->sensors); in dualsense_parse_report()
1165 input_mt_slot(ds->touchpad, i); in dualsense_parse_report()
1166 input_mt_report_slot_state(ds->touchpad, MT_TOOL_FINGER, active); in dualsense_parse_report()
1172 input_report_abs(ds->touchpad, ABS_MT_POSITION_X, x); in dualsense_parse_report()
1173 input_report_abs(ds->touchpad, ABS_MT_POSITION_Y, y); in dualsense_parse_report()
1176 input_mt_sync_frame(ds->touchpad); in dualsense_parse_report()
1177 input_report_key(ds->touchpad, BTN_LEFT, ds_report->buttons[2] & DS_BUTTONS2_TOUCHPAD); in dualsense_parse_report()
1178 input_sync(ds->touchpad); in dualsense_parse_report()
1222 struct dualsense *ds = hid_get_drvdata(hdev); in dualsense_play_effect() local
1228 spin_lock_irqsave(&ds->base.lock, flags); in dualsense_play_effect()
1229 ds->update_rumble = true; in dualsense_play_effect()
1230 ds->motor_left = effect->u.rumble.strong_magnitude / 256; in dualsense_play_effect()
1231 ds->motor_right = effect->u.rumble.weak_magnitude / 256; in dualsense_play_effect()
1232 spin_unlock_irqrestore(&ds->base.lock, flags); in dualsense_play_effect()
1234 dualsense_schedule_work(ds); in dualsense_play_effect()
1240 struct dualsense *ds = container_of(ps_dev, struct dualsense, base); in dualsense_remove() local
1243 spin_lock_irqsave(&ds->base.lock, flags); in dualsense_remove()
1244 ds->output_worker_initialized = false; in dualsense_remove()
1245 spin_unlock_irqrestore(&ds->base.lock, flags); in dualsense_remove()
1247 cancel_work_sync(&ds->output_worker); in dualsense_remove()
1250 static int dualsense_reset_leds(struct dualsense *ds) in dualsense_reset_leds() argument
1259 dualsense_init_output_report(ds, &report, buf); in dualsense_reset_leds()
1269 dualsense_send_output_report(ds, &report); in dualsense_reset_leds()
1275 static void dualsense_set_lightbar(struct dualsense *ds, uint8_t red, uint8_t green, uint8_t blue) in dualsense_set_lightbar() argument
1279 spin_lock_irqsave(&ds->base.lock, flags); in dualsense_set_lightbar()
1280 ds->update_lightbar = true; in dualsense_set_lightbar()
1281 ds->lightbar_red = red; in dualsense_set_lightbar()
1282 ds->lightbar_green = green; in dualsense_set_lightbar()
1283 ds->lightbar_blue = blue; in dualsense_set_lightbar()
1284 spin_unlock_irqrestore(&ds->base.lock, flags); in dualsense_set_lightbar()
1286 dualsense_schedule_work(ds); in dualsense_set_lightbar()
1289 static void dualsense_set_player_leds(struct dualsense *ds) in dualsense_set_player_leds() argument
1305 uint8_t player_id = ds->base.player_id % ARRAY_SIZE(player_ids); in dualsense_set_player_leds()
1307 ds->update_player_leds = true; in dualsense_set_player_leds()
1308 ds->player_leds_state = player_ids[player_id]; in dualsense_set_player_leds()
1309 dualsense_schedule_work(ds); in dualsense_set_player_leds()
1314 struct dualsense *ds; in dualsense_create() local
1332 ds = devm_kzalloc(&hdev->dev, sizeof(*ds), GFP_KERNEL); in dualsense_create()
1333 if (!ds) in dualsense_create()
1342 ps_dev = &ds->base; in dualsense_create()
1349 INIT_WORK(&ds->output_worker, dualsense_output_worker); in dualsense_create()
1350 ds->output_worker_initialized = true; in dualsense_create()
1351 hid_set_drvdata(hdev, ds); in dualsense_create()
1354 ds->output_report_dmabuf = devm_kzalloc(&hdev->dev, max_output_report_size, GFP_KERNEL); in dualsense_create()
1355 if (!ds->output_report_dmabuf) in dualsense_create()
1358 ret = dualsense_get_mac_address(ds); in dualsense_create()
1363 snprintf(hdev->uniq, sizeof(hdev->uniq), "%pMR", ds->base.mac_address); in dualsense_create()
1365 ret = dualsense_get_firmware_info(ds); in dualsense_create()
1381 ds->use_vibration_v2 = ds->update_version >= DS_FEATURE_VERSION(2, 21); in dualsense_create()
1383 ds->use_vibration_v2 = true; in dualsense_create()
1390 ret = dualsense_get_calibration_data(ds); in dualsense_create()
1396 ds->gamepad = ps_gamepad_create(hdev, dualsense_play_effect); in dualsense_create()
1397 if (IS_ERR(ds->gamepad)) { in dualsense_create()
1398 ret = PTR_ERR(ds->gamepad); in dualsense_create()
1402 ps_dev->input_dev_name = dev_name(&ds->gamepad->dev); in dualsense_create()
1404 ds->sensors = ps_sensors_create(hdev, DS_ACC_RANGE, DS_ACC_RES_PER_G, in dualsense_create()
1406 if (IS_ERR(ds->sensors)) { in dualsense_create()
1407 ret = PTR_ERR(ds->sensors); in dualsense_create()
1411 ds->touchpad = ps_touchpad_create(hdev, DS_TOUCHPAD_WIDTH, DS_TOUCHPAD_HEIGHT, 2); in dualsense_create()
1412 if (IS_ERR(ds->touchpad)) { in dualsense_create()
1413 ret = PTR_ERR(ds->touchpad); in dualsense_create()
1426 ret = dualsense_reset_leds(ds); in dualsense_create()
1430 ret = ps_lightbar_register(ps_dev, &ds->lightbar, dualsense_lightbar_set_brightness); in dualsense_create()
1435 dualsense_set_lightbar(ds, 0, 0, 128); /* blue */ in dualsense_create()
1440 ret = ps_led_register(ps_dev, &ds->player_leds[i], led_info); in dualsense_create()
1452 dualsense_set_player_leds(ds); in dualsense_create()
1459 ds->base.hw_version, ds->base.fw_version); in dualsense_create()
1461 return &ds->base; in dualsense_create()