Skip to content

Commit 49670e2

Browse files
author
zhuyi
committed
Add Retimer FW status get/set command
1 parent 2da8466 commit 49670e2

File tree

5 files changed

+205
-0
lines changed

5 files changed

+205
-0
lines changed

embedded-service/src/type_c/controller.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ pub enum PortCommandData {
9292
PortStatus,
9393
/// Get and clear events
9494
ClearEvents,
95+
/// Get retimer fw update state
96+
RetimerFwUpdateGetState,
97+
/// Set retimer fw update state
98+
RetimerFwUpdateSetState,
99+
/// Clear retimer fw update state
100+
RetimerFwUpdateClearState,
95101
}
96102

97103
/// Port-specific commands
@@ -114,6 +120,10 @@ pub enum PortResponseData {
114120
PortStatus(PortStatus),
115121
/// ClearEvents
116122
ClearEvents(PortEventKind),
123+
/// Retimer Fw Update status
124+
RtFwUpdateStatus(bool),
125+
/// Retimer Fw Update set state success with no error
126+
RtFwUpdateSetState,
117127
}
118128

119129
impl PortResponseData {
@@ -319,6 +329,18 @@ pub trait Controller {
319329
/// Returns the port status
320330
fn get_port_status(&mut self, port: LocalPortId)
321331
-> impl Future<Output = Result<PortStatus, Error<Self::BusError>>>;
332+
/// Returns the retimer fw update state
333+
fn get_rt_fw_update_status(
334+
&mut self,
335+
port: LocalPortId,
336+
) -> impl Future<Output = Result<bool, Error<Self::BusError>>>;
337+
/// Set retimer fw update state
338+
fn set_rt_fw_update_state(&mut self, port: LocalPortId) -> impl Future<Output = Result<(), Error<Self::BusError>>>;
339+
/// Clear retimer fw update state
340+
fn clear_rt_fw_update_state(
341+
&mut self,
342+
port: LocalPortId,
343+
) -> impl Future<Output = Result<(), Error<Self::BusError>>>;
322344
/// Enable or disable sink path
323345
fn enable_sink_path(
324346
&mut self,
@@ -589,6 +611,39 @@ impl ContextToken {
589611
}
590612
}
591613

614+
/// Get the retimer fw update status
615+
pub async fn get_rt_fw_update_status(&self, port: GlobalPortId) -> Result<bool, PdError> {
616+
match self
617+
.send_port_command(port, PortCommandData::RetimerFwUpdateGetState, DEFAULT_TIMEOUT)
618+
.await?
619+
{
620+
PortResponseData::RtFwUpdateStatus(status) => Ok(status),
621+
_ => Err(PdError::InvalidResponse),
622+
}
623+
}
624+
625+
/// Set the retimer fw update state
626+
pub async fn set_rt_fw_update_state(&self, port: GlobalPortId) -> Result<(), PdError> {
627+
match self
628+
.send_port_command(port, PortCommandData::RetimerFwUpdateSetState, DEFAULT_TIMEOUT)
629+
.await?
630+
{
631+
PortResponseData::RtFwUpdateSetState => Ok(()),
632+
_ => Err(PdError::InvalidResponse),
633+
}
634+
}
635+
636+
/// Clear the retimer fw update state
637+
pub async fn clear_rt_fw_update_state(&self, port: GlobalPortId) -> Result<(), PdError> {
638+
match self
639+
.send_port_command(port, PortCommandData::RetimerFwUpdateClearState, DEFAULT_TIMEOUT)
640+
.await?
641+
{
642+
PortResponseData::RtFwUpdateSetState => Ok(()),
643+
_ => Err(PdError::InvalidResponse),
644+
}
645+
}
646+
592647
/// Get current controller status
593648
pub async fn get_controller_status(
594649
&self,

embedded-service/src/type_c/external.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ pub type ControllerResponse<'a> = Result<ControllerResponseData<'a>, PdError>;
4444
pub enum PortCommandData {
4545
/// Get port status
4646
PortStatus,
47+
/// Get retimer fw update status
48+
RetimerFwUpdateGetState,
49+
/// Set retimer fw update status
50+
RetimerFwUpdateSetState,
51+
/// Clear retimer fw update status
52+
RetimerFwUpdateClearState,
4753
}
4854

4955
/// Port-specific commands
@@ -62,6 +68,12 @@ pub struct PortCommand {
6268
pub enum PortResponseData {
6369
/// Get port status
6470
PortStatus(PortStatus),
71+
/// Get retimer fw update status
72+
RetimerFwUpdateGetState(bool),
73+
/// Set retimer fw update status
74+
RetimerFwUpdateSetState,
75+
/// Clear retimer fw update status
76+
RetimerFwUpdateClearState,
6577
}
6678

6779
/// Port-specific command response
@@ -133,3 +145,45 @@ pub async fn controller_port_to_global_id(
133145
) -> Result<GlobalPortId, PdError> {
134146
lookup_controller(controller_id).await?.lookup_global_port(port_id)
135147
}
148+
149+
/// Get the retimer fw update status of the given port
150+
#[allow(unreachable_patterns)]
151+
pub async fn port_get_rt_fw_update_status(port: GlobalPortId) -> Result<bool, PdError> {
152+
match execute_external_port_command(Command::Port(PortCommand {
153+
port,
154+
data: PortCommandData::RetimerFwUpdateGetState,
155+
}))
156+
.await?
157+
{
158+
PortResponseData::RetimerFwUpdateGetState(status) => Ok(status),
159+
_ => Err(PdError::InvalidResponse),
160+
}
161+
}
162+
163+
/// Set the retimer fw update state of the given port
164+
#[allow(unreachable_patterns)]
165+
pub async fn port_set_rt_fw_update_state(port: GlobalPortId) -> Result<(), PdError> {
166+
match execute_external_port_command(Command::Port(PortCommand {
167+
port,
168+
data: PortCommandData::RetimerFwUpdateSetState,
169+
}))
170+
.await?
171+
{
172+
PortResponseData::RetimerFwUpdateSetState => Ok(()),
173+
_ => Err(PdError::InvalidResponse),
174+
}
175+
}
176+
177+
/// Clear the retimer fw update state of the given port
178+
#[allow(unreachable_patterns)]
179+
pub async fn port_clear_rt_fw_update_state(port: GlobalPortId) -> Result<(), PdError> {
180+
match execute_external_port_command(Command::Port(PortCommand {
181+
port,
182+
data: PortCommandData::RetimerFwUpdateSetState,
183+
}))
184+
.await?
185+
{
186+
PortResponseData::RetimerFwUpdateClearState => Ok(()),
187+
_ => Err(PdError::InvalidResponse),
188+
}
189+
}

type-c-service/src/driver/tps6699x.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,24 @@ impl<const N: usize, M: RawMutex, B: I2c> Controller for Tps6699x<'_, N, M, B> {
259259
Ok(self.port_status[port.0 as usize].get())
260260
}
261261

262+
#[allow(clippy::await_holding_refcell_ref)]
263+
async fn get_rt_fw_update_status(&mut self, port: LocalPortId) -> Result<bool, Error<Self::BusError>> {
264+
let mut tps6699x = self.tps6699x.borrow_mut();
265+
tps6699x.get_rt_fw_update_status(port).await
266+
}
267+
268+
#[allow(clippy::await_holding_refcell_ref)]
269+
async fn set_rt_fw_update_state(&mut self, port: LocalPortId) -> Result<(), Error<Self::BusError>> {
270+
let mut tps6699x = self.tps6699x.borrow_mut();
271+
tps6699x.set_rt_fw_update_state(port).await
272+
}
273+
274+
#[allow(clippy::await_holding_refcell_ref)]
275+
async fn clear_rt_fw_update_state(&mut self, port: LocalPortId) -> Result<(), Error<Self::BusError>> {
276+
let mut tps6699x = self.tps6699x.borrow_mut();
277+
tps6699x.clear_rt_fw_update_state(port).await
278+
}
279+
262280
#[allow(clippy::await_holding_refcell_ref)]
263281
async fn enable_sink_path(&mut self, port: LocalPortId, enable: bool) -> Result<(), Error<Self::BusError>> {
264282
debug!("Port{} enable sink path: {}", port.0, enable);

type-c-service/src/task.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,62 @@ impl Service {
151151
.await;
152152
}
153153

154+
/// Process get retimer fw update status commands
155+
async fn process_get_rt_fw_update_status(&self, port_id: GlobalPortId) {
156+
let status = self.context.get_rt_fw_update_status(port_id).await;
157+
if let Err(e) = status {
158+
error!("Error getting retimer fw update status: {:#?}", e);
159+
}
160+
161+
self.context
162+
.send_external_response(external::Response::Port(
163+
status.map(external::PortResponseData::RetimerFwUpdateGetState),
164+
))
165+
.await;
166+
}
167+
168+
/// Process set retimer fw update state commands
169+
async fn process_set_rt_fw_update_state(&self, port_id: GlobalPortId) {
170+
let status = self.context.set_rt_fw_update_state(port_id).await;
171+
if let Err(e) = status {
172+
error!("Error setting retimer fw update state: {:#?}", e);
173+
}
174+
175+
self.context
176+
.send_external_response(external::Response::Port(
177+
status.map(|_| external::PortResponseData::RetimerFwUpdateSetState),
178+
))
179+
.await;
180+
}
181+
182+
/// Process clear retimer fw update state commands
183+
async fn process_clear_rt_fw_update_state(&self, port_id: GlobalPortId) {
184+
let status = self.context.clear_rt_fw_update_state(port_id).await;
185+
if let Err(e) = status {
186+
error!("Error clear retimer fw update state: {:#?}", e);
187+
}
188+
189+
self.context
190+
.send_external_response(external::Response::Port(
191+
status.map(|_| external::PortResponseData::RetimerFwUpdateClearState),
192+
))
193+
.await;
194+
}
195+
154196
/// Process external port commands
155197
async fn process_external_port_command(&self, command: external::PortCommand) {
156198
debug!("Processing external port command: {:#?}", command);
157199
match command.data {
158200
external::PortCommandData::PortStatus => self.process_external_port_status(command.port).await,
201+
external::PortCommandData::RetimerFwUpdateGetState => {
202+
self.process_get_rt_fw_update_status(command.port).await
203+
}
204+
external::PortCommandData::RetimerFwUpdateSetState => {
205+
self.process_set_rt_fw_update_state(command.port).await
206+
}
207+
external::PortCommandData::RetimerFwUpdateClearState => {
208+
self.process_clear_rt_fw_update_state(command.port).await
209+
}
159210
}
160211
}
161212

type-c-service/src/wrapper/pd.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,33 @@ impl<const N: usize, C: Controller> ControllerWrapper<'_, N, C> {
2828
self.active_events[0].set(PortEventKind::none());
2929
Ok(controller::PortResponseData::ClearEvents(event))
3030
}
31+
controller::PortCommandData::RetimerFwUpdateGetState => {
32+
match controller.get_rt_fw_update_status(local_port).await {
33+
Ok(status) => Ok(controller::PortResponseData::RtFwUpdateStatus(status)),
34+
Err(e) => match e {
35+
Error::Bus(_) => Err(PdError::Failed),
36+
Error::Pd(e) => Err(e),
37+
},
38+
}
39+
}
40+
controller::PortCommandData::RetimerFwUpdateSetState => {
41+
match controller.set_rt_fw_update_state(local_port).await {
42+
Ok(status) => Ok(controller::PortResponseData::RtFwUpdateSetState),
43+
Err(e) => match e {
44+
Error::Bus(_) => Err(PdError::Failed),
45+
Error::Pd(e) => Err(e),
46+
},
47+
}
48+
}
49+
controller::PortCommandData::RetimerFwUpdateClearState => {
50+
match controller.clear_rt_fw_update_state(local_port).await {
51+
Ok(status) => Ok(controller::PortResponseData::RtFwUpdateSetState),
52+
Err(e) => match e {
53+
Error::Bus(_) => Err(PdError::Failed),
54+
Error::Pd(e) => Err(e),
55+
},
56+
}
57+
}
3158
};
3259

3360
self.pd_controller

0 commit comments

Comments
 (0)