Lines Matching refs:ds
302 static void dualsense_set_lightbar(struct dualsense *ds, uint8_t red, uint8_t green, uint8_t blue);
705 static int dualsense_get_calibration_data(struct dualsense *ds) in dualsense_get_calibration_data() argument
723 ret = ps_get_report(ds->base.hdev, DS_FEATURE_REPORT_CALIBRATION, buf, in dualsense_get_calibration_data()
726 hid_err(ds->base.hdev, "Failed to retrieve DualSense calibration info: %d\n", ret); in dualsense_get_calibration_data()
753 ds->gyro_calib_data[0].abs_code = ABS_RX; in dualsense_get_calibration_data()
754 ds->gyro_calib_data[0].bias = gyro_pitch_bias; in dualsense_get_calibration_data()
755 ds->gyro_calib_data[0].sens_numer = speed_2x*DS_GYRO_RES_PER_DEG_S; in dualsense_get_calibration_data()
756 ds->gyro_calib_data[0].sens_denom = gyro_pitch_plus - gyro_pitch_minus; in dualsense_get_calibration_data()
758 ds->gyro_calib_data[1].abs_code = ABS_RY; in dualsense_get_calibration_data()
759 ds->gyro_calib_data[1].bias = gyro_yaw_bias; in dualsense_get_calibration_data()
760 ds->gyro_calib_data[1].sens_numer = speed_2x*DS_GYRO_RES_PER_DEG_S; in dualsense_get_calibration_data()
761 ds->gyro_calib_data[1].sens_denom = gyro_yaw_plus - gyro_yaw_minus; in dualsense_get_calibration_data()
763 ds->gyro_calib_data[2].abs_code = ABS_RZ; in dualsense_get_calibration_data()
764 ds->gyro_calib_data[2].bias = gyro_roll_bias; in dualsense_get_calibration_data()
765 ds->gyro_calib_data[2].sens_numer = speed_2x*DS_GYRO_RES_PER_DEG_S; in dualsense_get_calibration_data()
766 ds->gyro_calib_data[2].sens_denom = gyro_roll_plus - gyro_roll_minus; in dualsense_get_calibration_data()
773 ds->accel_calib_data[0].abs_code = ABS_X; in dualsense_get_calibration_data()
774 ds->accel_calib_data[0].bias = acc_x_plus - range_2g / 2; in dualsense_get_calibration_data()
775 ds->accel_calib_data[0].sens_numer = 2*DS_ACC_RES_PER_G; in dualsense_get_calibration_data()
776 ds->accel_calib_data[0].sens_denom = range_2g; in dualsense_get_calibration_data()
779 ds->accel_calib_data[1].abs_code = ABS_Y; in dualsense_get_calibration_data()
780 ds->accel_calib_data[1].bias = acc_y_plus - range_2g / 2; in dualsense_get_calibration_data()
781 ds->accel_calib_data[1].sens_numer = 2*DS_ACC_RES_PER_G; in dualsense_get_calibration_data()
782 ds->accel_calib_data[1].sens_denom = range_2g; in dualsense_get_calibration_data()
785 ds->accel_calib_data[2].abs_code = ABS_Z; in dualsense_get_calibration_data()
786 ds->accel_calib_data[2].bias = acc_z_plus - range_2g / 2; in dualsense_get_calibration_data()
787 ds->accel_calib_data[2].sens_numer = 2*DS_ACC_RES_PER_G; in dualsense_get_calibration_data()
788 ds->accel_calib_data[2].sens_denom = range_2g; in dualsense_get_calibration_data()
795 static int dualsense_get_firmware_info(struct dualsense *ds) in dualsense_get_firmware_info() argument
804 ret = ps_get_report(ds->base.hdev, DS_FEATURE_REPORT_FIRMWARE_INFO, buf, in dualsense_get_firmware_info()
807 hid_err(ds->base.hdev, "Failed to retrieve DualSense firmware info: %d\n", ret); in dualsense_get_firmware_info()
811 ds->base.hw_version = get_unaligned_le32(&buf[24]); in dualsense_get_firmware_info()
812 ds->base.fw_version = get_unaligned_le32(&buf[28]); in dualsense_get_firmware_info()
819 static int dualsense_get_mac_address(struct dualsense *ds) in dualsense_get_mac_address() argument
828 ret = ps_get_report(ds->base.hdev, DS_FEATURE_REPORT_PAIRING_INFO, buf, in dualsense_get_mac_address()
831 hid_err(ds->base.hdev, "Failed to retrieve DualSense pairing info: %d\n", ret); in dualsense_get_mac_address()
835 memcpy(ds->base.mac_address, &buf[1], sizeof(ds->base.mac_address)); in dualsense_get_mac_address()
846 struct dualsense *ds = container_of(mc_cdev, struct dualsense, lightbar); in dualsense_lightbar_set_brightness() local
854 dualsense_set_lightbar(ds, red, green, blue); in dualsense_lightbar_set_brightness()
861 struct dualsense *ds = hid_get_drvdata(hdev); in dualsense_player_led_get_brightness() local
863 return !!(ds->player_leds_state & BIT(led - ds->player_leds)); in dualsense_player_led_get_brightness()
869 struct dualsense *ds = hid_get_drvdata(hdev); in dualsense_player_led_set_brightness() local
873 spin_lock_irqsave(&ds->base.lock, flags); in dualsense_player_led_set_brightness()
875 led_index = led - ds->player_leds; in dualsense_player_led_set_brightness()
877 ds->player_leds_state &= ~BIT(led_index); in dualsense_player_led_set_brightness()
879 ds->player_leds_state |= BIT(led_index); in dualsense_player_led_set_brightness()
881 ds->update_player_leds = true; in dualsense_player_led_set_brightness()
882 spin_unlock_irqrestore(&ds->base.lock, flags); in dualsense_player_led_set_brightness()
884 schedule_work(&ds->output_worker); in dualsense_player_led_set_brightness()
889 static void dualsense_init_output_report(struct dualsense *ds, struct dualsense_output_report *rp, in dualsense_init_output_report() argument
892 struct hid_device *hdev = ds->base.hdev; in dualsense_init_output_report()
905 bt->seq_tag = (ds->output_seq << 4) | 0x0; in dualsense_init_output_report()
906 if (++ds->output_seq == 16) in dualsense_init_output_report()
907 ds->output_seq = 0; in dualsense_init_output_report()
932 static void dualsense_send_output_report(struct dualsense *ds, in dualsense_send_output_report() argument
935 struct hid_device *hdev = ds->base.hdev; in dualsense_send_output_report()
953 struct dualsense *ds = container_of(work, struct dualsense, output_worker); in dualsense_output_worker() local
958 dualsense_init_output_report(ds, &report, ds->output_report_dmabuf); in dualsense_output_worker()
961 spin_lock_irqsave(&ds->base.lock, flags); in dualsense_output_worker()
963 if (ds->update_rumble) { in dualsense_output_worker()
967 common->motor_left = ds->motor_left; in dualsense_output_worker()
968 common->motor_right = ds->motor_right; in dualsense_output_worker()
969 ds->update_rumble = false; in dualsense_output_worker()
972 if (ds->update_lightbar) { in dualsense_output_worker()
974 common->lightbar_red = ds->lightbar_red; in dualsense_output_worker()
975 common->lightbar_green = ds->lightbar_green; in dualsense_output_worker()
976 common->lightbar_blue = ds->lightbar_blue; in dualsense_output_worker()
978 ds->update_lightbar = false; in dualsense_output_worker()
981 if (ds->update_player_leds) { in dualsense_output_worker()
983 common->player_leds = ds->player_leds_state; in dualsense_output_worker()
985 ds->update_player_leds = false; in dualsense_output_worker()
988 if (ds->update_mic_mute) { in dualsense_output_worker()
990 common->mute_button_led = ds->mic_muted; in dualsense_output_worker()
992 if (ds->mic_muted) { in dualsense_output_worker()
1002 ds->update_mic_mute = false; in dualsense_output_worker()
1005 spin_unlock_irqrestore(&ds->base.lock, flags); in dualsense_output_worker()
1007 dualsense_send_output_report(ds, &report); in dualsense_output_worker()
1014 struct dualsense *ds = container_of(ps_dev, struct dualsense, base); in dualsense_parse_report() local
1047 input_report_abs(ds->gamepad, ABS_X, ds_report->x); in dualsense_parse_report()
1048 input_report_abs(ds->gamepad, ABS_Y, ds_report->y); in dualsense_parse_report()
1049 input_report_abs(ds->gamepad, ABS_RX, ds_report->rx); in dualsense_parse_report()
1050 input_report_abs(ds->gamepad, ABS_RY, ds_report->ry); in dualsense_parse_report()
1051 input_report_abs(ds->gamepad, ABS_Z, ds_report->z); in dualsense_parse_report()
1052 input_report_abs(ds->gamepad, ABS_RZ, ds_report->rz); in dualsense_parse_report()
1057 input_report_abs(ds->gamepad, ABS_HAT0X, ps_gamepad_hat_mapping[value].x); in dualsense_parse_report()
1058 input_report_abs(ds->gamepad, ABS_HAT0Y, ps_gamepad_hat_mapping[value].y); in dualsense_parse_report()
1060 input_report_key(ds->gamepad, BTN_WEST, ds_report->buttons[0] & DS_BUTTONS0_SQUARE); in dualsense_parse_report()
1061 input_report_key(ds->gamepad, BTN_SOUTH, ds_report->buttons[0] & DS_BUTTONS0_CROSS); in dualsense_parse_report()
1062 input_report_key(ds->gamepad, BTN_EAST, ds_report->buttons[0] & DS_BUTTONS0_CIRCLE); in dualsense_parse_report()
1063 input_report_key(ds->gamepad, BTN_NORTH, ds_report->buttons[0] & DS_BUTTONS0_TRIANGLE); in dualsense_parse_report()
1064 input_report_key(ds->gamepad, BTN_TL, ds_report->buttons[1] & DS_BUTTONS1_L1); in dualsense_parse_report()
1065 input_report_key(ds->gamepad, BTN_TR, ds_report->buttons[1] & DS_BUTTONS1_R1); in dualsense_parse_report()
1066 input_report_key(ds->gamepad, BTN_TL2, ds_report->buttons[1] & DS_BUTTONS1_L2); in dualsense_parse_report()
1067 input_report_key(ds->gamepad, BTN_TR2, ds_report->buttons[1] & DS_BUTTONS1_R2); in dualsense_parse_report()
1068 input_report_key(ds->gamepad, BTN_SELECT, ds_report->buttons[1] & DS_BUTTONS1_CREATE); in dualsense_parse_report()
1069 input_report_key(ds->gamepad, BTN_START, ds_report->buttons[1] & DS_BUTTONS1_OPTIONS); in dualsense_parse_report()
1070 input_report_key(ds->gamepad, BTN_THUMBL, ds_report->buttons[1] & DS_BUTTONS1_L3); in dualsense_parse_report()
1071 input_report_key(ds->gamepad, BTN_THUMBR, ds_report->buttons[1] & DS_BUTTONS1_R3); in dualsense_parse_report()
1072 input_report_key(ds->gamepad, BTN_MODE, ds_report->buttons[2] & DS_BUTTONS2_PS_HOME); in dualsense_parse_report()
1073 input_sync(ds->gamepad); in dualsense_parse_report()
1081 if (btn_mic_state && !ds->last_btn_mic_state) { in dualsense_parse_report()
1083 ds->update_mic_mute = true; in dualsense_parse_report()
1084 ds->mic_muted = !ds->mic_muted; /* toggle */ in dualsense_parse_report()
1088 schedule_work(&ds->output_worker); in dualsense_parse_report()
1090 ds->last_btn_mic_state = btn_mic_state; in dualsense_parse_report()
1095 int calib_data = mult_frac(ds->gyro_calib_data[i].sens_numer, in dualsense_parse_report()
1096 raw_data - ds->gyro_calib_data[i].bias, in dualsense_parse_report()
1097 ds->gyro_calib_data[i].sens_denom); in dualsense_parse_report()
1099 input_report_abs(ds->sensors, ds->gyro_calib_data[i].abs_code, calib_data); in dualsense_parse_report()
1105 int calib_data = mult_frac(ds->accel_calib_data[i].sens_numer, in dualsense_parse_report()
1106 raw_data - ds->accel_calib_data[i].bias, in dualsense_parse_report()
1107 ds->accel_calib_data[i].sens_denom); in dualsense_parse_report()
1109 input_report_abs(ds->sensors, ds->accel_calib_data[i].abs_code, calib_data); in dualsense_parse_report()
1114 if (!ds->sensor_timestamp_initialized) { in dualsense_parse_report()
1115 ds->sensor_timestamp_us = DIV_ROUND_CLOSEST(sensor_timestamp, 3); in dualsense_parse_report()
1116 ds->sensor_timestamp_initialized = true; in dualsense_parse_report()
1120 if (ds->prev_sensor_timestamp > sensor_timestamp) in dualsense_parse_report()
1121 delta = (U32_MAX - ds->prev_sensor_timestamp + sensor_timestamp + 1); in dualsense_parse_report()
1123 delta = sensor_timestamp - ds->prev_sensor_timestamp; in dualsense_parse_report()
1124 ds->sensor_timestamp_us += DIV_ROUND_CLOSEST(delta, 3); in dualsense_parse_report()
1126 ds->prev_sensor_timestamp = sensor_timestamp; in dualsense_parse_report()
1127 input_event(ds->sensors, EV_MSC, MSC_TIMESTAMP, ds->sensor_timestamp_us); in dualsense_parse_report()
1128 input_sync(ds->sensors); in dualsense_parse_report()
1134 input_mt_slot(ds->touchpad, i); in dualsense_parse_report()
1135 input_mt_report_slot_state(ds->touchpad, MT_TOOL_FINGER, active); in dualsense_parse_report()
1141 input_report_abs(ds->touchpad, ABS_MT_POSITION_X, x); in dualsense_parse_report()
1142 input_report_abs(ds->touchpad, ABS_MT_POSITION_Y, y); in dualsense_parse_report()
1145 input_mt_sync_frame(ds->touchpad); in dualsense_parse_report()
1146 input_report_key(ds->touchpad, BTN_LEFT, ds_report->buttons[2] & DS_BUTTONS2_TOUCHPAD); in dualsense_parse_report()
1147 input_sync(ds->touchpad); in dualsense_parse_report()
1191 struct dualsense *ds = hid_get_drvdata(hdev); in dualsense_play_effect() local
1197 spin_lock_irqsave(&ds->base.lock, flags); in dualsense_play_effect()
1198 ds->update_rumble = true; in dualsense_play_effect()
1199 ds->motor_left = effect->u.rumble.strong_magnitude / 256; in dualsense_play_effect()
1200 ds->motor_right = effect->u.rumble.weak_magnitude / 256; in dualsense_play_effect()
1201 spin_unlock_irqrestore(&ds->base.lock, flags); in dualsense_play_effect()
1203 schedule_work(&ds->output_worker); in dualsense_play_effect()
1207 static int dualsense_reset_leds(struct dualsense *ds) in dualsense_reset_leds() argument
1216 dualsense_init_output_report(ds, &report, buf); in dualsense_reset_leds()
1226 dualsense_send_output_report(ds, &report); in dualsense_reset_leds()
1232 static void dualsense_set_lightbar(struct dualsense *ds, uint8_t red, uint8_t green, uint8_t blue) in dualsense_set_lightbar() argument
1236 spin_lock_irqsave(&ds->base.lock, flags); in dualsense_set_lightbar()
1237 ds->update_lightbar = true; in dualsense_set_lightbar()
1238 ds->lightbar_red = red; in dualsense_set_lightbar()
1239 ds->lightbar_green = green; in dualsense_set_lightbar()
1240 ds->lightbar_blue = blue; in dualsense_set_lightbar()
1241 spin_unlock_irqrestore(&ds->base.lock, flags); in dualsense_set_lightbar()
1243 schedule_work(&ds->output_worker); in dualsense_set_lightbar()
1246 static void dualsense_set_player_leds(struct dualsense *ds) in dualsense_set_player_leds() argument
1262 uint8_t player_id = ds->base.player_id % ARRAY_SIZE(player_ids); in dualsense_set_player_leds()
1264 ds->update_player_leds = true; in dualsense_set_player_leds()
1265 ds->player_leds_state = player_ids[player_id]; in dualsense_set_player_leds()
1266 schedule_work(&ds->output_worker); in dualsense_set_player_leds()
1271 struct dualsense *ds; in dualsense_create() local
1289 ds = devm_kzalloc(&hdev->dev, sizeof(*ds), GFP_KERNEL); in dualsense_create()
1290 if (!ds) in dualsense_create()
1299 ps_dev = &ds->base; in dualsense_create()
1305 INIT_WORK(&ds->output_worker, dualsense_output_worker); in dualsense_create()
1306 hid_set_drvdata(hdev, ds); in dualsense_create()
1309 ds->output_report_dmabuf = devm_kzalloc(&hdev->dev, max_output_report_size, GFP_KERNEL); in dualsense_create()
1310 if (!ds->output_report_dmabuf) in dualsense_create()
1313 ret = dualsense_get_mac_address(ds); in dualsense_create()
1318 snprintf(hdev->uniq, sizeof(hdev->uniq), "%pMR", ds->base.mac_address); in dualsense_create()
1320 ret = dualsense_get_firmware_info(ds); in dualsense_create()
1330 ret = dualsense_get_calibration_data(ds); in dualsense_create()
1336 ds->gamepad = ps_gamepad_create(hdev, dualsense_play_effect); in dualsense_create()
1337 if (IS_ERR(ds->gamepad)) { in dualsense_create()
1338 ret = PTR_ERR(ds->gamepad); in dualsense_create()
1342 ps_dev->input_dev_name = dev_name(&ds->gamepad->dev); in dualsense_create()
1344 ds->sensors = ps_sensors_create(hdev, DS_ACC_RANGE, DS_ACC_RES_PER_G, in dualsense_create()
1346 if (IS_ERR(ds->sensors)) { in dualsense_create()
1347 ret = PTR_ERR(ds->sensors); in dualsense_create()
1351 ds->touchpad = ps_touchpad_create(hdev, DS_TOUCHPAD_WIDTH, DS_TOUCHPAD_HEIGHT, 2); in dualsense_create()
1352 if (IS_ERR(ds->touchpad)) { in dualsense_create()
1353 ret = PTR_ERR(ds->touchpad); in dualsense_create()
1366 ret = dualsense_reset_leds(ds); in dualsense_create()
1370 ret = ps_lightbar_register(ps_dev, &ds->lightbar, dualsense_lightbar_set_brightness); in dualsense_create()
1375 dualsense_set_lightbar(ds, 0, 0, 128); /* blue */ in dualsense_create()
1380 ret = ps_led_register(ps_dev, &ds->player_leds[i], led_info); in dualsense_create()
1392 dualsense_set_player_leds(ds); in dualsense_create()
1399 ds->base.hw_version, ds->base.fw_version); in dualsense_create()
1401 return &ds->base; in dualsense_create()