@@ -42,6 +42,9 @@ use crate::chromium_ec::commands::RebootEcCmd;
4242use crate :: chromium_ec:: commands:: RgbS ;
4343use crate :: chromium_ec:: commands:: TabletModeOverride ;
4444use crate :: chromium_ec:: commands:: EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED ;
45+ use crate :: chromium_ec:: commands:: {
46+ EC_DEBUG_KEYBOARD , EC_DEBUG_PD_UCSI , EC_DEBUG_PD_UCSI_TUNNEL_DIS , EC_DEBUG_PD_VERBOSE_MSG ,
47+ } ;
4548use crate :: chromium_ec:: commands:: { PORT_80_EVENT_RESET , PORT_80_EVENT_RESUME } ;
4649use crate :: chromium_ec:: EcResponseStatus ;
4750use crate :: chromium_ec:: Port80History ;
@@ -99,6 +102,24 @@ pub enum ConsoleArg {
99102 Follow ,
100103}
101104
105+ #[ cfg_attr( not( feature = "uefi" ) , derive( clap:: ValueEnum ) ) ]
106+ #[ derive( Clone , Debug , PartialEq ) ]
107+ pub enum PdDebugArg {
108+ Status ,
109+ Off ,
110+ Verbose ,
111+ Ucsi ,
112+ All ,
113+ }
114+
115+ #[ cfg_attr( not( feature = "uefi" ) , derive( clap:: ValueEnum ) ) ]
116+ #[ derive( Clone , Debug , PartialEq ) ]
117+ pub enum KbdDebugArg {
118+ Status ,
119+ Off ,
120+ On ,
121+ }
122+
102123#[ cfg_attr( not( feature = "uefi" ) , derive( clap:: ValueEnum ) ) ]
103124#[ derive( Clone , Debug , PartialEq ) ]
104125pub enum RebootEcArg {
@@ -207,6 +228,8 @@ pub struct Cli {
207228 pub pd_reset : Option < u8 > ,
208229 pub pd_disable : Option < u8 > ,
209230 pub pd_enable : Option < u8 > ,
231+ pub pd_debug : Option < PdDebugArg > ,
232+ pub kbd_debug : Option < KbdDebugArg > ,
210233 pub dp_hdmi_info : bool ,
211234 pub dp_hdmi_update : Option < String > ,
212235 pub audio_card_info : bool ,
@@ -308,6 +331,8 @@ pub fn parse(args: &[String]) -> Cli {
308331 // pd_reset
309332 // pd_disable
310333 // pd_enable
334+ // pd_debug
335+ // kbd_debug
311336 dp_hdmi_info : cli. dp_hdmi_info ,
312337 // dp_hdmi_update
313338 audio_card_info : cli. audio_card_info ,
@@ -1777,6 +1802,50 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
17771802 Ok ( ( ) )
17781803 }
17791804 } ) ;
1805+ } else if let Some ( pd_debug) = & args. pd_debug {
1806+ let ( set_mask, flags) = match pd_debug {
1807+ PdDebugArg :: Status => ( 0 , 0 ) ,
1808+ PdDebugArg :: Off => ( EC_DEBUG_PD_VERBOSE_MSG | EC_DEBUG_PD_UCSI , 0 ) ,
1809+ PdDebugArg :: Verbose => ( EC_DEBUG_PD_VERBOSE_MSG , EC_DEBUG_PD_VERBOSE_MSG ) ,
1810+ PdDebugArg :: Ucsi => ( EC_DEBUG_PD_UCSI , EC_DEBUG_PD_UCSI ) ,
1811+ PdDebugArg :: All => (
1812+ EC_DEBUG_PD_VERBOSE_MSG | EC_DEBUG_PD_UCSI ,
1813+ EC_DEBUG_PD_VERBOSE_MSG | EC_DEBUG_PD_UCSI ,
1814+ ) ,
1815+ } ;
1816+ match ec. debug_control ( set_mask, flags) {
1817+ Ok ( cur) => {
1818+ println ! ( "PD debug logging:" ) ;
1819+ println ! (
1820+ " Verbose: {}" ,
1821+ cur & EC_DEBUG_PD_VERBOSE_MSG != 0
1822+ ) ;
1823+ println ! ( " UCSI: {}" , cur & EC_DEBUG_PD_UCSI != 0 ) ;
1824+ println ! (
1825+ " UCSI tunnel disabled: {}" ,
1826+ cur & EC_DEBUG_PD_UCSI_TUNNEL_DIS != 0
1827+ ) ;
1828+ if cur & ( EC_DEBUG_PD_VERBOSE_MSG | EC_DEBUG_PD_UCSI ) != 0 {
1829+ println ! ( "Read the log output with --console follow" ) ;
1830+ }
1831+ }
1832+ Err ( err) => println ! ( "Failed to control PD debug logging: {:?}" , err) ,
1833+ }
1834+ } else if let Some ( kbd_debug) = & args. kbd_debug {
1835+ let ( set_mask, flags) = match kbd_debug {
1836+ KbdDebugArg :: Status => ( 0 , 0 ) ,
1837+ KbdDebugArg :: Off => ( EC_DEBUG_KEYBOARD , 0 ) ,
1838+ KbdDebugArg :: On => ( EC_DEBUG_KEYBOARD , EC_DEBUG_KEYBOARD ) ,
1839+ } ;
1840+ match ec. debug_control ( set_mask, flags) {
1841+ Ok ( cur) => {
1842+ println ! ( "Keyboard debug logging: {}" , cur & EC_DEBUG_KEYBOARD != 0 ) ;
1843+ if cur & EC_DEBUG_KEYBOARD != 0 {
1844+ println ! ( "Read the log output with --console follow" ) ;
1845+ }
1846+ }
1847+ Err ( err) => println ! ( "Failed to control keyboard debug logging: {:?}" , err) ,
1848+ }
17801849 } else if args. dp_hdmi_info {
17811850 #[ cfg( feature = "hidapi" ) ]
17821851 print_dp_hdmi_details ( true ) ;
@@ -2104,6 +2173,8 @@ Options:
21042173 Set the color of a key to RGB. Multiple colors for adjacent keys can be set at once
21052174 --tablet-mode <MODE> Set tablet mode override [possible values: auto, tablet, laptop]
21062175 --console <CONSOLE> Get EC console, choose whether recent or to follow the output [possible values: recent, follow]
2176+ --pd-debug <MODE> Get or set PD debug logging, read it via --console [possible values: status, off, verbose, ucsi, all]
2177+ --kbd-debug <MODE> Get or set keyboard controller debug logging, read it via --console [possible values: status, off, on]
21072178 --hash <HASH> Hash a file of arbitrary data
21082179 --flash-gpu-descriptor <MAGIC> <18 DIGIT SN> Overwrite the GPU bay descriptor SN and type.
21092180 --flash-gpu-descriptor-file <DESCRIPTOR_FILE> Write the GPU bay descriptor with a descriptor file.
0 commit comments