MLK-16013-24 staging: typec: tcpm: use hrtimer for send response
As the sender response timer have very small margin(25~30ms), so use a hrtimer to handle it. Reviewed-by: Peter Chen <peter.chen@nxp.com> Signed-off-by: Li Jun <jun.li@nxp.com>pull/10/head
parent
8e0d4bef56
commit
9cd3840e86
|
@ -19,6 +19,7 @@
|
|||
#include <linux/device.h>
|
||||
#include <linux/jiffies.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/ktime.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/proc_fs.h>
|
||||
|
@ -296,6 +297,9 @@ struct tcpm_port {
|
|||
/* Deadline in jiffies to exit src_try_wait state */
|
||||
unsigned long max_wait;
|
||||
|
||||
/* Send response timer */
|
||||
struct hrtimer snd_res_timer;
|
||||
|
||||
#ifdef CONFIG_DEBUG_FS
|
||||
struct dentry *dentry;
|
||||
struct mutex logbuffer_lock; /* log buffer access lock */
|
||||
|
@ -1332,6 +1336,7 @@ static void tcpm_pd_data_request(struct tcpm_port *port,
|
|||
break;
|
||||
}
|
||||
port->sink_request = le32_to_cpu(msg->payload[0]);
|
||||
hrtimer_cancel(&port->snd_res_timer);
|
||||
tcpm_set_state(port, SRC_NEGOTIATE_CAPABILITIES, 0);
|
||||
break;
|
||||
case PD_DATA_SINK_CAP:
|
||||
|
@ -1383,6 +1388,7 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,
|
|||
tcpm_queue_message(port, PD_MSG_DATA_SINK_CAP);
|
||||
break;
|
||||
default:
|
||||
hrtimer_cancel(&port->snd_res_timer);
|
||||
tcpm_set_state(port, SOFT_RESET_SEND, 0);
|
||||
break;
|
||||
}
|
||||
|
@ -1424,6 +1430,7 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,
|
|||
case PD_CTRL_WAIT:
|
||||
switch (port->state) {
|
||||
case SNK_NEGOTIATE_CAPABILITIES:
|
||||
hrtimer_cancel(&port->snd_res_timer);
|
||||
/* USB PD specification, Figure 8-43 */
|
||||
if (port->explicit_contract)
|
||||
next_state = SNK_READY;
|
||||
|
@ -1453,6 +1460,7 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,
|
|||
case PD_CTRL_ACCEPT:
|
||||
switch (port->state) {
|
||||
case SNK_NEGOTIATE_CAPABILITIES:
|
||||
hrtimer_cancel(&port->snd_res_timer);
|
||||
tcpm_set_state(port, SNK_TRANSITION_SINK, 0);
|
||||
break;
|
||||
case SOFT_RESET_SEND:
|
||||
|
@ -2219,6 +2227,16 @@ static enum typec_pwr_opmode tcpm_get_pwr_opmode(enum typec_cc_status cc)
|
|||
}
|
||||
}
|
||||
|
||||
static enum hrtimer_restart tcpm_sender_res_handle(struct hrtimer *data)
|
||||
{
|
||||
struct tcpm_port *port = container_of(data, struct tcpm_port,
|
||||
snd_res_timer);
|
||||
|
||||
tcpm_log_force(port, "Sender response timeout!");
|
||||
tcpm_set_state(port, HARD_RESET_SEND, 0);
|
||||
return HRTIMER_NORESTART;
|
||||
}
|
||||
|
||||
static void run_state_machine(struct tcpm_port *port)
|
||||
{
|
||||
int ret;
|
||||
|
@ -2351,8 +2369,9 @@ static void run_state_machine(struct tcpm_port *port)
|
|||
/* port->hard_reset_count = 0; */
|
||||
port->caps_count = 0;
|
||||
port->pd_capable = true;
|
||||
tcpm_set_state_cond(port, hard_reset_state(port),
|
||||
PD_T_SEND_SOURCE_CAP);
|
||||
hrtimer_start(&port->snd_res_timer,
|
||||
ms_to_ktime(PD_T_SENDER_RESPONSE),
|
||||
HRTIMER_MODE_REL);
|
||||
}
|
||||
break;
|
||||
case SRC_NEGOTIATE_CAPABILITIES:
|
||||
|
@ -2568,8 +2587,9 @@ static void run_state_machine(struct tcpm_port *port)
|
|||
/* Let the Source send capabilities again. */
|
||||
tcpm_set_state(port, SNK_WAIT_CAPABILITIES, 0);
|
||||
} else {
|
||||
tcpm_set_state_cond(port, hard_reset_state(port),
|
||||
PD_T_SENDER_RESPONSE);
|
||||
hrtimer_start(&port->snd_res_timer,
|
||||
ms_to_ktime(PD_T_SENDER_RESPONSE),
|
||||
HRTIMER_MODE_REL);
|
||||
}
|
||||
break;
|
||||
case SNK_TRANSITION_SINK:
|
||||
|
@ -3704,6 +3724,9 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)
|
|||
}
|
||||
}
|
||||
|
||||
hrtimer_init(&port->snd_res_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
|
||||
port->snd_res_timer.function = tcpm_sender_res_handle;
|
||||
|
||||
tcpm_debugfs_init(port);
|
||||
mutex_lock(&port->lock);
|
||||
tcpm_init(port);
|
||||
|
|
Loading…
Reference in New Issue