All of lore.kernel.org
 help / color / mirror / Atom feed
* [android-common:mirror-pa-android12-5.10-staging 1622/1718] drivers/usb/typec/tcpm/tcpm.c:4025:6: warning: this statement may fall through
@ 2020-12-08  2:46 kernel test robot
  0 siblings, 0 replies; only message in thread
From: kernel test robot @ 2020-12-08  2:46 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 36329 bytes --]

Hi Badhri,

FYI, the error/warning still remains.

tree:   https://android.googlesource.com/kernel/common mirror-pa-android12-5.10-staging
head:   0927548be1b3d5699f9b9849f90bb711ca481a07
commit: dd5bb066956e7c347ba93db4b4e0b65a84c7b933 [1622/1718] FROMLIST: usb: typec: tcpm: Honour pSnkStdby requirement during negotiation
config: arm64-randconfig-r006-20201208 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        git remote add android-common https://android.googlesource.com/kernel/common
        git fetch --no-tags android-common mirror-pa-android12-5.10-staging
        git checkout dd5bb066956e7c347ba93db4b4e0b65a84c7b933
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/usb/typec/tcpm/tcpm.c: In function 'run_state_machine':
>> drivers/usb/typec/tcpm/tcpm.c:4025:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
    4025 |   if (port->psnkstdby_after_accept)
         |      ^
   drivers/usb/typec/tcpm/tcpm.c:4029:2: note: here
    4029 |  case SNK_TRANSITION_SINK_VBUS:
         |  ^~~~
   At top level:
   drivers/usb/typec/tcpm/tcpm.c:2072:39: warning: 'tcpm_altmode_ops' defined but not used [-Wunused-const-variable=]
    2072 | static const struct typec_altmode_ops tcpm_altmode_ops = {
         |                                       ^~~~~~~~~~~~~~~~

vim +4025 drivers/usb/typec/tcpm/tcpm.c

  3568	
  3569	static void run_state_machine(struct tcpm_port *port)
  3570	{
  3571		int ret;
  3572		enum typec_pwr_opmode opmode;
  3573		unsigned int msecs;
  3574		enum tcpm_state upcoming_state;
  3575	
  3576		port->enter_state = port->state;
  3577		switch (port->state) {
  3578		case TOGGLING:
  3579			break;
  3580		/* SRC states */
  3581		case SRC_UNATTACHED:
  3582			if (!port->non_pd_role_swap)
  3583				tcpm_swap_complete(port, -ENOTCONN);
  3584			tcpm_src_detach(port);
  3585			if (port->debouncing) {
  3586				port->debouncing = false;
  3587				if (port->tcpc->check_contaminant &&
  3588				    port->tcpc->check_contaminant(port->tcpc)) {
  3589					/* Contaminant detection would handle toggling */
  3590					tcpm_set_state(port, TOGGLING, 0);
  3591					break;
  3592				}
  3593			}
  3594			if (tcpm_start_toggling(port, tcpm_rp_cc(port))) {
  3595				tcpm_set_state(port, TOGGLING, 0);
  3596				break;
  3597			}
  3598			tcpm_set_cc(port, tcpm_rp_cc(port));
  3599			if (port->port_type == TYPEC_PORT_DRP)
  3600				tcpm_set_state(port, SNK_UNATTACHED, PD_T_DRP_SNK);
  3601			break;
  3602		case SRC_ATTACH_WAIT:
  3603			port->debouncing = true;
  3604			if (tcpm_port_is_debug(port))
  3605				tcpm_set_state(port, DEBUG_ACC_ATTACHED,
  3606					       PD_T_CC_DEBOUNCE);
  3607			else if (tcpm_port_is_audio(port))
  3608				tcpm_set_state(port, AUDIO_ACC_ATTACHED,
  3609					       PD_T_CC_DEBOUNCE);
  3610			else if (tcpm_port_is_source(port))
  3611				tcpm_set_state(port,
  3612					       tcpm_try_snk(port) ? SNK_TRY
  3613								  : SRC_ATTACHED,
  3614					       PD_T_CC_DEBOUNCE);
  3615			break;
  3616	
  3617		case SNK_TRY:
  3618			port->debouncing = false;
  3619			port->try_snk_count++;
  3620			/*
  3621			 * Requirements:
  3622			 * - Do not drive vconn or vbus
  3623			 * - Terminate CC pins (both) to Rd
  3624			 * Action:
  3625			 * - Wait for tDRPTry (PD_T_DRP_TRY).
  3626			 *   Until then, ignore any state changes.
  3627			 */
  3628			tcpm_set_cc(port, TYPEC_CC_RD);
  3629			tcpm_set_state(port, SNK_TRY_WAIT, PD_T_DRP_TRY);
  3630			break;
  3631		case SNK_TRY_WAIT:
  3632			if (tcpm_port_is_sink(port)) {
  3633				tcpm_set_state(port, SNK_TRY_WAIT_DEBOUNCE, 0);
  3634			} else {
  3635				tcpm_set_state(port, SRC_TRYWAIT, 0);
  3636				port->max_wait = 0;
  3637			}
  3638			break;
  3639		case SNK_TRY_WAIT_DEBOUNCE:
  3640			tcpm_set_state(port, SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS,
  3641				       PD_T_TRY_CC_DEBOUNCE);
  3642			break;
  3643		case SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS:
  3644			if (port->vbus_present && tcpm_port_is_sink(port))
  3645				tcpm_set_state(port, SNK_ATTACHED, 0);
  3646			else
  3647				port->max_wait = 0;
  3648			break;
  3649		case SRC_TRYWAIT:
  3650			tcpm_set_cc(port, tcpm_rp_cc(port));
  3651			if (port->max_wait == 0) {
  3652				port->max_wait = jiffies +
  3653						 msecs_to_jiffies(PD_T_DRP_TRY);
  3654				tcpm_set_state(port, SRC_TRYWAIT_UNATTACHED,
  3655					       PD_T_DRP_TRY);
  3656			} else {
  3657				if (time_is_after_jiffies(port->max_wait))
  3658					tcpm_set_state(port, SRC_TRYWAIT_UNATTACHED,
  3659						       jiffies_to_msecs(port->max_wait -
  3660									jiffies));
  3661				else
  3662					tcpm_set_state(port, SNK_UNATTACHED, 0);
  3663			}
  3664			break;
  3665		case SRC_TRYWAIT_DEBOUNCE:
  3666			tcpm_set_state(port, SRC_ATTACHED, PD_T_CC_DEBOUNCE);
  3667			break;
  3668		case SRC_TRYWAIT_UNATTACHED:
  3669			tcpm_set_state(port, SNK_UNATTACHED, 0);
  3670			break;
  3671	
  3672		case SRC_ATTACHED:
  3673			ret = tcpm_src_attach(port);
  3674			tcpm_set_state(port, SRC_UNATTACHED,
  3675				       ret < 0 ? 0 : PD_T_PS_SOURCE_ON);
  3676			break;
  3677		case SRC_STARTUP:
  3678			opmode =  tcpm_get_pwr_opmode(tcpm_rp_cc(port));
  3679			typec_set_pwr_opmode(port->typec_port, opmode);
  3680			port->pwr_opmode = TYPEC_PWR_MODE_USB;
  3681			port->caps_count = 0;
  3682			port->negotiated_rev = PD_MAX_REV;
  3683			port->svdm_version = SVDM_MAX_VER;
  3684			port->message_id = 0;
  3685			port->rx_msgid = -1;
  3686			port->explicit_contract = false;
  3687			/* SNK -> SRC POWER/FAST_ROLE_SWAP finished */
  3688			if (port->ams == POWER_ROLE_SWAP ||
  3689			    port->ams == FAST_ROLE_SWAP)
  3690				tcpm_ams_finish(port);
  3691			port->upcoming_state = SRC_SEND_CAPABILITIES;
  3692			tcpm_ams_start(port, POWER_NEGOTIATION);
  3693			break;
  3694		case SRC_SEND_CAPABILITIES:
  3695			port->caps_count++;
  3696			if (port->caps_count > PD_N_CAPS_COUNT) {
  3697				tcpm_set_state(port, SRC_READY, 0);
  3698				break;
  3699			}
  3700			ret = tcpm_pd_send_source_caps(port);
  3701			if (ret < 0) {
  3702				tcpm_set_state(port, SRC_SEND_CAPABILITIES,
  3703					       PD_T_SEND_SOURCE_CAP);
  3704			} else {
  3705				/*
  3706				 * Per standard, we should clear the reset counter here.
  3707				 * However, that can result in state machine hang-ups.
  3708				 * Reset it only in READY state to improve stability.
  3709				 */
  3710				/* port->hard_reset_count = 0; */
  3711				port->caps_count = 0;
  3712	
  3713				tcpm_set_pd_capable(port, true);
  3714				tcpm_set_state_cond(port, SRC_SEND_CAPABILITIES_TIMEOUT,
  3715						    PD_T_SEND_SOURCE_CAP);
  3716			}
  3717			break;
  3718		case SRC_SEND_CAPABILITIES_TIMEOUT:
  3719			/*
  3720			 * Error recovery for a PD_DATA_SOURCE_CAP reply timeout.
  3721			 *
  3722			 * PD 2.0 sinks are supposed to accept src-capabilities with a
  3723			 * 3.0 header and simply ignore any src PDOs which the sink does
  3724			 * not understand such as PPS but some 2.0 sinks instead ignore
  3725			 * the entire PD_DATA_SOURCE_CAP message, causing contract
  3726			 * negotiation to fail.
  3727			 *
  3728			 * After PD_N_HARD_RESET_COUNT hard-reset attempts, we try
  3729			 * sending src-capabilities with a lower PD revision to
  3730			 * make these broken sinks work.
  3731			 */
  3732			if (port->hard_reset_count < PD_N_HARD_RESET_COUNT) {
  3733				tcpm_set_state(port, HARD_RESET_SEND, 0);
  3734			} else if (port->negotiated_rev > PD_REV20) {
  3735				port->negotiated_rev--;
  3736				port->hard_reset_count = 0;
  3737				tcpm_set_state(port, SRC_SEND_CAPABILITIES, 0);
  3738			} else {
  3739				tcpm_set_state(port, hard_reset_state(port), 0);
  3740			}
  3741			break;
  3742		case SRC_NEGOTIATE_CAPABILITIES:
  3743			ret = tcpm_pd_check_request(port);
  3744			if (ret < 0) {
  3745				tcpm_pd_send_control(port, PD_CTRL_REJECT);
  3746				if (!port->explicit_contract) {
  3747					tcpm_set_state(port,
  3748						       SRC_WAIT_NEW_CAPABILITIES, 0);
  3749				} else {
  3750					tcpm_set_state(port, SRC_READY, 0);
  3751				}
  3752			} else {
  3753				tcpm_pd_send_control(port, PD_CTRL_ACCEPT);
  3754				port->usb_comm_capable = port->sink_request &
  3755							 RDO_USB_COMM;
  3756				/* Notify TCPC of usb_comm_capable. */
  3757				tcpm_set_attached_state(port, true);
  3758				tcpm_set_state(port, SRC_TRANSITION_SUPPLY,
  3759					       PD_T_SRC_TRANSITION);
  3760			}
  3761			break;
  3762		case SRC_TRANSITION_SUPPLY:
  3763			/* XXX: regulator_set_voltage(vbus, ...) */
  3764			tcpm_pd_send_control(port, PD_CTRL_PS_RDY);
  3765			port->explicit_contract = true;
  3766			typec_set_pwr_opmode(port->typec_port, TYPEC_PWR_MODE_PD);
  3767			port->pwr_opmode = TYPEC_PWR_MODE_PD;
  3768			tcpm_set_state_cond(port, SRC_READY, 0);
  3769			break;
  3770		case SRC_READY:
  3771	#if 1
  3772			port->hard_reset_count = 0;
  3773	#endif
  3774			port->try_src_count = 0;
  3775	
  3776			tcpm_swap_complete(port, 0);
  3777			tcpm_typec_connect(port);
  3778	
  3779			if (port->ams != NONE_AMS)
  3780				tcpm_ams_finish(port);
  3781			if (port->next_ams != NONE_AMS) {
  3782				port->ams = port->next_ams;
  3783				port->next_ams = NONE_AMS;
  3784			}
  3785	
  3786			/*
  3787			 * If previous AMS is interrupted, switch to the upcoming
  3788			 * state.
  3789			 */
  3790			upcoming_state = port->upcoming_state;
  3791			if (port->upcoming_state != INVALID_STATE) {
  3792				port->upcoming_state = INVALID_STATE;
  3793				tcpm_set_state(port, upcoming_state, 0);
  3794				break;
  3795			}
  3796			tcpm_check_send_discover(port);
  3797			/*
  3798			 * 6.3.5
  3799			 * Sending ping messages is not necessary if
  3800			 * - the source operates at vSafe5V
  3801			 * or
  3802			 * - The system is not operating in PD mode
  3803			 * or
  3804			 * - Both partners are connected using a Type-C connector
  3805			 *
  3806			 * There is no actual need to send PD messages since the local
  3807			 * port type-c and the spec does not clearly say whether PD is
  3808			 * possible when type-c is connected to Type-A/B
  3809			 */
  3810			break;
  3811		case SRC_WAIT_NEW_CAPABILITIES:
  3812			/* Nothing to do... */
  3813			break;
  3814	
  3815		/* SNK states */
  3816		case SNK_UNATTACHED:
  3817			if (!port->non_pd_role_swap)
  3818				tcpm_swap_complete(port, -ENOTCONN);
  3819			tcpm_pps_complete(port, -ENOTCONN);
  3820			tcpm_snk_detach(port);
  3821			if (port->debouncing) {
  3822				port->debouncing = false;
  3823				if (port->tcpc->check_contaminant &&
  3824				    port->tcpc->check_contaminant(port->tcpc)) {
  3825					/* Contaminant detection would handle toggling */
  3826					tcpm_set_state(port, TOGGLING, 0);
  3827					break;
  3828				}
  3829			}
  3830			if (tcpm_start_toggling(port, TYPEC_CC_RD)) {
  3831				tcpm_set_state(port, TOGGLING, 0);
  3832				break;
  3833			}
  3834			tcpm_set_cc(port, TYPEC_CC_RD);
  3835			if (port->port_type == TYPEC_PORT_DRP)
  3836				tcpm_set_state(port, SRC_UNATTACHED, PD_T_DRP_SRC);
  3837			break;
  3838		case SNK_ATTACH_WAIT:
  3839			port->debouncing = true;
  3840			if ((port->cc1 == TYPEC_CC_OPEN &&
  3841			     port->cc2 != TYPEC_CC_OPEN) ||
  3842			    (port->cc1 != TYPEC_CC_OPEN &&
  3843			     port->cc2 == TYPEC_CC_OPEN))
  3844				tcpm_set_state(port, SNK_DEBOUNCED,
  3845					       PD_T_CC_DEBOUNCE);
  3846			else if (tcpm_port_is_disconnected(port))
  3847				tcpm_set_state(port, SNK_UNATTACHED,
  3848					       PD_T_PD_DEBOUNCE);
  3849			break;
  3850		case SNK_DEBOUNCED:
  3851			if (tcpm_port_is_disconnected(port)) {
  3852				tcpm_set_state(port, SNK_UNATTACHED,
  3853					       PD_T_PD_DEBOUNCE);
  3854			} else if (port->vbus_present) {
  3855				tcpm_set_state(port,
  3856					       tcpm_try_src(port) ? SRC_TRY
  3857								  : SNK_ATTACHED,
  3858					       0);
  3859				port->debouncing = false;
  3860			} else {
  3861				/* Wait for VBUS, but not forever */
  3862				tcpm_set_state(port, PORT_RESET, PD_T_PS_SOURCE_ON);
  3863				port->debouncing = false;
  3864			}
  3865			break;
  3866	
  3867		case SRC_TRY:
  3868			port->try_src_count++;
  3869			tcpm_set_cc(port, tcpm_rp_cc(port));
  3870			port->max_wait = 0;
  3871			tcpm_set_state(port, SRC_TRY_WAIT, 0);
  3872			break;
  3873		case SRC_TRY_WAIT:
  3874			if (port->max_wait == 0) {
  3875				port->max_wait = jiffies +
  3876						 msecs_to_jiffies(PD_T_DRP_TRY);
  3877				msecs = PD_T_DRP_TRY;
  3878			} else {
  3879				if (time_is_after_jiffies(port->max_wait))
  3880					msecs = jiffies_to_msecs(port->max_wait -
  3881								 jiffies);
  3882				else
  3883					msecs = 0;
  3884			}
  3885			tcpm_set_state(port, SNK_TRYWAIT, msecs);
  3886			break;
  3887		case SRC_TRY_DEBOUNCE:
  3888			tcpm_set_state(port, SRC_ATTACHED, PD_T_PD_DEBOUNCE);
  3889			break;
  3890		case SNK_TRYWAIT:
  3891			tcpm_set_cc(port, TYPEC_CC_RD);
  3892			tcpm_set_state(port, SNK_TRYWAIT_VBUS, PD_T_CC_DEBOUNCE);
  3893			break;
  3894		case SNK_TRYWAIT_VBUS:
  3895			/*
  3896			 * TCPM stays in this state indefinitely until VBUS
  3897			 * is detected as long as Rp is not detected for
  3898			 * more than a time period of tPDDebounce.
  3899			 */
  3900			if (port->vbus_present && tcpm_port_is_sink(port)) {
  3901				tcpm_set_state(port, SNK_ATTACHED, 0);
  3902				break;
  3903			}
  3904			if (!tcpm_port_is_sink(port))
  3905				tcpm_set_state(port, SNK_TRYWAIT_DEBOUNCE, 0);
  3906			break;
  3907		case SNK_TRYWAIT_DEBOUNCE:
  3908			tcpm_set_state(port, SNK_UNATTACHED, PD_T_PD_DEBOUNCE);
  3909			break;
  3910		case SNK_ATTACHED:
  3911			ret = tcpm_snk_attach(port);
  3912			if (ret < 0)
  3913				tcpm_set_state(port, SNK_UNATTACHED, 0);
  3914			else
  3915				tcpm_set_state(port, SNK_STARTUP, 0);
  3916			break;
  3917		case SNK_STARTUP:
  3918			opmode =  tcpm_get_pwr_opmode(port->polarity ?
  3919						      port->cc2 : port->cc1);
  3920			typec_set_pwr_opmode(port->typec_port, opmode);
  3921			port->pwr_opmode = TYPEC_PWR_MODE_USB;
  3922			port->negotiated_rev = PD_MAX_REV;
  3923			port->svdm_version = SVDM_MAX_VER;
  3924			port->message_id = 0;
  3925			port->rx_msgid = -1;
  3926			port->explicit_contract = false;
  3927	
  3928			if (port->ams == POWER_ROLE_SWAP ||
  3929			    port->ams == FAST_ROLE_SWAP)
  3930				/* SRC -> SNK POWER/FAST_ROLE_SWAP finished */
  3931				tcpm_ams_finish(port);
  3932	
  3933			tcpm_set_state(port, SNK_DISCOVERY, 500);
  3934			break;
  3935		case SNK_DISCOVERY:
  3936			if (port->vbus_present) {
  3937				if (port->psnkstdby_after_accept || tcpm_get_current_limit(port) <=
  3938				    PD_P_SNK_STDBY_5V)
  3939					tcpm_set_current_limit(port, tcpm_get_current_limit(port), 5000);
  3940				else
  3941					tcpm_set_current_limit(port, PD_P_SNK_STDBY_5V, 5000);
  3942				tcpm_set_charge(port, true);
  3943				tcpm_set_state(port, SNK_WAIT_CAPABILITIES, 0);
  3944				break;
  3945			}
  3946			/*
  3947			 * For DRP, timeouts differ. Also, handling is supposed to be
  3948			 * different and much more complex (dead battery detection;
  3949			 * see USB power delivery specification, section 8.3.3.6.1.5.1).
  3950			 */
  3951			tcpm_set_state(port, hard_reset_state(port),
  3952				       port->port_type == TYPEC_PORT_DRP ?
  3953						PD_T_DB_DETECT : PD_T_NO_RESPONSE);
  3954			break;
  3955		case SNK_DISCOVERY_DEBOUNCE:
  3956			tcpm_set_state(port, SNK_DISCOVERY_DEBOUNCE_DONE,
  3957				       PD_T_CC_DEBOUNCE);
  3958			break;
  3959		case SNK_DISCOVERY_DEBOUNCE_DONE:
  3960			if (!tcpm_port_is_disconnected(port) &&
  3961			    tcpm_port_is_sink(port) &&
  3962			    ktime_after(port->delayed_runtime, ktime_get())) {
  3963				tcpm_set_state(port, SNK_DISCOVERY,
  3964					       ktime_to_ms(ktime_sub(port->delayed_runtime, ktime_get())));
  3965				break;
  3966			}
  3967			tcpm_set_state(port, unattached_state(port), 0);
  3968			break;
  3969		case SNK_WAIT_CAPABILITIES:
  3970			ret = port->tcpc->set_pd_rx(port->tcpc, true);
  3971			if (ret < 0) {
  3972				tcpm_set_state(port, SNK_READY, 0);
  3973				break;
  3974			}
  3975			/*
  3976			 * If VBUS has never been low, and we time out waiting
  3977			 * for source cap, try a soft reset first, in case we
  3978			 * were already in a stable contract before this boot.
  3979			 * Do this only once.
  3980			 */
  3981			if (port->vbus_never_low) {
  3982				port->vbus_never_low = false;
  3983				tcpm_set_state(port, SNK_SOFT_RESET,
  3984					       PD_T_SINK_WAIT_CAP);
  3985			} else {
  3986				tcpm_set_state(port, hard_reset_state(port),
  3987					       PD_T_SINK_WAIT_CAP);
  3988			}
  3989			break;
  3990		case SNK_NEGOTIATE_CAPABILITIES:
  3991			tcpm_set_pd_capable(port, true);
  3992			port->usb_comm_capable = port->source_caps[0] &
  3993						 PDO_FIXED_USB_COMM;
  3994			/* Notify TCPC of usb_comm_capable. */
  3995			tcpm_set_attached_state(port, true);
  3996			port->hard_reset_count = 0;
  3997			ret = tcpm_pd_send_request(port);
  3998			if (ret < 0) {
  3999				/* Let the Source send capabilities again. */
  4000				tcpm_set_state(port, SNK_WAIT_CAPABILITIES, 0);
  4001			} else {
  4002				tcpm_set_state_cond(port, hard_reset_state(port),
  4003						    PD_T_SENDER_RESPONSE);
  4004			}
  4005			break;
  4006		case SNK_NEGOTIATE_PPS_CAPABILITIES:
  4007			ret = tcpm_pd_send_pps_request(port);
  4008			if (ret < 0) {
  4009				port->pps_status = ret;
  4010				/*
  4011				 * If this was called due to updates to sink
  4012				 * capabilities, and pps is no longer valid, we should
  4013				 * safely fall back to a standard PDO.
  4014				 */
  4015				if (port->update_sink_caps)
  4016					tcpm_set_state(port, SNK_NEGOTIATE_CAPABILITIES, 0);
  4017				else
  4018					tcpm_set_state(port, SNK_READY, 0);
  4019			} else {
  4020				tcpm_set_state_cond(port, hard_reset_state(port),
  4021						    PD_T_SENDER_RESPONSE);
  4022			}
  4023			break;
  4024		case SNK_TRANSITION_SINK:
> 4025			if (port->psnkstdby_after_accept)
  4026				tcpm_set_current_limit(port, tcpm_get_current_limit(port) >
  4027						       PD_P_SNK_STDBY_5V ? PD_P_SNK_STDBY_5V :
  4028						       tcpm_get_current_limit(port), 5000);
  4029		case SNK_TRANSITION_SINK_VBUS:
  4030			tcpm_set_state(port, hard_reset_state(port),
  4031				       PD_T_PS_TRANSITION);
  4032			break;
  4033		case SNK_READY:
  4034			port->try_snk_count = 0;
  4035			port->update_sink_caps = false;
  4036			if (port->explicit_contract) {
  4037				typec_set_pwr_opmode(port->typec_port,
  4038						     TYPEC_PWR_MODE_PD);
  4039				port->pwr_opmode = TYPEC_PWR_MODE_PD;
  4040			}
  4041	
  4042			/* Set current limit for NON-PD link when psnkstdby_after_accept is not set*/
  4043			if (!port->pd_capable && !port->psnkstdby_after_accept)
  4044				tcpm_set_current_limit(port, tcpm_get_current_limit(port), 5000);
  4045	
  4046			tcpm_swap_complete(port, 0);
  4047			tcpm_typec_connect(port);
  4048			tcpm_pps_complete(port, port->pps_status);
  4049	
  4050			if (port->ams != NONE_AMS)
  4051				tcpm_ams_finish(port);
  4052			if (port->next_ams != NONE_AMS) {
  4053				port->ams = port->next_ams;
  4054				port->next_ams = NONE_AMS;
  4055			}
  4056	
  4057			/*
  4058			 * If previous AMS is interrupted, switch to the upcoming
  4059			 * state.
  4060			 */
  4061			upcoming_state = port->upcoming_state;
  4062			if (port->upcoming_state != INVALID_STATE) {
  4063				port->upcoming_state = INVALID_STATE;
  4064				tcpm_set_state(port, upcoming_state, 0);
  4065				break;
  4066			}
  4067			tcpm_check_send_discover(port);
  4068			power_supply_changed(port->psy);
  4069	
  4070			break;
  4071	
  4072		/* Accessory states */
  4073		case ACC_UNATTACHED:
  4074			tcpm_acc_detach(port);
  4075			tcpm_set_state(port, SRC_UNATTACHED, 0);
  4076			break;
  4077		case DEBUG_ACC_ATTACHED:
  4078		case AUDIO_ACC_ATTACHED:
  4079			ret = tcpm_acc_attach(port);
  4080			if (ret < 0)
  4081				tcpm_set_state(port, ACC_UNATTACHED, 0);
  4082			break;
  4083		case AUDIO_ACC_DEBOUNCE:
  4084			tcpm_set_state(port, ACC_UNATTACHED, PD_T_CC_DEBOUNCE);
  4085			break;
  4086	
  4087		/* Hard_Reset states */
  4088		case HARD_RESET_SEND:
  4089			if (port->ams != NONE_AMS)
  4090				tcpm_ams_finish(port);
  4091			/*
  4092			 * State machine will be directed to HARD_RESET_START,
  4093			 * thus set upcoming_state to INVALID_STATE.
  4094			 */
  4095			port->upcoming_state = INVALID_STATE;
  4096			tcpm_ams_start(port, HARD_RESET);
  4097			break;
  4098		case HARD_RESET_START:
  4099			port->hard_reset_count++;
  4100			port->tcpc->set_pd_rx(port->tcpc, false);
  4101			tcpm_unregister_altmodes(port);
  4102			port->send_discover = true;
  4103			port->usb_comm_capable = false;
  4104			if (port->pwr_role == TYPEC_SOURCE)
  4105				tcpm_set_state(port, SRC_HARD_RESET_VBUS_OFF,
  4106					       PD_T_PS_HARD_RESET);
  4107			else
  4108				tcpm_set_state(port, SNK_HARD_RESET_SINK_OFF, 0);
  4109			break;
  4110		case SRC_HARD_RESET_VBUS_OFF:
  4111			/*
  4112			 * 7.1.5 Response to Hard Resets
  4113			 * Hard Reset Signaling indicates a communication failure has occurred and the
  4114			 * Source Shall stop driving VCONN, Shall remove Rp from the VCONN pin and Shall
  4115			 * drive VBUS to vSafe0V as shown in Figure 7-9.
  4116			 */
  4117			tcpm_set_vconn(port, false);
  4118			tcpm_set_vbus(port, false);
  4119			tcpm_set_roles(port, port->self_powered, TYPEC_SOURCE,
  4120				       tcpm_data_role_for_source(port));
  4121			/*
  4122			 * If tcpc fails to notify vbus off, TCPM will wait for PD_T_SAFE_0V +
  4123			 * PD_T_SRC_RECOVER before turning vbus back on.
  4124			 * From Table 7-12 Sequence Description for a Source Initiated Hard Reset:
  4125			 * 4. Policy Engine waits tPSHardReset after sending Hard Reset Signaling and then
  4126			 * tells the Device Policy Manager to instruct the power supply to perform a
  4127			 * Hard Reset. The transition to vSafe0V Shall occur within tSafe0V (t2).
  4128			 * 5. After tSrcRecover the Source applies power to VBUS in an attempt to
  4129			 * re-establish communication with the Sink and resume USB Default Operation.
  4130			 * The transition to vSafe5V Shall occur within tSrcTurnOn(t4).
  4131			 */
  4132			tcpm_set_state(port, SRC_HARD_RESET_VBUS_ON, PD_T_SAFE_0V + PD_T_SRC_RECOVER);
  4133			break;
  4134		case SRC_HARD_RESET_VBUS_ON:
  4135			tcpm_set_vconn(port, true);
  4136			tcpm_set_vbus(port, true);
  4137			if (port->ams == HARD_RESET)
  4138				tcpm_ams_finish(port);
  4139			port->tcpc->set_pd_rx(port->tcpc, true);
  4140			tcpm_set_attached_state(port, true);
  4141			tcpm_set_state(port, SRC_UNATTACHED, PD_T_PS_SOURCE_ON);
  4142			break;
  4143		case SNK_HARD_RESET_SINK_OFF:
  4144			memset(&port->pps_data, 0, sizeof(port->pps_data));
  4145			tcpm_set_vconn(port, false);
  4146			if (port->pd_capable)
  4147				tcpm_set_charge(port, false);
  4148			tcpm_set_roles(port, port->self_powered, TYPEC_SINK,
  4149				       tcpm_data_role_for_sink(port));
  4150			/*
  4151			 * VBUS may or may not toggle, depending on the adapter.
  4152			 * If it doesn't toggle, transition to SNK_HARD_RESET_SINK_ON
  4153			 * directly after timeout.
  4154			 */
  4155			tcpm_set_state(port, SNK_HARD_RESET_SINK_ON, PD_T_SAFE_0V);
  4156			break;
  4157		case SNK_HARD_RESET_WAIT_VBUS:
  4158			if (port->ams == HARD_RESET)
  4159				tcpm_ams_finish(port);
  4160			/* Assume we're disconnected if VBUS doesn't come back. */
  4161			tcpm_set_state(port, SNK_UNATTACHED,
  4162				       PD_T_SRC_RECOVER_MAX + PD_T_SRC_TURN_ON);
  4163			break;
  4164		case SNK_HARD_RESET_SINK_ON:
  4165			/* Note: There is no guarantee that VBUS is on in this state */
  4166			/*
  4167			 * XXX:
  4168			 * The specification suggests that dual mode ports in sink
  4169			 * mode should transition to state PE_SRC_Transition_to_default.
  4170			 * See USB power delivery specification chapter 8.3.3.6.1.3.
  4171			 * This would mean to to
  4172			 * - turn off VCONN, reset power supply
  4173			 * - request hardware reset
  4174			 * - turn on VCONN
  4175			 * - Transition to state PE_Src_Startup
  4176			 * SNK only ports shall transition to state Snk_Startup
  4177			 * (see chapter 8.3.3.3.8).
  4178			 * Similar, dual-mode ports in source mode should transition
  4179			 * to PE_SNK_Transition_to_default.
  4180			 */
  4181			if (port->pd_capable) {
  4182				tcpm_set_current_limit(port,
  4183						       tcpm_get_current_limit(port),
  4184						       5000);
  4185				tcpm_set_charge(port, true);
  4186			}
  4187			if (port->ams == HARD_RESET)
  4188				tcpm_ams_finish(port);
  4189			tcpm_set_attached_state(port, true);
  4190			tcpm_set_state(port, SNK_STARTUP, 0);
  4191			break;
  4192	
  4193		/* Soft_Reset states */
  4194		case SOFT_RESET:
  4195			port->message_id = 0;
  4196			port->rx_msgid = -1;
  4197			tcpm_pd_send_control(port, PD_CTRL_ACCEPT);
  4198			tcpm_ams_finish(port);
  4199			if (port->pwr_role == TYPEC_SOURCE) {
  4200				port->upcoming_state = SRC_SEND_CAPABILITIES;
  4201				tcpm_ams_start(port, POWER_NEGOTIATION);
  4202			} else {
  4203				tcpm_set_state(port, SNK_WAIT_CAPABILITIES, 0);
  4204			}
  4205			break;
  4206		case SRC_SOFT_RESET_WAIT_SNK_TX:
  4207		case SNK_SOFT_RESET:
  4208			if (port->ams != NONE_AMS)
  4209				tcpm_ams_finish(port);
  4210			port->upcoming_state = SOFT_RESET_SEND;
  4211			tcpm_ams_start(port, SOFT_RESET_AMS);
  4212			break;
  4213		case SOFT_RESET_SEND:
  4214			port->message_id = 0;
  4215			port->rx_msgid = -1;
  4216			if (tcpm_pd_send_control(port, PD_CTRL_SOFT_RESET))
  4217				tcpm_set_state_cond(port, hard_reset_state(port), 0);
  4218			else
  4219				tcpm_set_state_cond(port, hard_reset_state(port),
  4220						    PD_T_SENDER_RESPONSE);
  4221			break;
  4222	
  4223		/* DR_Swap states */
  4224		case DR_SWAP_SEND:
  4225			tcpm_pd_send_control(port, PD_CTRL_DR_SWAP);
  4226			tcpm_set_state_cond(port, DR_SWAP_SEND_TIMEOUT,
  4227					    PD_T_SENDER_RESPONSE);
  4228			break;
  4229		case DR_SWAP_ACCEPT:
  4230			tcpm_pd_send_control(port, PD_CTRL_ACCEPT);
  4231			/* Set VDM state machine running flag ASAP */
  4232			if (port->data_role == TYPEC_DEVICE && port->send_discover)
  4233				port->vdm_sm_running = true;
  4234			tcpm_set_state_cond(port, DR_SWAP_CHANGE_DR, 0);
  4235			break;
  4236		case DR_SWAP_SEND_TIMEOUT:
  4237			tcpm_swap_complete(port, -ETIMEDOUT);
  4238			tcpm_ams_finish(port);
  4239			tcpm_set_state(port, ready_state(port), 0);
  4240			break;
  4241		case DR_SWAP_CHANGE_DR:
  4242			if (port->data_role == TYPEC_HOST) {
  4243				tcpm_unregister_altmodes(port);
  4244				tcpm_set_roles(port, true, port->pwr_role,
  4245					       TYPEC_DEVICE);
  4246			} else {
  4247				tcpm_set_roles(port, true, port->pwr_role,
  4248					       TYPEC_HOST);
  4249				port->send_discover = true;
  4250			}
  4251			tcpm_ams_finish(port);
  4252			tcpm_set_state(port, ready_state(port), 0);
  4253			break;
  4254	
  4255		/* PR_Swap states */
  4256		case PR_SWAP_ACCEPT:
  4257			tcpm_pd_send_control(port, PD_CTRL_ACCEPT);
  4258			tcpm_set_state(port, PR_SWAP_START, 0);
  4259			break;
  4260		case PR_SWAP_SEND:
  4261			tcpm_pd_send_control(port, PD_CTRL_PR_SWAP);
  4262			tcpm_set_state_cond(port, PR_SWAP_SEND_TIMEOUT,
  4263					    PD_T_SENDER_RESPONSE);
  4264			break;
  4265		case PR_SWAP_SEND_TIMEOUT:
  4266			tcpm_swap_complete(port, -ETIMEDOUT);
  4267			tcpm_set_state(port, ready_state(port), 0);
  4268			break;
  4269		case PR_SWAP_START:
  4270			if (port->pwr_role == TYPEC_SOURCE)
  4271				tcpm_set_state(port, PR_SWAP_SRC_SNK_TRANSITION_OFF,
  4272					       PD_T_SRC_TRANSITION);
  4273			else
  4274				tcpm_set_state(port, PR_SWAP_SNK_SRC_SINK_OFF, 0);
  4275			break;
  4276		case PR_SWAP_SRC_SNK_TRANSITION_OFF:
  4277			tcpm_set_vbus(port, false);
  4278			port->explicit_contract = false;
  4279			/* allow time for Vbus discharge, must be < tSrcSwapStdby */
  4280			tcpm_set_state(port, PR_SWAP_SRC_SNK_SOURCE_OFF,
  4281				       PD_T_SRCSWAPSTDBY);
  4282			break;
  4283		case PR_SWAP_SRC_SNK_SOURCE_OFF:
  4284			tcpm_set_cc(port, TYPEC_CC_RD);
  4285			/* allow CC debounce */
  4286			tcpm_set_state(port, PR_SWAP_SRC_SNK_SOURCE_OFF_CC_DEBOUNCED,
  4287				       PD_T_CC_DEBOUNCE);
  4288			break;
  4289		case PR_SWAP_SRC_SNK_SOURCE_OFF_CC_DEBOUNCED:
  4290			/*
  4291			 * USB-PD standard, 6.2.1.4, Port Power Role:
  4292			 * "During the Power Role Swap Sequence, for the initial Source
  4293			 * Port, the Port Power Role field shall be set to Sink in the
  4294			 * PS_RDY Message indicating that the initial Source’s power
  4295			 * supply is turned off"
  4296			 */
  4297			tcpm_set_pwr_role(port, TYPEC_SINK);
  4298			if (tcpm_pd_send_control(port, PD_CTRL_PS_RDY)) {
  4299				tcpm_set_state(port, ERROR_RECOVERY, 0);
  4300				break;
  4301			}
  4302			tcpm_set_state(port, ERROR_RECOVERY, PD_T_PS_SOURCE_ON_PRS);
  4303			break;
  4304		case PR_SWAP_SRC_SNK_SINK_ON:
  4305			tcpm_set_state(port, SNK_STARTUP, 0);
  4306			break;
  4307		case PR_SWAP_SNK_SRC_SINK_OFF:
  4308			tcpm_set_charge(port, false);
  4309			tcpm_set_state(port, hard_reset_state(port),
  4310				       PD_T_PS_SOURCE_OFF);
  4311			break;
  4312		case PR_SWAP_SNK_SRC_SOURCE_ON:
  4313			tcpm_set_cc(port, tcpm_rp_cc(port));
  4314			tcpm_set_vbus(port, true);
  4315			/*
  4316			 * allow time VBUS ramp-up, must be < tNewSrc
  4317			 * Also, this window overlaps with CC debounce as well.
  4318			 * So, Wait for the max of two which is PD_T_NEWSRC
  4319			 */
  4320			tcpm_set_state(port, PR_SWAP_SNK_SRC_SOURCE_ON_VBUS_RAMPED_UP,
  4321				       PD_T_NEWSRC);
  4322			break;
  4323		case PR_SWAP_SNK_SRC_SOURCE_ON_VBUS_RAMPED_UP:
  4324			/*
  4325			 * USB PD standard, 6.2.1.4:
  4326			 * "Subsequent Messages initiated by the Policy Engine,
  4327			 * such as the PS_RDY Message sent to indicate that Vbus
  4328			 * is ready, will have the Port Power Role field set to
  4329			 * Source."
  4330			 */
  4331			tcpm_set_pwr_role(port, TYPEC_SOURCE);
  4332			tcpm_pd_send_control(port, PD_CTRL_PS_RDY);
  4333			tcpm_set_state(port, SRC_STARTUP, PD_T_SWAP_SRC_START);
  4334			break;
  4335	
  4336		case VCONN_SWAP_ACCEPT:
  4337			tcpm_pd_send_control(port, PD_CTRL_ACCEPT);
  4338			tcpm_ams_finish(port);
  4339			tcpm_set_state(port, VCONN_SWAP_START, 0);
  4340			break;
  4341		case VCONN_SWAP_SEND:
  4342			tcpm_pd_send_control(port, PD_CTRL_VCONN_SWAP);
  4343			tcpm_set_state(port, VCONN_SWAP_SEND_TIMEOUT,
  4344				       PD_T_SENDER_RESPONSE);
  4345			break;
  4346		case VCONN_SWAP_SEND_TIMEOUT:
  4347			tcpm_swap_complete(port, -ETIMEDOUT);
  4348			if (port->data_role == TYPEC_HOST && port->send_discover)
  4349				port->vdm_sm_running = true;
  4350			tcpm_set_state(port, ready_state(port), 0);
  4351			break;
  4352		case VCONN_SWAP_START:
  4353			if (port->vconn_role == TYPEC_SOURCE)
  4354				tcpm_set_state(port, VCONN_SWAP_WAIT_FOR_VCONN, 0);
  4355			else
  4356				tcpm_set_state(port, VCONN_SWAP_TURN_ON_VCONN, 0);
  4357			break;
  4358		case VCONN_SWAP_WAIT_FOR_VCONN:
  4359			tcpm_set_state(port, hard_reset_state(port),
  4360				       PD_T_VCONN_SOURCE_ON);
  4361			break;
  4362		case VCONN_SWAP_TURN_ON_VCONN:
  4363			tcpm_set_vconn(port, true);
  4364			tcpm_pd_send_control(port, PD_CTRL_PS_RDY);
  4365			if (port->data_role == TYPEC_HOST && port->send_discover)
  4366				port->vdm_sm_running = true;
  4367			tcpm_set_state(port, ready_state(port), 0);
  4368			break;
  4369		case VCONN_SWAP_TURN_OFF_VCONN:
  4370			tcpm_set_vconn(port, false);
  4371			if (port->data_role == TYPEC_HOST && port->send_discover)
  4372				port->vdm_sm_running = true;
  4373			tcpm_set_state(port, ready_state(port), 0);
  4374			break;
  4375	
  4376		case DR_SWAP_CANCEL:
  4377		case PR_SWAP_CANCEL:
  4378		case VCONN_SWAP_CANCEL:
  4379			tcpm_swap_complete(port, port->swap_status);
  4380			if (port->data_role == TYPEC_HOST && port->send_discover)
  4381				port->vdm_sm_running = true;
  4382			if (port->pwr_role == TYPEC_SOURCE)
  4383				tcpm_set_state(port, SRC_READY, 0);
  4384			else
  4385				tcpm_set_state(port, SNK_READY, 0);
  4386			break;
  4387	
  4388		case BIST_RX:
  4389			switch (BDO_MODE_MASK(port->bist_request)) {
  4390			case BDO_MODE_CARRIER2:
  4391				tcpm_pd_transmit(port, TCPC_TX_BIST_MODE_2, NULL);
  4392				tcpm_set_state(port, unattached_state(port),
  4393					       PD_T_BIST_CONT_MODE);
  4394				break;
  4395			case BDO_MODE_TESTDATA:
  4396				if (port->tcpc->set_bist_data) {
  4397					tcpm_log(port, "Enable BIST MODE TESTDATA");
  4398					port->tcpc->set_bist_data(port->tcpc, true);
  4399				}
  4400				break;
  4401			default:
  4402				break;
  4403			}
  4404			break;
  4405		case GET_STATUS_SEND:
  4406			tcpm_pd_send_control(port, PD_CTRL_GET_STATUS);
  4407			tcpm_set_state(port, GET_STATUS_SEND_TIMEOUT,
  4408				       PD_T_SENDER_RESPONSE);
  4409			break;
  4410		case GET_STATUS_SEND_TIMEOUT:
  4411			tcpm_set_state(port, ready_state(port), 0);
  4412			break;
  4413		case GET_PPS_STATUS_SEND:
  4414			tcpm_pd_send_control(port, PD_CTRL_GET_PPS_STATUS);
  4415			tcpm_set_state(port, GET_PPS_STATUS_SEND_TIMEOUT,
  4416				       PD_T_SENDER_RESPONSE);
  4417			break;
  4418		case GET_PPS_STATUS_SEND_TIMEOUT:
  4419			tcpm_set_state(port, ready_state(port), 0);
  4420			break;
  4421		case ERROR_RECOVERY:
  4422			tcpm_swap_complete(port, -EPROTO);
  4423			tcpm_pps_complete(port, -EPROTO);
  4424			tcpm_set_state(port, PORT_RESET, 0);
  4425			break;
  4426		case PORT_RESET:
  4427			tcpm_reset_port(port);
  4428			tcpm_set_cc(port, TYPEC_CC_OPEN);
  4429			tcpm_set_state(port, PORT_RESET_WAIT_OFF,
  4430				       PD_T_ERROR_RECOVERY);
  4431			break;
  4432		case PORT_RESET_WAIT_OFF:
  4433			tcpm_set_state(port,
  4434				       tcpm_default_state(port),
  4435				       port->vbus_present ? PD_T_PS_SOURCE_OFF : 0);
  4436			break;
  4437	
  4438		/* AMS intermediate state */
  4439		case AMS_START:
  4440			if (port->upcoming_state == INVALID_STATE) {
  4441				tcpm_set_state(port, port->pwr_role == TYPEC_SOURCE ?
  4442					       SRC_READY : SNK_READY, 0);
  4443				break;
  4444			}
  4445	
  4446			upcoming_state = port->upcoming_state;
  4447			port->upcoming_state = INVALID_STATE;
  4448			tcpm_set_state(port, upcoming_state, 0);
  4449			break;
  4450	
  4451		/* Chunk state */
  4452		case CHUNK_NOT_SUPP:
  4453			tcpm_pd_send_control(port, PD_CTRL_NOT_SUPP);
  4454			tcpm_set_state(port, port->pwr_role == TYPEC_SOURCE ?
  4455				       SRC_READY : SNK_READY, 0);
  4456			break;
  4457		default:
  4458			WARN(1, "Unexpected port state %d\n", port->state);
  4459			break;
  4460		}
  4461	}
  4462	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 32622 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-08  2:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-08  2:46 [android-common:mirror-pa-android12-5.10-staging 1622/1718] drivers/usb/typec/tcpm/tcpm.c:4025:6: warning: this statement may fall through kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.