Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: typec: ucsi: ccg: move command quirks to ucsi_ccg_sync_control()

It is easier to keep all command-specific quirks in a single place. Move
them to ucsi_ccg_sync_control() as the code now allows us to return
modified messages data.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20250120-ucsi-merge-commands-v2-2-462a1ec22ecc@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Dmitry Baryshkov and committed by
Greg Kroah-Hartman
7f826354 667ecac5

+29 -33
+29 -33
drivers/usb/typec/ucsi/ucsi_ccg.c
··· 222 222 u16 fw_build; 223 223 struct work_struct pm_work; 224 224 225 - u64 last_cmd_sent; 226 225 bool has_multiple_dp; 227 226 struct ucsi_ccg_altmode orig[UCSI_MAX_ALTMODES]; 228 227 struct ucsi_ccg_altmode updated[UCSI_MAX_ALTMODES]; ··· 537 538 * first and then vdo=0x3 538 539 */ 539 540 static void ucsi_ccg_nvidia_altmode(struct ucsi_ccg *uc, 540 - struct ucsi_altmode *alt) 541 + struct ucsi_altmode *alt, 542 + u64 command) 541 543 { 542 - switch (UCSI_ALTMODE_OFFSET(uc->last_cmd_sent)) { 544 + switch (UCSI_ALTMODE_OFFSET(command)) { 543 545 case NVIDIA_FTB_DP_OFFSET: 544 546 if (alt[0].mid == USB_TYPEC_NVIDIA_VLINK_DBG_VDO) 545 547 alt[0].mid = USB_TYPEC_NVIDIA_VLINK_DP_VDO | ··· 578 578 static int ucsi_ccg_read_message_in(struct ucsi *ucsi, void *val, size_t val_len) 579 579 { 580 580 struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi); 581 - struct ucsi_capability *cap; 582 - struct ucsi_altmode *alt; 583 581 584 582 spin_lock(&uc->op_lock); 585 583 memcpy(val, uc->op_data.message_in, val_len); 586 584 spin_unlock(&uc->op_lock); 587 - 588 - switch (UCSI_COMMAND(uc->last_cmd_sent)) { 589 - case UCSI_GET_CURRENT_CAM: 590 - if (uc->has_multiple_dp) 591 - ucsi_ccg_update_get_current_cam_cmd(uc, (u8 *)val); 592 - break; 593 - case UCSI_GET_ALTERNATE_MODES: 594 - if (UCSI_ALTMODE_RECIPIENT(uc->last_cmd_sent) == 595 - UCSI_RECIPIENT_SOP) { 596 - alt = val; 597 - if (alt[0].svid == USB_TYPEC_NVIDIA_VLINK_SID) 598 - ucsi_ccg_nvidia_altmode(uc, alt); 599 - } 600 - break; 601 - case UCSI_GET_CAPABILITY: 602 - if (uc->fw_build == CCG_FW_BUILD_NVIDIA_TEGRA) { 603 - cap = val; 604 - cap->features &= ~UCSI_CAP_ALT_MODE_DETAILS; 605 - } 606 - break; 607 - default: 608 - break; 609 - } 610 - uc->last_cmd_sent = 0; 611 585 612 586 return 0; 613 587 } ··· 613 639 mutex_lock(&uc->lock); 614 640 pm_runtime_get_sync(uc->dev); 615 641 616 - uc->last_cmd_sent = command; 617 - 618 - if (UCSI_COMMAND(uc->last_cmd_sent) == UCSI_SET_NEW_CAM && 642 + if (UCSI_COMMAND(command) == UCSI_SET_NEW_CAM && 619 643 uc->has_multiple_dp) { 620 - con_index = (uc->last_cmd_sent >> 16) & 644 + con_index = (command >> 16) & 621 645 UCSI_CMD_CONNECTOR_MASK; 622 646 if (con_index == 0) { 623 647 ret = -EINVAL; ··· 626 654 } 627 655 628 656 ret = ucsi_sync_control_common(ucsi, command, cci, data, size); 657 + 658 + switch (UCSI_COMMAND(command)) { 659 + case UCSI_GET_CURRENT_CAM: 660 + if (uc->has_multiple_dp) 661 + ucsi_ccg_update_get_current_cam_cmd(uc, (u8 *)data); 662 + break; 663 + case UCSI_GET_ALTERNATE_MODES: 664 + if (UCSI_ALTMODE_RECIPIENT(command) == UCSI_RECIPIENT_SOP) { 665 + struct ucsi_altmode *alt = data; 666 + 667 + if (alt[0].svid == USB_TYPEC_NVIDIA_VLINK_SID) 668 + ucsi_ccg_nvidia_altmode(uc, alt, command); 669 + } 670 + break; 671 + case UCSI_GET_CAPABILITY: 672 + if (uc->fw_build == CCG_FW_BUILD_NVIDIA_TEGRA) { 673 + struct ucsi_capability *cap = data; 674 + 675 + cap->features &= ~UCSI_CAP_ALT_MODE_DETAILS; 676 + } 677 + break; 678 + default: 679 + break; 680 + } 629 681 630 682 err_put: 631 683 pm_runtime_put_sync(uc->dev);