Fix code style
BUG=b:319124515
TEST=make local_tests && make um_ppm
Change-Id: Ib242a4ca70437c922119e164a27efccde475220c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/usb/um_ppm/+/5255581
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Abhishek Pandit-Subedi <abhishekpandit@google.com>
diff --git a/include/pd_driver.h b/include/pd_driver.h
index f4c84da..a8a8ee9 100644
--- a/include/pd_driver.h
+++ b/include/pd_driver.h
@@ -6,11 +6,11 @@
#ifndef UM_PPM_INCLUDE_PD_DRIVER_H_
#define UM_PPM_INCLUDE_PD_DRIVER_H_
+#include "include/ppm.h"
+
#include <stddef.h>
#include <stdint.h>
-#include "include/ppm.h"
-
/* Internal data structure for pd_driver implementations. */
struct ucsi_pd_device;
@@ -27,7 +27,7 @@
*
* @return 0 if IRQ is configured (or already configured). -1 on error.
*/
-typedef int(ucsi_pd_configure_lpm_irq)(struct ucsi_pd_device* dev);
+typedef int(ucsi_pd_configure_lpm_irq)(struct ucsi_pd_device *dev);
/**
* Initialize the PPM associated with this PD driver.
@@ -39,14 +39,14 @@
*
* @return 0 on success, -1 on error.
*/
-typedef int(ucsi_pd_init_ppm)(struct ucsi_pd_device* dev);
+typedef int(ucsi_pd_init_ppm)(struct ucsi_pd_device *dev);
/**
* Grab a pointer to the PPM.
*
* @param dev: Device object for this PD controller.
*/
-typedef struct ucsi_ppm_driver*(ucsi_pd_get_ppm)(struct ucsi_pd_device* dev);
+typedef struct ucsi_ppm_driver *(ucsi_pd_get_ppm)(struct ucsi_pd_device *dev);
/**
* Execute a command in the PPM.
@@ -62,16 +62,16 @@
*
* @returns -1 on error or the number of bytes read on success.
*/
-typedef int(ucsi_pd_execute_command)(struct ucsi_pd_device* dev,
- struct ucsi_control* control,
- uint8_t* lpm_data_out);
+typedef int(ucsi_pd_execute_command)(struct ucsi_pd_device *dev,
+ struct ucsi_control *control,
+ uint8_t *lpm_data_out);
/**
* Clean up the given PD driver. Call before freeing.
*
* @param driver: Driver object to clean up.
*/
-typedef void(ucsi_pd_cleanup)(struct ucsi_pd_driver* driver);
+typedef void(ucsi_pd_cleanup)(struct ucsi_pd_driver *driver);
/**
* General driver for PD controllers.
@@ -79,18 +79,18 @@
* When constructing, must be provided a PPM implementation.
*/
struct ucsi_pd_driver {
- struct ucsi_pd_device* dev;
+ struct ucsi_pd_device *dev;
- ucsi_pd_configure_lpm_irq* configure_lpm_irq;
- ucsi_pd_init_ppm* init_ppm;
- ucsi_pd_get_ppm* get_ppm;
- ucsi_pd_execute_command* execute_cmd;
+ ucsi_pd_configure_lpm_irq *configure_lpm_irq;
+ ucsi_pd_init_ppm *init_ppm;
+ ucsi_pd_get_ppm *get_ppm;
+ ucsi_pd_execute_command *execute_cmd;
- ucsi_pd_cleanup* cleanup;
+ ucsi_pd_cleanup *cleanup;
};
enum lpm_transport {
- SMBUS,
+ SMBUS,
};
/* Maximum number of addressible ports via PPM. The actual maximum depends on
@@ -103,16 +103,16 @@
* Configuration data for a PD controller.
*/
struct pd_driver_config {
- /* Maximum number of addresses supported by this pd driver.*/
- uint8_t max_num_ports;
+ /* Maximum number of addresses supported by this pd driver.*/
+ uint8_t max_num_ports;
- /* Map of port number to port id. Will be used for distinguishing ports at the
- * LPM.
- */
- uint8_t port_address_map[MAX_PORTS_SUPPORTED];
+ /* Map of port number to port id. Will be used for distinguishing ports
+ * at the LPM.
+ */
+ uint8_t port_address_map[MAX_PORTS_SUPPORTED];
- /* What transport is used for the LPM. */
- enum lpm_transport transport;
+ /* What transport is used for the LPM. */
+ enum lpm_transport transport;
};
-#endif // UM_PPM_INCLUDE_PD_DRIVER_H_
+#endif // UM_PPM_INCLUDE_PD_DRIVER_H_
diff --git a/include/platform.h b/include/platform.h
index 20eafba..a473306 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -7,47 +7,48 @@
#define UM_PPM_INCLUDE_PLATFORM_H_
#include <stdbool.h>
-#include <stdint.h>
#include <stddef.h>
+#include <stdint.h>
/**
* Platform independent utility functions.
*/
-#define DLOG(fmt, ...) \
- if (platform_debug_enabled()) { \
- platform_printf("DBG: %s: " fmt "\n", __func__, ##__VA_ARGS__); \
- }
+#define DLOG(fmt, ...) \
+ if (platform_debug_enabled()) { \
+ platform_printf("DBG: %s: " fmt "\n", __func__, \
+ ##__VA_ARGS__); \
+ }
-#define DLOG_START(fmt, ...) \
- if (platform_debug_enabled()) { \
- platform_printf("DBG: %s: " fmt, __func__, ##__VA_ARGS__); \
- }
+#define DLOG_START(fmt, ...) \
+ if (platform_debug_enabled()) { \
+ platform_printf("DBG: %s: " fmt, __func__, ##__VA_ARGS__); \
+ }
-#define DLOG_LOOP(fmt, ...) \
- if (platform_debug_enabled()) { \
- platform_printf(fmt, ##__VA_ARGS__); \
- }
+#define DLOG_LOOP(fmt, ...) \
+ if (platform_debug_enabled()) { \
+ platform_printf(fmt, ##__VA_ARGS__); \
+ }
-#define DLOG_END(fmt, ...) \
- if (platform_debug_enabled()) { \
- platform_printf(fmt "\n", ##__VA_ARGS__); \
- }
+#define DLOG_END(fmt, ...) \
+ if (platform_debug_enabled()) { \
+ platform_printf(fmt "\n", ##__VA_ARGS__); \
+ }
#define ELOG(fmt, ...) \
- platform_eprintf("ERR: %s: " fmt "\n", __func__, ##__VA_ARGS__)
+ platform_eprintf("ERR: %s: " fmt "\n", __func__, ##__VA_ARGS__)
-void* platform_malloc(size_t size);
-void* platform_calloc(size_t nmemb, size_t size);
-void platform_free(void* ptr);
+void *platform_malloc(size_t size);
+void *platform_calloc(size_t nmemb, size_t size);
+void platform_free(void *ptr);
-void platform_memcpy(void* dest, const void* src, size_t length);
-void platform_memset(void* dest, uint8_t data, size_t length);
+void platform_memcpy(void *dest, const void *src, size_t length);
+void platform_memset(void *dest, uint8_t data, size_t length);
void platform_set_debug(bool enable);
bool platform_debug_enabled();
-void platform_printf(const char* format, ...);
-void platform_eprintf(const char* format, ...);
+void platform_printf(const char *format, ...);
+void platform_eprintf(const char *format, ...);
void platform_usleep(uint32_t usec);
@@ -55,31 +56,31 @@
struct task_handle;
// Initialize a task (code that can be independently scheduled).
-struct task_handle* platform_task_init(void* start_fn, void* arg);
+struct task_handle *platform_task_init(void *start_fn, void *arg);
// Called from within the task to complete / exit.
void platform_task_exit();
// Block on task completion (to clean up).
-int platform_task_complete(struct task_handle* handle);
+int platform_task_complete(struct task_handle *handle);
/* Opaque mutex struct. */
struct platform_mutex;
// Allocate and initialize a platform mutex.
-struct platform_mutex* platform_mutex_init();
+struct platform_mutex *platform_mutex_init();
-void platform_mutex_lock(struct platform_mutex* mutex);
-void platform_mutex_unlock(struct platform_mutex* mutex);
+void platform_mutex_lock(struct platform_mutex *mutex);
+void platform_mutex_unlock(struct platform_mutex *mutex);
/* Opaque notifier struct. */
struct platform_condvar;
// Allocate and initialize a platform condvar.
-struct platform_condvar* platform_condvar_init();
+struct platform_condvar *platform_condvar_init();
-void platform_condvar_wait(struct platform_condvar* condvar,
- struct platform_mutex* mutex);
-void platform_condvar_signal(struct platform_condvar* condvar);
+void platform_condvar_wait(struct platform_condvar *condvar,
+ struct platform_mutex *mutex);
+void platform_condvar_signal(struct platform_condvar *condvar);
-#endif // UM_PPM_INCLUDE_PLATFORM_H_
+#endif // UM_PPM_INCLUDE_PLATFORM_H_
diff --git a/include/ppm.h b/include/ppm.h
index e54ea81..653540d 100644
--- a/include/ppm.h
+++ b/include/ppm.h
@@ -16,81 +16,83 @@
* but may persist waiting for some communication with either the OPM or LPM.
*/
enum ppm_states {
- // Only handle PPM_RESET or async event for PPM reset.
- // This is the default state before we are ready to handle any OPM commands.
- PPM_STATE_NOT_READY,
+ // Only handle PPM_RESET or async event for PPM reset.
+ // This is the default state before we are ready to handle any OPM
+ // commands.
+ PPM_STATE_NOT_READY,
- // Only accept Set Notification Enable. Everything else no-ops.
- PPM_STATE_IDLE,
+ // Only accept Set Notification Enable. Everything else no-ops.
+ PPM_STATE_IDLE,
- // Handle most commands.
- PPM_STATE_IDLE_NOTIFY,
+ // Handle most commands.
+ PPM_STATE_IDLE_NOTIFY,
- // Unused state.
- // PPM_STATE_BUSY,
+ // Unused state.
+ // PPM_STATE_BUSY,
- // PPM_STATE_PROCESS_COMMAND is a hidden state that happens synchronously.
- // Processing current command.
- PPM_STATE_PROCESSING_COMMAND,
+ // PPM_STATE_PROCESS_COMMAND is a hidden state that happens
+ // synchronously.
+ // Processing current command.
+ PPM_STATE_PROCESSING_COMMAND,
- // Waiting for command complete acknowledgement from OPM.
- PPM_STATE_WAITING_CC_ACK,
- // PPM_STATE_PROCESS_CC_ACK,
+ // Waiting for command complete acknowledgement from OPM.
+ PPM_STATE_WAITING_CC_ACK,
+ // PPM_STATE_PROCESS_CC_ACK,
- // Waiting for async event acknowledgement from OPM.
- PPM_STATE_WAITING_ASYNC_EV_ACK,
- // PPM_STATE_PROCESS_ASYNC_EV_ACK,
+ // Waiting for async event acknowledgement from OPM.
+ PPM_STATE_WAITING_ASYNC_EV_ACK,
+ // PPM_STATE_PROCESS_ASYNC_EV_ACK,
- // PPM_STATE_CANCELLING_COMMAND,
+ // PPM_STATE_CANCELLING_COMMAND,
- // Just for bounds checking.
- PPM_STATE_MAX,
+ // Just for bounds checking.
+ PPM_STATE_MAX,
};
/* Indicators of pending data states in the PPM. */
struct ppm_pending_data {
- // Async events are received from the LPM.
- uint16_t async_event : 1;
+ // Async events are received from the LPM.
+ uint16_t async_event : 1;
- // Command is pending from OPM.
- uint16_t command : 1;
+ // Command is pending from OPM.
+ uint16_t command : 1;
};
/* Constants for UCSI commands (up to date for UCSI 3.0). */
enum ucsi_commands {
- UCSI_CMD_RESERVED = 0,
- UCSI_CMD_PPM_RESET = 0x01,
- UCSI_CMD_CANCEL = 0x02,
- UCSI_CMD_CONNECTOR_RESET = 0x03,
- UCSI_CMD_ACK_CC_CI = 0x04,
- UCSI_CMD_SET_NOTIFICATION_ENABLE = 0x05,
- UCSI_CMD_GET_CAPABILITY = 0x06,
- UCSI_CMD_GET_CONNECTOR_CAPABILITY = 0x07,
- UCSI_CMD_SET_CCOM = 0x08,
- UCSI_CMD_SET_UOR = 0x09,
- obsolete_UCSI_CMD_SET_PDM = 0x0A,
- UCSI_CMD_SET_PDR = 0x0B,
- UCSI_CMD_GET_ALTERNATE_MODES = 0x0C,
- UCSI_CMD_GET_CAM_SUPPORTED = 0x0D,
- UCSI_CMD_GET_CURRENT_CAM = 0x0E,
- UCSI_CMD_SET_NEW_CAM = 0x0F,
- UCSI_CMD_GET_PDOS = 0x10,
- UCSI_CMD_GET_CABLE_PROPERTY = 0x11,
- UCSI_CMD_GET_CONNECTOR_STATUS = 0x12,
- UCSI_CMD_GET_ERROR_STATUS = 0x13,
- UCSI_CMD_SET_POWER_LEVEL = 0x14,
- UCSI_CMD_GET_PD_MESSAGE = 0x15,
- UCSI_CMD_GET_ATTENTION_VDO = 0x16,
- UCSI_CMD_reserved_0x17 = 0x17,
- UCSI_CMD_GET_CAM_CS = 0x18,
- UCSI_CMD_LPM_FW_UPDATE_REQUEST = 0x19,
- UCSI_CMD_SECURITY_REQUEST = 0x1A,
- UCSI_CMD_SET_RETIMER_MODE = 0x1B,
- UCSI_CMD_SET_SINK_PATH = 0x1C,
- UCSI_CMD_SET_PDOS = 0x1D,
- UCSI_CMD_READ_POWER_LEVEL = 0x1E,
- UCSI_CMD_CHUNKING_SUPPORT = 0x1F,
- UCSI_CMD_VENDOR_CMD = 0x20,
+ UCSI_CMD_RESERVED = 0,
+ UCSI_CMD_PPM_RESET = 0x01,
+ UCSI_CMD_CANCEL = 0x02,
+ UCSI_CMD_CONNECTOR_RESET = 0x03,
+ UCSI_CMD_ACK_CC_CI = 0x04,
+ UCSI_CMD_SET_NOTIFICATION_ENABLE = 0x05,
+ UCSI_CMD_GET_CAPABILITY = 0x06,
+ UCSI_CMD_GET_CONNECTOR_CAPABILITY = 0x07,
+ UCSI_CMD_SET_CCOM = 0x08,
+ UCSI_CMD_SET_UOR = 0x09,
+ obsolete_UCSI_CMD_SET_PDM = 0x0A,
+ UCSI_CMD_SET_PDR = 0x0B,
+ UCSI_CMD_GET_ALTERNATE_MODES = 0x0C,
+ UCSI_CMD_GET_CAM_SUPPORTED = 0x0D,
+ UCSI_CMD_GET_CURRENT_CAM = 0x0E,
+ UCSI_CMD_SET_NEW_CAM = 0x0F,
+ UCSI_CMD_GET_PDOS = 0x10,
+ UCSI_CMD_GET_CABLE_PROPERTY = 0x11,
+ UCSI_CMD_GET_CONNECTOR_STATUS = 0x12,
+ UCSI_CMD_GET_ERROR_STATUS = 0x13,
+ UCSI_CMD_SET_POWER_LEVEL = 0x14,
+ UCSI_CMD_GET_PD_MESSAGE = 0x15,
+ UCSI_CMD_GET_ATTENTION_VDO = 0x16,
+ UCSI_CMD_reserved_0x17 = 0x17,
+ UCSI_CMD_GET_CAM_CS = 0x18,
+ UCSI_CMD_LPM_FW_UPDATE_REQUEST = 0x19,
+ UCSI_CMD_SECURITY_REQUEST = 0x1A,
+ UCSI_CMD_SET_RETIMER_MODE = 0x1B,
+ UCSI_CMD_SET_SINK_PATH = 0x1C,
+ UCSI_CMD_SET_PDOS = 0x1D,
+ UCSI_CMD_READ_POWER_LEVEL = 0x1E,
+ UCSI_CMD_CHUNKING_SUPPORT = 0x1F,
+ UCSI_CMD_VENDOR_CMD = 0x20,
};
/* Byte offsets to UCSI data */
@@ -106,123 +108,123 @@
/* UCSI version struct */
struct ucsi_version {
- uint16_t version;
- uint8_t lpm_address;
- uint8_t unused0;
+ uint16_t version;
+ uint8_t lpm_address;
+ uint8_t unused0;
} __attribute__((__packed__));
/* UCSI Connector Change Indication data structure */
struct ucsi_cci {
- uint32_t end_of_message : 1;
- uint32_t connector_changed : 7;
+ uint32_t end_of_message : 1;
+ uint32_t connector_changed : 7;
- uint32_t data_length : 8;
+ uint32_t data_length : 8;
- uint32_t vendor_defined_message : 1;
- uint32_t reserved_0 : 6;
- uint32_t security_request : 1;
+ uint32_t vendor_defined_message : 1;
+ uint32_t reserved_0 : 6;
+ uint32_t security_request : 1;
- uint32_t fw_update_request : 1;
- uint32_t not_supported : 1;
- uint32_t cancel_completed : 1;
- uint32_t reset_completed : 1;
- uint32_t busy : 1;
- uint32_t ack_command : 1;
- uint32_t error : 1;
- uint32_t cmd_complete : 1;
+ uint32_t fw_update_request : 1;
+ uint32_t not_supported : 1;
+ uint32_t cancel_completed : 1;
+ uint32_t reset_completed : 1;
+ uint32_t busy : 1;
+ uint32_t ack_command : 1;
+ uint32_t error : 1;
+ uint32_t cmd_complete : 1;
} __attribute__((__packed__));
/* UCSI Control Data structure */
struct ucsi_control {
- uint8_t command;
- uint8_t data_length;
- uint8_t command_specific[6];
+ uint8_t command;
+ uint8_t data_length;
+ uint8_t command_specific[6];
} __attribute__((__packed__));
/* Overall memory layout for OPM to PPM communication. */
struct ucsi_memory_region {
- struct ucsi_version version;
- struct ucsi_cci cci;
- struct ucsi_control control;
- // TODO - Message sizes depends on chunking support.
- // May not need to be full 256.
- uint8_t message_in[MESSAGE_IN_SIZE]; // OPM to PPM buffer
- uint8_t message_out[MESSAGE_OUT_SIZE]; // PPM to OPM buffer
+ struct ucsi_version version;
+ struct ucsi_cci cci;
+ struct ucsi_control control;
+ // TODO - Message sizes depends on chunking support.
+ // May not need to be full 256.
+ uint8_t message_in[MESSAGE_IN_SIZE]; // OPM to PPM buffer
+ uint8_t message_out[MESSAGE_OUT_SIZE]; // PPM to OPM buffer
} __attribute__((__packed__));
/* Commands and data below */
/* ACK_CCI_CI Command */
struct ucsiv3_ack_cc_ci_cmd {
- unsigned connector_change_ack : 1;
- unsigned command_complete_ack : 1;
+ unsigned connector_change_ack : 1;
+ unsigned command_complete_ack : 1;
- // 46-bits reserved
- unsigned reserved_0 : 32;
- unsigned reserved_1 : 14;
+ // 46-bits reserved
+ unsigned reserved_0 : 32;
+ unsigned reserved_1 : 14;
} __attribute__((__packed__));
/* GET_PD_MESSAGE Command */
struct ucsiv3_get_pd_message_cmd {
- unsigned connector_number : 7;
- unsigned recipient : 3;
- unsigned message_offset : 8;
- unsigned number_of_bytes : 8;
- unsigned response_message_type : 6;
+ unsigned connector_number : 7;
+ unsigned recipient : 3;
+ unsigned message_offset : 8;
+ unsigned number_of_bytes : 8;
+ unsigned response_message_type : 6;
- // 16-bits reserved
- unsigned reserved_0 : 16;
+ // 16-bits reserved
+ unsigned reserved_0 : 16;
} __attribute__((__packed__));
/* GET_CONNECTOR_STATUS data */
struct ucsiv3_get_connector_status_data {
- unsigned connector_status_change : 16;
- unsigned power_operation_mode : 3;
- unsigned connect_status : 1;
- unsigned power_direction : 1;
- unsigned connector_partner_flags : 8;
- unsigned connector_partner_type : 3;
- unsigned request_data_object : 32;
- unsigned bc_capability_status : 2;
- unsigned provider_caps_limited_reason : 4;
- unsigned bcd_pd_version_op_mode : 16;
- unsigned orientation : 1;
- unsigned sink_path_status : 1;
- unsigned reverse_current_protect_status : 1;
- unsigned power_reading : 1;
- unsigned current_scale : 3;
- unsigned peak_current : 16;
- unsigned avg_current : 16;
- unsigned volt_scale : 4;
- unsigned volt_reading : 16;
+ unsigned connector_status_change : 16;
+ unsigned power_operation_mode : 3;
+ unsigned connect_status : 1;
+ unsigned power_direction : 1;
+ unsigned connector_partner_flags : 8;
+ unsigned connector_partner_type : 3;
+ unsigned request_data_object : 32;
+ unsigned bc_capability_status : 2;
+ unsigned provider_caps_limited_reason : 4;
+ unsigned bcd_pd_version_op_mode : 16;
+ unsigned orientation : 1;
+ unsigned sink_path_status : 1;
+ unsigned reverse_current_protect_status : 1;
+ unsigned power_reading : 1;
+ unsigned current_scale : 3;
+ unsigned peak_current : 16;
+ unsigned avg_current : 16;
+ unsigned volt_scale : 4;
+ unsigned volt_reading : 16;
- // 110-bits reserved (32 + 32 + 32 + 14)
- unsigned reserved_0 : 32;
- unsigned reserved_1 : 32;
- unsigned reserved_2 : 32;
- unsigned reserved_3 : 14;
+ // 110-bits reserved (32 + 32 + 32 + 14)
+ unsigned reserved_0 : 32;
+ unsigned reserved_1 : 32;
+ unsigned reserved_2 : 32;
+ unsigned reserved_3 : 14;
} __attribute__((__packed__));
struct ucsiv3_get_error_status_data {
- struct error_information {
- uint16_t unrecognized_command : 1;
- uint16_t nonexistent_connector_number : 1;
- uint16_t invalid_cmd_specific_params : 1;
- uint16_t incompatible_connector_partner : 1;
- uint16_t cc_comm_error : 1;
- uint16_t cmd_unsuccessful_dead_battery : 1;
- uint16_t contract_negotiation_failure : 1;
- uint16_t overcurrent : 1;
- uint16_t undefined : 1;
- uint16_t port_partner_reject_swap : 1;
- uint16_t hard_reset : 1;
- uint16_t ppm_policy_conflict : 1;
- uint16_t swap_rejected : 1;
- uint16_t reverse_current_protection : 1;
- uint16_t set_sink_path_rejected : 1;
- uint16_t reserved_0 : 1;
- } error_information;
- uint16_t vendor_defined;
+ struct error_information {
+ uint16_t unrecognized_command : 1;
+ uint16_t nonexistent_connector_number : 1;
+ uint16_t invalid_cmd_specific_params : 1;
+ uint16_t incompatible_connector_partner : 1;
+ uint16_t cc_comm_error : 1;
+ uint16_t cmd_unsuccessful_dead_battery : 1;
+ uint16_t contract_negotiation_failure : 1;
+ uint16_t overcurrent : 1;
+ uint16_t undefined : 1;
+ uint16_t port_partner_reject_swap : 1;
+ uint16_t hard_reset : 1;
+ uint16_t ppm_policy_conflict : 1;
+ uint16_t swap_rejected : 1;
+ uint16_t reverse_current_protection : 1;
+ uint16_t set_sink_path_rejected : 1;
+ uint16_t reserved_0 : 1;
+ } error_information;
+ uint16_t vendor_defined;
} __attribute__((__packed__));
// Forward declarations.
@@ -237,8 +239,8 @@
*
* @return 0 on success and -1 on error.
*/
-typedef int(ucsi_ppm_init_and_wait)(struct ucsi_ppm_device* device,
- uint8_t num_ports);
+typedef int(ucsi_ppm_init_and_wait)(struct ucsi_ppm_device *device,
+ uint8_t num_ports);
/**
* Get access to the UCSI data region.
@@ -247,8 +249,8 @@
*
* @return Pointer to UCSI shared data.
*/
-typedef struct ucsi_memory_region*(
- ucsi_ppm_get_data_region)(struct ucsi_ppm_device* device);
+typedef struct ucsi_memory_region *(
+ ucsi_ppm_get_data_region)(struct ucsi_ppm_device *device);
/**
* Get the next connector status if a connector change indication is
@@ -261,8 +263,8 @@
* @return True if we have pending connector change indications.
*/
typedef bool(ucsi_ppm_get_next_connector_status)(
- struct ucsi_ppm_device* device, uint8_t* out_port_num,
- struct ucsiv3_get_connector_status_data** out_connector_status);
+ struct ucsi_ppm_device *device, uint8_t *out_port_num,
+ struct ucsiv3_get_connector_status_data **out_connector_status);
/**
* Read data from UCSI at a specific data offset.
@@ -274,8 +276,8 @@
*
* @return Bytes read or -1 for errors.
*/
-typedef int(ucsi_ppm_read)(struct ucsi_ppm_device* device, unsigned int offset,
- void* buf, size_t length);
+typedef int(ucsi_ppm_read)(struct ucsi_ppm_device *device, unsigned int offset,
+ void *buf, size_t length);
/**
* Write data for UCSI to a specific data offset.
@@ -287,15 +289,15 @@
*
* @return Bytes written or -1 for errors.
*/
-typedef int(ucsi_ppm_write)(struct ucsi_ppm_device* device, unsigned int offset,
- const void* buf, size_t length);
+typedef int(ucsi_ppm_write)(struct ucsi_ppm_device *device, unsigned int offset,
+ const void *buf, size_t length);
/**
* Function to send OPM a notification (doorbell).
*
* @param context: Context data for the OPM notifier.
*/
-typedef void(ucsi_ppm_notify)(void* context);
+typedef void(ucsi_ppm_notify)(void *context);
/**
* Register a notification callback with the driver. If there is already an
@@ -307,8 +309,8 @@
*
* @return 0 if new callback set or 1 if callback replaced.
*/
-typedef int(ucsi_ppm_register_notify)(struct ucsi_ppm_device* device,
- ucsi_ppm_notify* callback, void* context);
+typedef int(ucsi_ppm_register_notify)(struct ucsi_ppm_device *device,
+ ucsi_ppm_notify *callback, void *context);
/**
* Alert the PPM that an LPM has sent a notification.
@@ -316,28 +318,28 @@
* @param device: Data for PPM implementation.
* @param port_id: Port on which the change was made.
*/
-typedef void(ucsi_ppm_lpm_alert)(struct ucsi_ppm_device* device,
- uint8_t port_id);
+typedef void(ucsi_ppm_lpm_alert)(struct ucsi_ppm_device *device,
+ uint8_t port_id);
/**
* Clean up the given PPM driver. Call before freeing.
*
* @param driver: Driver object to clean up.
*/
-typedef void(ucsi_ppm_cleanup)(struct ucsi_ppm_driver* driver);
+typedef void(ucsi_ppm_cleanup)(struct ucsi_ppm_driver *driver);
struct ucsi_ppm_driver {
- struct ucsi_ppm_device* dev;
+ struct ucsi_ppm_device *dev;
- ucsi_ppm_init_and_wait* init_and_wait;
- ucsi_ppm_get_data_region* get_data_region;
- ucsi_ppm_get_next_connector_status* get_next_connector_status;
- ucsi_ppm_read* read;
- ucsi_ppm_write* write;
- ucsi_ppm_register_notify* register_notify;
- ucsi_ppm_lpm_alert* lpm_alert;
+ ucsi_ppm_init_and_wait *init_and_wait;
+ ucsi_ppm_get_data_region *get_data_region;
+ ucsi_ppm_get_next_connector_status *get_next_connector_status;
+ ucsi_ppm_read *read;
+ ucsi_ppm_write *write;
+ ucsi_ppm_register_notify *register_notify;
+ ucsi_ppm_lpm_alert *lpm_alert;
- ucsi_ppm_cleanup* cleanup;
+ ucsi_ppm_cleanup *cleanup;
};
-#endif // UM_PPM_INCLUDE_PPM_H_
+#endif // UM_PPM_INCLUDE_PPM_H_
diff --git a/include/smbus.h b/include/smbus.h
index f1ce034..84ac771 100644
--- a/include/smbus.h
+++ b/include/smbus.h
@@ -23,7 +23,7 @@
*
* @return Byte read or -1 for errors.
*/
-typedef int(smbus_read_byte)(struct smbus_device* device, uint8_t chip_address);
+typedef int(smbus_read_byte)(struct smbus_device *device, uint8_t chip_address);
/**
* Read data over smbus at given address.
@@ -36,8 +36,8 @@
*
* @return Bytes read or -1 for errors.
*/
-typedef int(smbus_read_block)(struct smbus_device* device, uint8_t chip_address,
- uint8_t address, void* buf, size_t length);
+typedef int(smbus_read_block)(struct smbus_device *device, uint8_t chip_address,
+ uint8_t address, void *buf, size_t length);
/**
* Write data over smbus at given address.
@@ -50,9 +50,9 @@
*
* @return Bytes written or -1 for errors.
*/
-typedef int(smbus_write_block)(struct smbus_device* device,
- uint8_t chip_address, uint8_t address, void* buf,
- size_t length);
+typedef int(smbus_write_block)(struct smbus_device *device,
+ uint8_t chip_address, uint8_t address, void *buf,
+ size_t length);
/**
* Read the Alert Receiving Address.
@@ -65,7 +65,7 @@
*
* @return -1 on error. ARA (uint8_t) on success (mask with 0xff).
*/
-typedef int(smbus_read_ara)(struct smbus_device* device, uint8_t ara_address);
+typedef int(smbus_read_ara)(struct smbus_device *device, uint8_t ara_address);
/**
* Blocks until a GPIO interrupt is seen.
@@ -78,29 +78,29 @@
*
* @return 0 on success. -1 on error.
*/
-typedef int(smbus_block_for_interrupt)(struct smbus_device* device);
+typedef int(smbus_block_for_interrupt)(struct smbus_device *device);
/**
* Clean up the given smbus driver. Call before freeing.
*
* @param driver: Driver object to clean up.
*/
-typedef void(smbus_cleanup)(struct smbus_driver* driver);
+typedef void(smbus_cleanup)(struct smbus_driver *driver);
/**
* General driver for smbus access.
*/
struct smbus_driver {
- struct smbus_device* dev;
+ struct smbus_device *dev;
- smbus_read_byte* read_byte;
- smbus_read_block* read_block;
- smbus_write_block* write_block;
+ smbus_read_byte *read_byte;
+ smbus_read_block *read_block;
+ smbus_write_block *write_block;
- smbus_read_ara* read_ara;
- smbus_block_for_interrupt* block_for_interrupt;
+ smbus_read_ara *read_ara;
+ smbus_block_for_interrupt *block_for_interrupt;
- smbus_cleanup* cleanup;
+ smbus_cleanup *cleanup;
};
-#endif // UM_PPM_INCLUDE_SMBUS_H_
+#endif // UM_PPM_INCLUDE_SMBUS_H_
diff --git a/main.c b/main.c
index fc68d56..3dd0e80 100644
--- a/main.c
+++ b/main.c
@@ -3,194 +3,201 @@
* found in the LICENSE file.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
#include "include/platform.h"
#include "rts5453.h"
#include "smbus_usermode.h"
#include "um_ppm_chardev.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <unistd.h>
+
/* Some extra functionality that's used by this binary that's not necessarily
* for UCSI (such as getting info about the PD controller, firmware update,
* etc).
*/
struct extra_driver_ops {
- int (*get_info)(struct ucsi_pd_driver* driver);
- int (*do_firmware_update)(struct ucsi_pd_driver* driver, const char* filepath,
- int dry_run);
+ int (*get_info)(struct ucsi_pd_driver *driver);
+ int (*do_firmware_update)(struct ucsi_pd_driver *driver,
+ const char *filepath, int dry_run);
- // Establish communication with SMBUS transport LPMs.
- struct ucsi_pd_driver* (*smbus_lpm_open)(struct smbus_driver* smbus,
- struct pd_driver_config* config);
+ // Establish communication with SMBUS transport LPMs.
+ struct ucsi_pd_driver *(*smbus_lpm_open)(
+ struct smbus_driver *smbus, struct pd_driver_config *config);
};
struct extra_driver_ops rts5453_ops = {
- .get_info = rts5453_get_info,
- .do_firmware_update = rts5453_do_firmware_update,
- .smbus_lpm_open = rts5453_open,
+ .get_info = rts5453_get_info,
+ .do_firmware_update = rts5453_do_firmware_update,
+ .smbus_lpm_open = rts5453_open,
};
// Set up the um_ppm device to start communicating with kernel.
-int cdev_prepare_um_ppm(char* um_test_devpath, struct ucsi_pd_driver* pd,
- struct smbus_driver* smbus,
- struct pd_driver_config* config) {
- // Open the kernel um_ppm chardev to establish the PPM communication.
- struct um_ppm_cdev* cdev =
- um_ppm_cdev_open(um_test_devpath, pd, smbus, config);
+int cdev_prepare_um_ppm(char *um_test_devpath, struct ucsi_pd_driver *pd,
+ struct smbus_driver *smbus,
+ struct pd_driver_config *config)
+{
+ // Open the kernel um_ppm chardev to establish the PPM communication.
+ struct um_ppm_cdev *cdev =
+ um_ppm_cdev_open(um_test_devpath, pd, smbus, config);
- if (!cdev) {
- ELOG("Failed to initialize PPM chardev. Exit early!");
- return -1;
- }
+ if (!cdev) {
+ ELOG("Failed to initialize PPM chardev. Exit early!");
+ return -1;
+ }
- // TODO - Register sigterm handler so we know when to exit.
+ // TODO - Register sigterm handler so we know when to exit.
- // Mainloop with chardev handling.
- um_ppm_cdev_mainloop(cdev);
+ // Mainloop with chardev handling.
+ um_ppm_cdev_mainloop(cdev);
- return 0;
+ return 0;
}
-static const char* usage_str =
- ("um_ppm [options]\n"
- "\n"
- "Userspace PPM implementation and helper functions. Use this to\n"
- "develop against and test new devkits.\n"
- "\n"
- "General options:\n"
- "\t-p PD driver config to use. Valid values: ['rts5453']\n"
- "\t-b I2C Bus number (/dev/i2c-N) (required)\n"
- "\t-g /dev/gpiochip[N] (required)\n"
- "\t-l Gpio line for LPM alert (required)\n"
- "\t-v Enable verbose logs\n"
- "Actions (exclusive):\n"
- "\t-f <path> Do firmware update with file at this path\n"
- "\t-k <dev path> Attach ucsi_um_kernel driver via this chardev path\n"
- "\t-d Demo commands\n");
+static const char *usage_str =
+ ("um_ppm [options]\n"
+ "\n"
+ "Userspace PPM implementation and helper functions. Use this to\n"
+ "develop against and test new devkits.\n"
+ "\n"
+ "General options:\n"
+ "\t-p PD driver config to use. Valid values: ['rts5453']\n"
+ "\t-b I2C Bus number (/dev/i2c-N) (required)\n"
+ "\t-g /dev/gpiochip[N] (required)\n"
+ "\t-l Gpio line for LPM alert (required)\n"
+ "\t-v Enable verbose logs\n"
+ "Actions (exclusive):\n"
+ "\t-f <path> Do firmware update with file at this path\n"
+ "\t-k <dev path> Attach ucsi_um_kernel driver via this chardev path\n"
+ "\t-d Demo commands\n");
-void usage() { printf(usage_str); }
+void usage()
+{
+ printf(usage_str);
+}
-int main(int argc, char* argv[]) {
- int opt;
+int main(int argc, char *argv[])
+{
+ int opt;
- int fwupdate = 0;
- char* fwupdate_file = NULL;
- int demo = 0;
- int i2c_bus = -1;
- int i2c_chip_address = -1;
- int gpio_chip = -1;
- int gpio_line = -1;
- int attach_to_kernel = 0;
- char* ucsi_um_kernel_dev = NULL;
- char* driver_config_in = NULL;
- struct pd_driver_config driver_config;
- struct extra_driver_ops* ops;
+ int fwupdate = 0;
+ char *fwupdate_file = NULL;
+ int demo = 0;
+ int i2c_bus = -1;
+ int i2c_chip_address = -1;
+ int gpio_chip = -1;
+ int gpio_line = -1;
+ int attach_to_kernel = 0;
+ char *ucsi_um_kernel_dev = NULL;
+ char *driver_config_in = NULL;
+ struct pd_driver_config driver_config;
+ struct extra_driver_ops *ops;
- while ((opt = getopt(argc, argv, ":f:k:dvb:p:g:l:")) != -1) {
- switch (opt) {
- case 'b':
- i2c_bus = strtol(optarg, NULL, 10);
- break;
- case 'p':
- driver_config_in = strdup(optarg);
- break;
- case 'g':
- gpio_chip = strtol(optarg, NULL, 10);
- break;
- case 'l':
- gpio_line = strtol(optarg, NULL, 10);
- break;
- case 'f':
- fwupdate = 1;
- fwupdate_file = strdup(optarg);
- break;
- case 'k':
- attach_to_kernel = 1;
- ucsi_um_kernel_dev = strdup(optarg);
- break;
- case 'd':
- demo = 1;
- break;
- case 'v':
- platform_set_debug(true);
- break;
- case ':':
- printf("Missing arg for %c\n", optopt);
- usage();
- return -1;
- case '?':
- default:
- printf("Unknown option: %c\n", optopt);
- usage();
- return -1;
- }
- }
+ while ((opt = getopt(argc, argv, ":f:k:dvb:p:g:l:")) != -1) {
+ switch (opt) {
+ case 'b':
+ i2c_bus = strtol(optarg, NULL, 10);
+ break;
+ case 'p':
+ driver_config_in = strdup(optarg);
+ break;
+ case 'g':
+ gpio_chip = strtol(optarg, NULL, 10);
+ break;
+ case 'l':
+ gpio_line = strtol(optarg, NULL, 10);
+ break;
+ case 'f':
+ fwupdate = 1;
+ fwupdate_file = strdup(optarg);
+ break;
+ case 'k':
+ attach_to_kernel = 1;
+ ucsi_um_kernel_dev = strdup(optarg);
+ break;
+ case 'd':
+ demo = 1;
+ break;
+ case 'v':
+ platform_set_debug(true);
+ break;
+ case ':':
+ printf("Missing arg for %c\n", optopt);
+ usage();
+ return -1;
+ case '?':
+ default:
+ printf("Unknown option: %c\n", optopt);
+ usage();
+ return -1;
+ }
+ }
- struct smbus_driver* smbus = NULL;
- struct ucsi_pd_driver* pd_driver = NULL;
+ struct smbus_driver *smbus = NULL;
+ struct ucsi_pd_driver *pd_driver = NULL;
- if (i2c_bus == -1) {
- ELOG("Invalid bus (%d) parameter", i2c_bus);
- return -1;
- }
+ if (i2c_bus == -1) {
+ ELOG("Invalid bus (%d) parameter", i2c_bus);
+ return -1;
+ }
- if (!driver_config_in) {
- ELOG("No driver config given. Defaulting to rts5453.");
- driver_config_in = "rts5453";
- }
+ if (!driver_config_in) {
+ ELOG("No driver config given. Defaulting to rts5453.");
+ driver_config_in = "rts5453";
+ }
- // Get driver config
- if (strcmp(driver_config_in, "rts5453") == 0) {
- driver_config = rts5453_get_driver_config();
- ops = &rts5453_ops;
+ // Get driver config
+ if (strcmp(driver_config_in, "rts5453") == 0) {
+ driver_config = rts5453_get_driver_config();
+ ops = &rts5453_ops;
- // Use port-0 for smbus addressing
- i2c_chip_address = driver_config.port_address_map[0];
- } else {
- ELOG("Unsupported PD driver config: %s", driver_config_in);
- return -1;
- }
+ // Use port-0 for smbus addressing
+ i2c_chip_address = driver_config.port_address_map[0];
+ } else {
+ ELOG("Unsupported PD driver config: %s", driver_config_in);
+ return -1;
+ }
- // Open usermode smbus.
- smbus = smbus_um_open(i2c_bus, i2c_chip_address, gpio_chip, gpio_line);
- if (!smbus) {
- ELOG("Failed to open smbus");
- goto handle_error;
- }
+ // Open usermode smbus.
+ smbus = smbus_um_open(i2c_bus, i2c_chip_address, gpio_chip, gpio_line);
+ if (!smbus) {
+ ELOG("Failed to open smbus");
+ goto handle_error;
+ }
- // Open PD driver
- pd_driver = ops->smbus_lpm_open(smbus, &driver_config);
- if (!pd_driver) {
- ELOG("Failed to open PD driver.");
- goto handle_error;
- }
+ // Open PD driver
+ pd_driver = ops->smbus_lpm_open(smbus, &driver_config);
+ if (!pd_driver) {
+ ELOG("Failed to open PD driver.");
+ goto handle_error;
+ }
- DLOG("RTS5453 is initialized. Now taking desired action...");
+ DLOG("RTS5453 is initialized. Now taking desired action...");
- if (demo) {
- return ops->get_info(pd_driver);
- } else if (fwupdate && fwupdate_file) {
- return ops->do_firmware_update(pd_driver, fwupdate_file, /*dry_run=*/0);
- } else if (attach_to_kernel) {
- return cdev_prepare_um_ppm(ucsi_um_kernel_dev, pd_driver, smbus,
- &driver_config);
- }
+ if (demo) {
+ return ops->get_info(pd_driver);
+ } else if (fwupdate && fwupdate_file) {
+ return ops->do_firmware_update(pd_driver, fwupdate_file,
+ /*dry_run=*/0);
+ } else if (attach_to_kernel) {
+ return cdev_prepare_um_ppm(ucsi_um_kernel_dev, pd_driver, smbus,
+ &driver_config);
+ }
- return 0;
+ return 0;
handle_error:
- if (smbus) {
- smbus->cleanup(smbus);
- free(smbus);
- }
+ if (smbus) {
+ smbus->cleanup(smbus);
+ free(smbus);
+ }
- if (pd_driver) {
- pd_driver->cleanup(pd_driver);
- free(pd_driver);
- }
+ if (pd_driver) {
+ pd_driver->cleanup(pd_driver);
+ free(pd_driver);
+ }
- return -1;
+ return -1;
}
diff --git a/platform_usermode.c b/platform_usermode.c
index 8852025..a7fc887 100644
--- a/platform_usermode.c
+++ b/platform_usermode.c
@@ -3,123 +3,158 @@
* found in the LICENSE file.
*/
-#include <pthread.h>
+#include "include/platform.h"
+
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
-#include "include/platform.h"
+#include <pthread.h>
+#include <unistd.h>
bool debug_enabled = false;
-void *platform_malloc(size_t size) { return malloc(size); }
-void *platform_calloc(size_t nmemb, size_t size) { return calloc(nmemb, size); }
-void platform_free(void *ptr) { free(ptr); }
-
-void platform_memcpy(void *dest, const void *src, size_t length) {
- memcpy(dest, src, length);
+void *platform_malloc(size_t size)
+{
+ return malloc(size);
}
-void platform_memset(void *dest, uint8_t data, size_t length) {
- memset(dest, data, length);
+void *platform_calloc(size_t nmemb, size_t size)
+{
+ return calloc(nmemb, size);
+}
+void platform_free(void *ptr)
+{
+ free(ptr);
}
-void platform_set_debug(bool enable) { debug_enabled = enable; }
-bool platform_debug_enabled() { return debug_enabled; }
-
-void platform_printf(const char *format, ...) {
- va_list arglist;
-
- va_start(arglist, format);
- vprintf(format, arglist);
- va_end(arglist);
+void platform_memcpy(void *dest, const void *src, size_t length)
+{
+ memcpy(dest, src, length);
}
-void platform_eprintf(const char *format, ...) {
- va_list arglist;
-
- va_start(arglist, format);
- vfprintf(stderr, format, arglist);
- va_end(arglist);
+void platform_memset(void *dest, uint8_t data, size_t length)
+{
+ memset(dest, data, length);
}
-void platform_usleep(uint32_t usec) { usleep(usec); }
+void platform_set_debug(bool enable)
+{
+ debug_enabled = enable;
+}
+bool platform_debug_enabled()
+{
+ return debug_enabled;
+}
+
+void platform_printf(const char *format, ...)
+{
+ va_list arglist;
+
+ va_start(arglist, format);
+ vprintf(format, arglist);
+ va_end(arglist);
+}
+void platform_eprintf(const char *format, ...)
+{
+ va_list arglist;
+
+ va_start(arglist, format);
+ vfprintf(stderr, format, arglist);
+ va_end(arglist);
+}
+
+void platform_usleep(uint32_t usec)
+{
+ usleep(usec);
+}
struct task_handle {
- pthread_t thread;
+ pthread_t thread;
};
-struct task_handle *platform_task_init(void *start_fn, void *arg) {
- struct task_handle *handle = malloc(sizeof(struct task_handle));
- if (!handle) {
- ELOG("Failed to allocate task handle");
- return NULL;
- }
+struct task_handle *platform_task_init(void *start_fn, void *arg)
+{
+ struct task_handle *handle = malloc(sizeof(struct task_handle));
+ if (!handle) {
+ ELOG("Failed to allocate task handle");
+ return NULL;
+ }
- int res = pthread_create(&handle->thread, NULL, start_fn, arg);
- if (res != 0) {
- ELOG("Failed to start thread with error %d for start_fn %p", res, start_fn);
- free(handle);
- return NULL;
- }
+ int res = pthread_create(&handle->thread, NULL, start_fn, arg);
+ if (res != 0) {
+ ELOG("Failed to start thread with error %d for start_fn %p",
+ res, start_fn);
+ free(handle);
+ return NULL;
+ }
- return handle;
+ return handle;
}
-void platform_task_exit() { pthread_exit(NULL); }
+void platform_task_exit()
+{
+ pthread_exit(NULL);
+}
-int platform_task_complete(struct task_handle *handle) {
- return pthread_join(handle->thread, NULL);
+int platform_task_complete(struct task_handle *handle)
+{
+ return pthread_join(handle->thread, NULL);
}
struct platform_mutex {
- pthread_mutex_t lock;
+ pthread_mutex_t lock;
};
-struct platform_mutex *platform_mutex_init() {
- struct platform_mutex *mutex = malloc(sizeof(struct platform_mutex));
- if (!mutex) {
- return NULL;
- }
+struct platform_mutex *platform_mutex_init()
+{
+ struct platform_mutex *mutex = malloc(sizeof(struct platform_mutex));
+ if (!mutex) {
+ return NULL;
+ }
- if (pthread_mutex_init(&mutex->lock, NULL)) {
- free(mutex);
- return NULL;
- }
+ if (pthread_mutex_init(&mutex->lock, NULL)) {
+ free(mutex);
+ return NULL;
+ }
- return mutex;
+ return mutex;
}
-void platform_mutex_lock(struct platform_mutex *mutex) {
- pthread_mutex_lock(&mutex->lock);
+void platform_mutex_lock(struct platform_mutex *mutex)
+{
+ pthread_mutex_lock(&mutex->lock);
}
-void platform_mutex_unlock(struct platform_mutex *mutex) {
- pthread_mutex_unlock(&mutex->lock);
+void platform_mutex_unlock(struct platform_mutex *mutex)
+{
+ pthread_mutex_unlock(&mutex->lock);
}
struct platform_condvar {
- pthread_cond_t var;
+ pthread_cond_t var;
};
-struct platform_condvar *platform_condvar_init() {
- struct platform_condvar *cond = malloc(sizeof(struct platform_condvar));
- if (!cond) {
- return NULL;
- }
+struct platform_condvar *platform_condvar_init()
+{
+ struct platform_condvar *cond = malloc(sizeof(struct platform_condvar));
+ if (!cond) {
+ return NULL;
+ }
- if (pthread_cond_init(&cond->var, NULL)) {
- free(cond);
- return NULL;
- }
+ if (pthread_cond_init(&cond->var, NULL)) {
+ free(cond);
+ return NULL;
+ }
- return cond;
+ return cond;
}
void platform_condvar_wait(struct platform_condvar *condvar,
- struct platform_mutex *mutex) {
- pthread_cond_wait(&condvar->var, &mutex->lock);
+ struct platform_mutex *mutex)
+{
+ pthread_cond_wait(&condvar->var, &mutex->lock);
}
-void platform_condvar_signal(struct platform_condvar *condvar) {
- pthread_cond_signal(&condvar->var);
+void platform_condvar_signal(struct platform_condvar *condvar)
+{
+ pthread_cond_signal(&condvar->var);
}
diff --git a/ppm_common.c b/ppm_common.c
index 9655f0e..e15704c 100644
--- a/ppm_common.c
+++ b/ppm_common.c
@@ -3,701 +3,766 @@
* found in the LICENSE file.
*/
-#include "ppm_common.h"
-
#include "include/pd_driver.h"
#include "include/platform.h"
#include "include/ppm.h"
+#include "ppm_common.h"
-const char* ppm_state_strings[PPM_STATE_MAX] = {
- "PPM_STATE_NOT_READY", "PPM_STATE_IDLE",
- "PPM_STATE_IDLE_NOTIFY", "PPM_STATE_PROCESSING_COMMAND",
- "PPM_STATE_WAITING_CC_ACK", "PPM_STATE_WAITING_ASYNC_EV_ACK",
+const char *ppm_state_strings[PPM_STATE_MAX] = {
+ "PPM_STATE_NOT_READY", "PPM_STATE_IDLE",
+ "PPM_STATE_IDLE_NOTIFY", "PPM_STATE_PROCESSING_COMMAND",
+ "PPM_STATE_WAITING_CC_ACK", "PPM_STATE_WAITING_ASYNC_EV_ACK",
};
-const char* ppm_state_to_string(int state) {
- if (state < PPM_STATE_NOT_READY || state >= PPM_STATE_MAX) {
- return "PPM_STATE_Outside_valid_range";
- }
+const char *ppm_state_to_string(int state)
+{
+ if (state < PPM_STATE_NOT_READY || state >= PPM_STATE_MAX) {
+ return "PPM_STATE_Outside_valid_range";
+ }
- return ppm_state_strings[state];
+ return ppm_state_strings[state];
}
-const char* ucsi_cmd_strings[UCSI_CMD_VENDOR_CMD + 1] = {
- "UCSI_CMD_RESERVED",
- "UCSI_CMD_PPM_RESET",
- "UCSI_CMD_CANCEL",
- "UCSI_CMD_CONNECTOR_RESET",
- "UCSI_CMD_ACK_CC_CI",
- "UCSI_CMD_SET_NOTIFICATION_ENABLE",
- "UCSI_CMD_GET_CAPABILITY",
- "UCSI_CMD_GET_CONNECTOR_CAPABILITY",
- "UCSI_CMD_SET_CCOM",
- "UCSI_CMD_SET_UOR",
- "obsolete_UCSI_CMD_SET_PDM",
- "UCSI_CMD_SET_PDR",
- "UCSI_CMD_GET_ALTERNATE_MODES",
- "UCSI_CMD_GET_CAM_SUPPORTED",
- "UCSI_CMD_GET_CURRENT_CAM",
- "UCSI_CMD_SET_NEW_CAM",
- "UCSI_CMD_GET_PDOS",
- "UCSI_CMD_GET_CABLE_PROPERTY",
- "UCSI_CMD_GET_CONNECTOR_STATUS",
- "UCSI_CMD_GET_ERROR_STATUS",
- "UCSI_CMD_SET_POWER_LEVEL",
- "UCSI_CMD_GET_PD_MESSAGE",
- "UCSI_CMD_GET_ATTENTION_VDO",
- "UCSI_CMD_reserved_0x17",
- "UCSI_CMD_GET_CAM_CS",
- "UCSI_CMD_LPM_FW_UPDATE_REQUEST",
- "UCSI_CMD_SECURITY_REQUEST",
- "UCSI_CMD_SET_RETIMER_MODE",
- "UCSI_CMD_SET_SINK_PATH",
- "UCSI_CMD_SET_PDOS",
- "UCSI_CMD_READ_POWER_LEVEL",
- "UCSI_CMD_CHUNKING_SUPPORT",
- "UCSI_CMD_VENDOR_CMD",
+const char *ucsi_cmd_strings[UCSI_CMD_VENDOR_CMD + 1] = {
+ "UCSI_CMD_RESERVED",
+ "UCSI_CMD_PPM_RESET",
+ "UCSI_CMD_CANCEL",
+ "UCSI_CMD_CONNECTOR_RESET",
+ "UCSI_CMD_ACK_CC_CI",
+ "UCSI_CMD_SET_NOTIFICATION_ENABLE",
+ "UCSI_CMD_GET_CAPABILITY",
+ "UCSI_CMD_GET_CONNECTOR_CAPABILITY",
+ "UCSI_CMD_SET_CCOM",
+ "UCSI_CMD_SET_UOR",
+ "obsolete_UCSI_CMD_SET_PDM",
+ "UCSI_CMD_SET_PDR",
+ "UCSI_CMD_GET_ALTERNATE_MODES",
+ "UCSI_CMD_GET_CAM_SUPPORTED",
+ "UCSI_CMD_GET_CURRENT_CAM",
+ "UCSI_CMD_SET_NEW_CAM",
+ "UCSI_CMD_GET_PDOS",
+ "UCSI_CMD_GET_CABLE_PROPERTY",
+ "UCSI_CMD_GET_CONNECTOR_STATUS",
+ "UCSI_CMD_GET_ERROR_STATUS",
+ "UCSI_CMD_SET_POWER_LEVEL",
+ "UCSI_CMD_GET_PD_MESSAGE",
+ "UCSI_CMD_GET_ATTENTION_VDO",
+ "UCSI_CMD_reserved_0x17",
+ "UCSI_CMD_GET_CAM_CS",
+ "UCSI_CMD_LPM_FW_UPDATE_REQUEST",
+ "UCSI_CMD_SECURITY_REQUEST",
+ "UCSI_CMD_SET_RETIMER_MODE",
+ "UCSI_CMD_SET_SINK_PATH",
+ "UCSI_CMD_SET_PDOS",
+ "UCSI_CMD_READ_POWER_LEVEL",
+ "UCSI_CMD_CHUNKING_SUPPORT",
+ "UCSI_CMD_VENDOR_CMD",
};
-const char* ucsi_command_to_string(uint8_t command) {
- if (command > UCSI_CMD_VENDOR_CMD) {
- return "UCSI_CMD_Outside_valid_range";
- }
+const char *ucsi_command_to_string(uint8_t command)
+{
+ if (command > UCSI_CMD_VENDOR_CMD) {
+ return "UCSI_CMD_Outside_valid_range";
+ }
- return ucsi_cmd_strings[command];
+ return ucsi_cmd_strings[command];
}
-#define DEV_CAST_FROM(v) (struct ppm_common_device*)(v)
+#define DEV_CAST_FROM(v) (struct ppm_common_device *)(v)
-static void clear_cci(struct ppm_common_device* dev) {
- platform_memset(&dev->ucsi_data.cci, 0, sizeof(struct ucsi_cci));
+static void clear_cci(struct ppm_common_device *dev)
+{
+ platform_memset(&dev->ucsi_data.cci, 0, sizeof(struct ucsi_cci));
}
-static void clear_last_error(struct ppm_common_device* dev) {
- dev->last_error = ERROR_LPM;
- platform_memset(&dev->ppm_error_result, 0,
- sizeof(struct ucsiv3_get_error_status_data));
+static void clear_last_error(struct ppm_common_device *dev)
+{
+ dev->last_error = ERROR_LPM;
+ platform_memset(&dev->ppm_error_result, 0,
+ sizeof(struct ucsiv3_get_error_status_data));
}
-inline static void set_cci_error(struct ppm_common_device* dev) {
- clear_cci(dev);
- dev->ucsi_data.cci.error = 1;
- dev->ucsi_data.cci.cmd_complete = 1;
+inline static void set_cci_error(struct ppm_common_device *dev)
+{
+ clear_cci(dev);
+ dev->ucsi_data.cci.error = 1;
+ dev->ucsi_data.cci.cmd_complete = 1;
}
-static bool is_pending_async_event(struct ppm_common_device* dev) {
- return dev->pending.async_event;
+static bool is_pending_async_event(struct ppm_common_device *dev)
+{
+ return dev->pending.async_event;
}
-static int ppm_common_opm_notify(struct ppm_common_device* dev) {
- if (dev->opm_notify) {
- uint32_t cci;
+static int ppm_common_opm_notify(struct ppm_common_device *dev)
+{
+ if (dev->opm_notify) {
+ uint32_t cci;
- platform_memcpy(&cci, &dev->ucsi_data.cci, sizeof(uint32_t));
- DLOG("Notifying with CCI = 0x%08x", cci);
- dev->opm_notify(dev->opm_context);
- return 0;
- } else {
- ELOG("User error: No notifier!");
- }
+ platform_memcpy(&cci, &dev->ucsi_data.cci, sizeof(uint32_t));
+ DLOG("Notifying with CCI = 0x%08x", cci);
+ dev->opm_notify(dev->opm_context);
+ return 0;
+ } else {
+ ELOG("User error: No notifier!");
+ }
- return -1;
+ return -1;
}
-static void clear_pending_command(struct ppm_common_device* dev) {
- if (dev->pending.command) {
- DLOG("Cleared pending command[0x%x]", dev->ucsi_data.control.command);
- }
- dev->pending.command = 0;
+static void clear_pending_command(struct ppm_common_device *dev)
+{
+ if (dev->pending.command) {
+ DLOG("Cleared pending command[0x%x]",
+ dev->ucsi_data.control.command);
+ }
+ dev->pending.command = 0;
}
-static void ppm_common_handle_async_event(struct ppm_common_device* dev) {
- uint8_t port;
- struct ucsiv3_get_connector_status_data* port_status;
- bool alert_port = false;
+static void ppm_common_handle_async_event(struct ppm_common_device *dev)
+{
+ uint8_t port;
+ struct ucsiv3_get_connector_status_data *port_status;
+ bool alert_port = false;
- // Handle any smbus alert.
- if (dev->pending.async_event) {
- DLOG("PPM: Saw async event and processing.");
+ // Handle any smbus alert.
+ if (dev->pending.async_event) {
+ DLOG("PPM: Saw async event and processing.");
- // If we are in the not ready or IDLE (no notifications) state, we do not
- // bother updating OPM with status. Just clear the async event and move on.
- if (dev->ppm_state == PPM_STATE_NOT_READY ||
- dev->ppm_state == PPM_STATE_IDLE) {
- dev->pending.async_event = 0;
- return;
- }
+ // If we are in the not ready or IDLE (no notifications) state,
+ // we do not bother updating OPM with status. Just clear the
+ // async event and move on.
+ if (dev->ppm_state == PPM_STATE_NOT_READY ||
+ dev->ppm_state == PPM_STATE_IDLE) {
+ dev->pending.async_event = 0;
+ return;
+ }
- // Read per-port status if this is a fresh async event from an LPM alert.
- if (dev->last_connector_alerted != -1) {
- DLOG("Calling GET_CONNECTOR_STATUS on port %d",
- dev->last_connector_alerted);
+ // Read per-port status if this is a fresh async event from an
+ // LPM alert.
+ if (dev->last_connector_alerted != -1) {
+ DLOG("Calling GET_CONNECTOR_STATUS on port %d",
+ dev->last_connector_alerted);
- struct ucsi_control get_cs_cmd;
- platform_memset((void*)&get_cs_cmd, 0, sizeof(struct ucsi_control));
+ struct ucsi_control get_cs_cmd;
+ platform_memset((void *)&get_cs_cmd, 0,
+ sizeof(struct ucsi_control));
- get_cs_cmd.command = UCSI_CMD_GET_CONNECTOR_STATUS;
- get_cs_cmd.data_length = 0x0;
- get_cs_cmd.command_specific[0] = dev->last_connector_alerted;
+ get_cs_cmd.command = UCSI_CMD_GET_CONNECTOR_STATUS;
+ get_cs_cmd.data_length = 0x0;
+ get_cs_cmd.command_specific[0] =
+ dev->last_connector_alerted;
- // Clear port status before reading.
- port = dev->last_connector_alerted - 1;
- port_status = &dev->per_port_status[port];
- platform_memset(port_status, 0,
- sizeof(struct ucsiv3_get_connector_status_data));
+ // Clear port status before reading.
+ port = dev->last_connector_alerted - 1;
+ port_status = &dev->per_port_status[port];
+ platform_memset(
+ port_status, 0,
+ sizeof(struct ucsiv3_get_connector_status_data));
- if (dev->pd->execute_cmd(dev->pd->dev, &get_cs_cmd,
- (uint8_t*)port_status) == -1) {
- ELOG("Failed to read port %d status. No recovery.", port + 1);
- } else {
- DLOG("Port status change on %d: 0x%x", port + 1,
- (uint16_t)port_status->connector_status_change);
- }
+ if (dev->pd->execute_cmd(dev->pd->dev, &get_cs_cmd,
+ (uint8_t *)port_status) ==
+ -1) {
+ ELOG("Failed to read port %d status. No recovery.",
+ port + 1);
+ } else {
+ DLOG("Port status change on %d: 0x%x", port + 1,
+ (uint16_t)port_status
+ ->connector_status_change);
+ }
- // We got alerted with a change for a port we already sent notifications
- // for but which has not yet acked. Resend the notification.
- if (port == dev->last_connector_changed) {
- alert_port = true;
- }
+ // We got alerted with a change for a port we already
+ // sent notifications for but which has not yet acked.
+ // Resend the notification.
+ if (port == dev->last_connector_changed) {
+ alert_port = true;
+ }
- dev->last_connector_alerted = -1;
- }
+ dev->last_connector_alerted = -1;
+ }
- // If we are not already acting on an existing connector change, notify the
- // OS if there are any other connector changes.
- if (dev->last_connector_changed == -1) {
- // Find the first port with any pending change.
- for (port = 0; port < dev->num_ports; ++port) {
- if (dev->per_port_status[port].connector_status_change != 0) {
- break;
- }
- }
+ // If we are not already acting on an existing connector change,
+ // notify the OS if there are any other connector changes.
+ if (dev->last_connector_changed == -1) {
+ // Find the first port with any pending change.
+ for (port = 0; port < dev->num_ports; ++port) {
+ if (dev->per_port_status[port]
+ .connector_status_change != 0) {
+ break;
+ }
+ }
- // Handle events in order by setting CCI and notifying OPM.
- if (port < dev->num_ports) {
- alert_port = true;
- } else {
- DLOG("No more ports needing OPM alerting");
- }
- }
+ // Handle events in order by setting CCI and notifying
+ // OPM.
+ if (port < dev->num_ports) {
+ alert_port = true;
+ } else {
+ DLOG("No more ports needing OPM alerting");
+ }
+ }
- // Should we alert?
- if (alert_port) {
- DLOG("Notifying async event for port %d and changing state from %d (%s)",
- port + 1, dev->ppm_state, ppm_state_to_string(dev->ppm_state));
- // Notify the OPM that we have data for it to read.
- clear_cci(dev);
- dev->last_connector_changed = port;
- dev->ucsi_data.cci.connector_changed = port + 1;
- ppm_common_opm_notify(dev);
+ // Should we alert?
+ if (alert_port) {
+ DLOG("Notifying async event for port %d and changing state from %d (%s)",
+ port + 1, dev->ppm_state,
+ ppm_state_to_string(dev->ppm_state));
+ // Notify the OPM that we have data for it to read.
+ clear_cci(dev);
+ dev->last_connector_changed = port;
+ dev->ucsi_data.cci.connector_changed = port + 1;
+ ppm_common_opm_notify(dev);
- // Set PPM state to waiting for async event ack
- dev->ppm_state = PPM_STATE_WAITING_ASYNC_EV_ACK;
- }
+ // Set PPM state to waiting for async event ack
+ dev->ppm_state = PPM_STATE_WAITING_ASYNC_EV_ACK;
+ }
- // Clear the pending bit.
- dev->pending.async_event = 0;
- }
+ // Clear the pending bit.
+ dev->pending.async_event = 0;
+ }
}
-static bool is_pending_command(struct ppm_common_device* dev) {
- return dev->pending.command;
+static bool is_pending_command(struct ppm_common_device *dev)
+{
+ return dev->pending.command;
}
-static bool match_pending_command(struct ppm_common_device* dev,
- uint8_t command) {
- return dev->pending.command && dev->ucsi_data.control.command == command;
+static bool match_pending_command(struct ppm_common_device *dev,
+ uint8_t command)
+{
+ return dev->pending.command &&
+ dev->ucsi_data.control.command == command;
}
-static int ppm_common_execute_pending_cmd(struct ppm_common_device* dev) {
- struct ucsi_control* control = &dev->ucsi_data.control;
- struct ucsi_cci* cci = &dev->ucsi_data.cci;
- uint8_t* message_in = (uint8_t*)&dev->ucsi_data.message_in;
- uint8_t ucsi_command = control->command;
- int ret = -1;
- bool ack_ci = false;
+static int ppm_common_execute_pending_cmd(struct ppm_common_device *dev)
+{
+ struct ucsi_control *control = &dev->ucsi_data.control;
+ struct ucsi_cci *cci = &dev->ucsi_data.cci;
+ uint8_t *message_in = (uint8_t *)&dev->ucsi_data.message_in;
+ uint8_t ucsi_command = control->command;
+ int ret = -1;
+ bool ack_ci = false;
- if (control->command == 0 || control->command > UCSI_CMD_VENDOR_CMD) {
- ELOG("Invalid command 0x%x", control->command);
+ if (control->command == 0 || control->command > UCSI_CMD_VENDOR_CMD) {
+ ELOG("Invalid command 0x%x", control->command);
- // Set error condition to invalid command.
- clear_last_error(dev);
- dev->last_error = ERROR_PPM;
- dev->ppm_error_result.error_information.unrecognized_command = 1;
- set_cci_error(dev);
- return -1;
- }
+ // Set error condition to invalid command.
+ clear_last_error(dev);
+ dev->last_error = ERROR_PPM;
+ dev->ppm_error_result.error_information.unrecognized_command =
+ 1;
+ set_cci_error(dev);
+ return -1;
+ }
- switch (ucsi_command) {
- case UCSI_CMD_ACK_CC_CI:
- struct ucsiv3_ack_cc_ci_cmd* ack_cmd =
- (struct ucsiv3_ack_cc_ci_cmd*)control->command_specific;
- // The ack should already validated before we reach here.
- ack_ci = ack_cmd->connector_change_ack;
- break;
+ switch (ucsi_command) {
+ case UCSI_CMD_ACK_CC_CI:
+ struct ucsiv3_ack_cc_ci_cmd *ack_cmd =
+ (struct ucsiv3_ack_cc_ci_cmd *)control->command_specific;
+ // The ack should already validated before we reach here.
+ ack_ci = ack_cmd->connector_change_ack;
+ break;
- case UCSI_CMD_GET_ERROR_STATUS:
- // If the error status came from the PPM, return the cached value and skip
- // the |execute_cmd| in the pd_driver.
- if (dev->last_error == ERROR_PPM) {
- ret = sizeof(struct ucsiv3_get_error_status_data);
- platform_memcpy(message_in, &dev->ppm_error_result, ret);
- goto success;
- }
- break;
- default:
- break;
- }
+ case UCSI_CMD_GET_ERROR_STATUS:
+ // If the error status came from the PPM, return the cached
+ // value and skip the |execute_cmd| in the pd_driver.
+ if (dev->last_error == ERROR_PPM) {
+ ret = sizeof(struct ucsiv3_get_error_status_data);
+ platform_memcpy(message_in, &dev->ppm_error_result,
+ ret);
+ goto success;
+ }
+ break;
+ default:
+ break;
+ }
- // Do driver specific execute command.
- ret = dev->pd->execute_cmd(dev->pd->dev, control, message_in);
+ // Do driver specific execute command.
+ ret = dev->pd->execute_cmd(dev->pd->dev, control, message_in);
- // Clear command since we just executed it.
- platform_memset(control, 0, sizeof(struct ucsi_control));
+ // Clear command since we just executed it.
+ platform_memset(control, 0, sizeof(struct ucsi_control));
- if (ret < 0) {
- ELOG("Error with UCSI command 0x%x. Return was %d", ucsi_command, ret);
- clear_last_error(dev);
- dev->last_error = ERROR_LPM;
- set_cci_error(dev);
- return ret;
- }
+ if (ret < 0) {
+ ELOG("Error with UCSI command 0x%x. Return was %d",
+ ucsi_command, ret);
+ clear_last_error(dev);
+ dev->last_error = ERROR_LPM;
+ set_cci_error(dev);
+ return ret;
+ }
success:
- DLOG("Completed UCSI command 0x%x (%s)", ucsi_command,
- ucsi_command_to_string(ucsi_command));
- clear_cci(dev);
+ DLOG("Completed UCSI command 0x%x (%s)", ucsi_command,
+ ucsi_command_to_string(ucsi_command));
+ clear_cci(dev);
- // Post-success command handling
- if (ack_ci) {
- struct ucsiv3_get_connector_status_data* port_status =
- &dev->per_port_status[dev->last_connector_changed];
- // Clear port status for acked connector.
- port_status->connector_status_change = 0;
- dev->last_connector_changed = -1;
- // Flag a pending async event to process next event if it exists.
- dev->pending.async_event = 1;
- }
+ // Post-success command handling
+ if (ack_ci) {
+ struct ucsiv3_get_connector_status_data *port_status =
+ &dev->per_port_status[dev->last_connector_changed];
+ // Clear port status for acked connector.
+ port_status->connector_status_change = 0;
+ dev->last_connector_changed = -1;
+ // Flag a pending async event to process next event if it
+ // exists.
+ dev->pending.async_event = 1;
+ }
- // If we reset, we only surface up the reset completed event after busy.
- if (ucsi_command == UCSI_CMD_PPM_RESET) {
- cci->reset_completed = 1;
- } else {
- cci->data_length = ret & 0xFF;
- cci->cmd_complete = 1;
- }
- return 0;
+ // If we reset, we only surface up the reset completed event after busy.
+ if (ucsi_command == UCSI_CMD_PPM_RESET) {
+ cci->reset_completed = 1;
+ } else {
+ cci->data_length = ret & 0xFF;
+ cci->cmd_complete = 1;
+ }
+ return 0;
}
-inline static bool check_ack_has_valid_bits(struct ucsiv3_ack_cc_ci_cmd* cmd) {
- return cmd->command_complete_ack || cmd->connector_change_ack;
+inline static bool check_ack_has_valid_bits(struct ucsiv3_ack_cc_ci_cmd *cmd)
+{
+ return cmd->command_complete_ack || cmd->connector_change_ack;
}
-inline static bool check_ack_has_valid_ci(struct ucsiv3_ack_cc_ci_cmd* cmd,
- struct ppm_common_device* dev) {
- return cmd->connector_change_ack ? dev->last_connector_changed != -1 : 1;
+inline static bool check_ack_has_valid_ci(struct ucsiv3_ack_cc_ci_cmd *cmd,
+ struct ppm_common_device *dev)
+{
+ return cmd->connector_change_ack ? dev->last_connector_changed != -1 :
+ 1;
}
-inline static bool check_ack_has_valid_cc(struct ucsiv3_ack_cc_ci_cmd* cmd,
- struct ppm_common_device* dev) {
- return cmd->command_complete_ack ? dev->ppm_state == PPM_STATE_WAITING_CC_ACK
- : 1;
+inline static bool check_ack_has_valid_cc(struct ucsiv3_ack_cc_ci_cmd *cmd,
+ struct ppm_common_device *dev)
+{
+ return cmd->command_complete_ack ?
+ dev->ppm_state == PPM_STATE_WAITING_CC_ACK :
+ 1;
}
-inline static bool is_invalid_ack(struct ppm_common_device* dev) {
- struct ucsiv3_ack_cc_ci_cmd* cmd =
- (struct ucsiv3_ack_cc_ci_cmd*)dev->ucsi_data.control.command_specific;
- return (!(check_ack_has_valid_bits(cmd) && check_ack_has_valid_ci(cmd, dev) &&
- check_ack_has_valid_cc(cmd, dev)));
+inline static bool is_invalid_ack(struct ppm_common_device *dev)
+{
+ struct ucsiv3_ack_cc_ci_cmd *cmd =
+ (struct ucsiv3_ack_cc_ci_cmd *)
+ dev->ucsi_data.control.command_specific;
+ return (!(check_ack_has_valid_bits(cmd) &&
+ check_ack_has_valid_ci(cmd, dev) &&
+ check_ack_has_valid_cc(cmd, dev)));
}
-static void invalid_ack_notify(struct ppm_common_device* dev) {
- struct ucsiv3_ack_cc_ci_cmd* cmd =
- (struct ucsiv3_ack_cc_ci_cmd*)dev->ucsi_data.control.command_specific;
- ELOG(
- "Invalid ack usage (CI=%d CC=%d last_connector_changed=%d) in "
- "state %d",
- cmd->connector_change_ack, cmd->command_complete_ack,
- dev->last_connector_changed, dev->ppm_state);
+static void invalid_ack_notify(struct ppm_common_device *dev)
+{
+ struct ucsiv3_ack_cc_ci_cmd *cmd =
+ (struct ucsiv3_ack_cc_ci_cmd *)
+ dev->ucsi_data.control.command_specific;
+ ELOG("Invalid ack usage (CI=%d CC=%d last_connector_changed=%d) in "
+ "state %d",
+ cmd->connector_change_ack, cmd->command_complete_ack,
+ dev->last_connector_changed, dev->ppm_state);
- clear_last_error(dev);
- dev->last_error = ERROR_PPM;
- dev->ppm_error_result.error_information.invalid_cmd_specific_params = 1;
+ clear_last_error(dev);
+ dev->last_error = ERROR_PPM;
+ dev->ppm_error_result.error_information.invalid_cmd_specific_params = 1;
- set_cci_error(dev);
- // TODO(UCSI WG): Clarify pending clear behavior in case of PPM error
- clear_pending_command(dev);
- ppm_common_opm_notify(dev);
+ set_cci_error(dev);
+ // TODO(UCSI WG): Clarify pending clear behavior in case of PPM error
+ clear_pending_command(dev);
+ ppm_common_opm_notify(dev);
}
// Handle pending command. When handling pending commands, it is recommended
// that dev->ppm_state changes or notifications are made only in
// this function. Error bits may be set by other functions.
-static void ppm_common_handle_pending_command(struct ppm_common_device* dev) {
- uint8_t next_command = 0;
- int ret;
+static void ppm_common_handle_pending_command(struct ppm_common_device *dev)
+{
+ uint8_t next_command = 0;
+ int ret;
- if (dev->pending.command) {
- // Check what command is currently pending.
- next_command = dev->ucsi_data.control.command;
+ if (dev->pending.command) {
+ // Check what command is currently pending.
+ next_command = dev->ucsi_data.control.command;
- DLOG("PEND_CMD: Started command processing in state %d (%s), cmd 0x%x (%s)",
- dev->ppm_state, ppm_state_to_string(dev->ppm_state), next_command,
- ucsi_command_to_string(next_command));
- switch (dev->ppm_state) {
- case PPM_STATE_IDLE:
- case PPM_STATE_IDLE_NOTIFY:
- // We are now processing the command. Change state, notify OPM and then
- // continue.
- dev->ppm_state = PPM_STATE_PROCESSING_COMMAND;
- clear_cci(dev);
- dev->ucsi_data.cci.busy = 1;
- ppm_common_opm_notify(dev);
- // Intentional fallthrough since we are now processing.
- case PPM_STATE_PROCESSING_COMMAND:
- // TODO - Handle the case where we have a command that takes multiple
- // smbus calls to process (i.e. firmware update).
- // If we were handling something that requires processing (i.e.
- // firmware update), we would not update to WAITING_CC_ACK until it was
- // completed.
- ret = ppm_common_execute_pending_cmd(dev);
- if (ret == -1) {
- // CCI error bits are handled by execute_pending_command
- dev->ppm_state = PPM_STATE_IDLE_NOTIFY;
- ppm_common_opm_notify(dev);
- break;
- }
+ DLOG("PEND_CMD: Started command processing in state %d (%s), cmd 0x%x (%s)",
+ dev->ppm_state, ppm_state_to_string(dev->ppm_state),
+ next_command, ucsi_command_to_string(next_command));
+ switch (dev->ppm_state) {
+ case PPM_STATE_IDLE:
+ case PPM_STATE_IDLE_NOTIFY:
+ // We are now processing the command. Change state,
+ // notify OPM and then continue.
+ dev->ppm_state = PPM_STATE_PROCESSING_COMMAND;
+ clear_cci(dev);
+ dev->ucsi_data.cci.busy = 1;
+ ppm_common_opm_notify(dev);
+ // Intentional fallthrough since we are now processing.
+ case PPM_STATE_PROCESSING_COMMAND:
+ // TODO - Handle the case where we have a command that
+ // takes multiple smbus calls to process (i.e. firmware
+ // update). If we were handling something that requires
+ // processing (i.e. firmware update), we would not
+ // update to WAITING_CC_ACK until it was completed.
+ ret = ppm_common_execute_pending_cmd(dev);
+ if (ret == -1) {
+ // CCI error bits are handled by
+ // execute_pending_command
+ dev->ppm_state = PPM_STATE_IDLE_NOTIFY;
+ ppm_common_opm_notify(dev);
+ break;
+ }
- // If we were handling a PPM Reset, we go straight back to idle and
- // clear any error indicators.
- if (next_command == UCSI_CMD_PPM_RESET) {
- dev->ppm_state = PPM_STATE_IDLE;
- clear_last_error(dev);
- } else if (next_command == UCSI_CMD_ACK_CC_CI) {
- // We've received a standalone CI ack after completing command
- // loop(s).
- dev->ppm_state = PPM_STATE_IDLE_NOTIFY;
+ // If we were handling a PPM Reset, we go straight back
+ // to idle and clear any error indicators.
+ if (next_command == UCSI_CMD_PPM_RESET) {
+ dev->ppm_state = PPM_STATE_IDLE;
+ clear_last_error(dev);
+ } else if (next_command == UCSI_CMD_ACK_CC_CI) {
+ // We've received a standalone CI ack after
+ // completing command loop(s).
+ dev->ppm_state = PPM_STATE_IDLE_NOTIFY;
- clear_cci(dev);
- dev->ucsi_data.cci.ack_command = 1;
- } else {
- dev->ppm_state = PPM_STATE_WAITING_CC_ACK;
- }
+ clear_cci(dev);
+ dev->ucsi_data.cci.ack_command = 1;
+ } else {
+ dev->ppm_state = PPM_STATE_WAITING_CC_ACK;
+ }
- // Notify OPM to handle result and wait for ack if we're not still
- // processing.
- if (dev->ppm_state != PPM_STATE_PROCESSING_COMMAND) {
- ppm_common_opm_notify(dev);
- }
- break;
- case PPM_STATE_WAITING_CC_ACK:
- case PPM_STATE_WAITING_ASYNC_EV_ACK:
- // If we successfully ACK, update CCI and notify. On error, the CCI will
- // already be set by |ppm_common_execute_pending_cmd|.
- ret = ppm_common_execute_pending_cmd(dev);
- if (ret != -1) {
- dev->ppm_state = PPM_STATE_IDLE_NOTIFY;
+ // Notify OPM to handle result and wait for ack if we're
+ // not still processing.
+ if (dev->ppm_state != PPM_STATE_PROCESSING_COMMAND) {
+ ppm_common_opm_notify(dev);
+ }
+ break;
+ case PPM_STATE_WAITING_CC_ACK:
+ case PPM_STATE_WAITING_ASYNC_EV_ACK:
+ // If we successfully ACK, update CCI and notify. On
+ // error, the CCI will already be set by
+ // |ppm_common_execute_pending_cmd|.
+ ret = ppm_common_execute_pending_cmd(dev);
+ if (ret != -1) {
+ dev->ppm_state = PPM_STATE_IDLE_NOTIFY;
- clear_cci(dev);
- dev->ucsi_data.cci.ack_command = 1;
- }
+ clear_cci(dev);
+ dev->ucsi_data.cci.ack_command = 1;
+ }
- ppm_common_opm_notify(dev);
- break;
- default:
- ELOG("Unhandled ppm state (%d) when handling pending command",
- dev->ppm_state);
- break;
- }
+ ppm_common_opm_notify(dev);
+ break;
+ default:
+ ELOG("Unhandled ppm state (%d) when handling pending command",
+ dev->ppm_state);
+ break;
+ }
- DLOG("PEND_CMD: Ended command processing in state %d (%s)", dev->ppm_state,
- ppm_state_to_string(dev->ppm_state));
+ DLOG("PEND_CMD: Ended command processing in state %d (%s)",
+ dev->ppm_state, ppm_state_to_string(dev->ppm_state));
- // Last thing is to clear the pending command bit before executing the
- // command.
- if (dev->ppm_state != PPM_STATE_PROCESSING_COMMAND) {
- clear_pending_command(dev);
- }
- }
+ // Last thing is to clear the pending command bit before
+ // executing the command.
+ if (dev->ppm_state != PPM_STATE_PROCESSING_COMMAND) {
+ clear_pending_command(dev);
+ }
+ }
}
-static void ppm_common_task(void* context) {
- struct ppm_common_device* dev = DEV_CAST_FROM(context);
+static void ppm_common_task(void *context)
+{
+ struct ppm_common_device *dev = DEV_CAST_FROM(context);
- if (!dev) {
- ELOG("Cannot start PPM task without valid device pointer: %p", dev);
- return;
- }
+ if (!dev) {
+ ELOG("Cannot start PPM task without valid device pointer: %p",
+ dev);
+ return;
+ }
- DLOG("PPM: Starting the ppm task");
+ DLOG("PPM: Starting the ppm task");
- platform_mutex_lock(dev->ppm_lock);
+ platform_mutex_lock(dev->ppm_lock);
- // Initialize the system state.
- dev->ppm_state = PPM_STATE_NOT_READY;
+ // Initialize the system state.
+ dev->ppm_state = PPM_STATE_NOT_READY;
- // Send PPM reset and set state to IDLE if successful.
- platform_memset(&dev->ucsi_data.control, 0, sizeof(struct ucsi_control));
- dev->ucsi_data.control.command = UCSI_CMD_PPM_RESET;
- if (dev->pd->execute_cmd(dev->pd->dev, &dev->ucsi_data.control,
- dev->ucsi_data.message_in) != -1) {
- dev->ppm_state = PPM_STATE_IDLE;
- platform_memset(&dev->ucsi_data.cci, 0, sizeof(struct ucsi_cci));
- }
+ // Send PPM reset and set state to IDLE if successful.
+ platform_memset(&dev->ucsi_data.control, 0,
+ sizeof(struct ucsi_control));
+ dev->ucsi_data.control.command = UCSI_CMD_PPM_RESET;
+ if (dev->pd->execute_cmd(dev->pd->dev, &dev->ucsi_data.control,
+ dev->ucsi_data.message_in) != -1) {
+ dev->ppm_state = PPM_STATE_IDLE;
+ platform_memset(&dev->ucsi_data.cci, 0,
+ sizeof(struct ucsi_cci));
+ }
- // TODO - Note to self
- //
- // Smbus function calls are currently done with PPM lock; may need to fix
- // that.
- do {
- // Wait for a task from OPM unless we are already processing a command.
- if (dev->ppm_state != PPM_STATE_PROCESSING_COMMAND) {
- DLOG("Waiting for next command at state %d (%s)...", dev->ppm_state,
- ppm_state_to_string(dev->ppm_state));
- platform_condvar_wait(dev->ppm_condvar, dev->ppm_lock);
- }
+ // TODO - Note to self
+ //
+ // Smbus function calls are currently done with PPM lock; may need to
+ // fix that.
+ do {
+ // Wait for a task from OPM unless we are already processing a
+ // command.
+ if (dev->ppm_state != PPM_STATE_PROCESSING_COMMAND) {
+ DLOG("Waiting for next command at state %d (%s)...",
+ dev->ppm_state,
+ ppm_state_to_string(dev->ppm_state));
+ platform_condvar_wait(dev->ppm_condvar, dev->ppm_lock);
+ }
- DLOG("Handling next task at state %d (%s)", dev->ppm_state,
- ppm_state_to_string(dev->ppm_state));
+ DLOG("Handling next task at state %d (%s)", dev->ppm_state,
+ ppm_state_to_string(dev->ppm_state));
- switch (dev->ppm_state) {
- // Idle with notifications enabled.
- case PPM_STATE_IDLE:
- if (is_pending_command(dev)) {
- // Only handle SET_NOTIFICATION_ENABLE or PPM_RESET.
- // Otherwise clear the pending command.
- if (match_pending_command(dev, UCSI_CMD_SET_NOTIFICATION_ENABLE) ||
- match_pending_command(dev, UCSI_CMD_PPM_RESET)) {
- ppm_common_handle_pending_command(dev);
- } else {
- clear_pending_command(dev);
- }
- } else if (is_pending_async_event(dev)) {
- ppm_common_handle_async_event(dev);
- }
- break;
+ switch (dev->ppm_state) {
+ // Idle with notifications enabled.
+ case PPM_STATE_IDLE:
+ if (is_pending_command(dev)) {
+ // Only handle SET_NOTIFICATION_ENABLE or
+ // PPM_RESET. Otherwise clear the pending
+ // command.
+ if (match_pending_command(
+ dev,
+ UCSI_CMD_SET_NOTIFICATION_ENABLE) ||
+ match_pending_command(dev,
+ UCSI_CMD_PPM_RESET)) {
+ ppm_common_handle_pending_command(dev);
+ } else {
+ clear_pending_command(dev);
+ }
+ } else if (is_pending_async_event(dev)) {
+ ppm_common_handle_async_event(dev);
+ }
+ break;
- // Idle and waiting for a command or event.
- case PPM_STATE_IDLE_NOTIFY:
- // Check if you're acking in the right state for ACK_CC_CI. Only CI
- // acks are allowed here. i.e. we are still waiting for a CI ack after
- // a command loop was completed.
- if (is_pending_command(dev) &&
- match_pending_command(dev, UCSI_CMD_ACK_CC_CI) &&
- is_invalid_ack(dev)) {
- invalid_ack_notify(dev);
- break;
- }
+ // Idle and waiting for a command or event.
+ case PPM_STATE_IDLE_NOTIFY:
+ // Check if you're acking in the right state for
+ // ACK_CC_CI. Only CI acks are allowed here. i.e. we are
+ // still waiting for a CI ack after a command loop was
+ // completed.
+ if (is_pending_command(dev) &&
+ match_pending_command(dev, UCSI_CMD_ACK_CC_CI) &&
+ is_invalid_ack(dev)) {
+ invalid_ack_notify(dev);
+ break;
+ }
- if (is_pending_command(dev)) {
- ppm_common_handle_pending_command(dev);
- } else if (is_pending_async_event(dev)) {
- ppm_common_handle_async_event(dev);
- }
- break;
+ if (is_pending_command(dev)) {
+ ppm_common_handle_pending_command(dev);
+ } else if (is_pending_async_event(dev)) {
+ ppm_common_handle_async_event(dev);
+ }
+ break;
- // Processing a command. We only ever enter this state for firmware
- // update (for example if we're breaking up a chunk of firmware into
- // multiple transactions).
- case PPM_STATE_PROCESSING_COMMAND:
- ppm_common_handle_pending_command(dev);
- break;
+ // Processing a command. We only ever enter this state for
+ // firmware update (for example if we're breaking up a chunk of
+ // firmware into multiple transactions).
+ case PPM_STATE_PROCESSING_COMMAND:
+ ppm_common_handle_pending_command(dev);
+ break;
- // Waiting for a command completion acknowledge.
- case PPM_STATE_WAITING_CC_ACK:
- if (!match_pending_command(dev, UCSI_CMD_ACK_CC_CI) ||
- is_invalid_ack(dev)) {
- invalid_ack_notify(dev);
- break;
- }
- ppm_common_handle_pending_command(dev);
- break;
+ // Waiting for a command completion acknowledge.
+ case PPM_STATE_WAITING_CC_ACK:
+ if (!match_pending_command(dev, UCSI_CMD_ACK_CC_CI) ||
+ is_invalid_ack(dev)) {
+ invalid_ack_notify(dev);
+ break;
+ }
+ ppm_common_handle_pending_command(dev);
+ break;
- // Waiting for async event ack.
- case PPM_STATE_WAITING_ASYNC_EV_ACK:
- if (is_pending_command(dev)) {
- bool is_ack = match_pending_command(dev, UCSI_CMD_ACK_CC_CI);
- if (is_ack && is_invalid_ack(dev)) {
- invalid_ack_notify(dev);
- break;
- }
- // Waiting ASYNC_EV_ACK is a weird state. It can directly ACK the
- // CI or it can go into a PROCESSING_COMMAND state (in which case
- // it should be treated as a IDLE_NOTIFY).
- //
- // Thus, if we don't get UCSI_CMD_ACK_CC_CI here, we just treat
- // this as IDLE_NOTIFY state.
- if (!is_ack) {
- DLOG("ASYNC EV ACK state turned into IDLE_NOTIFY state");
- dev->ppm_state = PPM_STATE_IDLE_NOTIFY;
- }
- ppm_common_handle_pending_command(dev);
- }
- break;
+ // Waiting for async event ack.
+ case PPM_STATE_WAITING_ASYNC_EV_ACK:
+ if (is_pending_command(dev)) {
+ bool is_ack = match_pending_command(
+ dev, UCSI_CMD_ACK_CC_CI);
+ if (is_ack && is_invalid_ack(dev)) {
+ invalid_ack_notify(dev);
+ break;
+ }
+ // Waiting ASYNC_EV_ACK is a weird state. It can
+ // directly ACK the CI or it can go into a
+ // PROCESSING_COMMAND state (in which case it
+ // should be treated as a IDLE_NOTIFY).
+ //
+ // Thus, if we don't get UCSI_CMD_ACK_CC_CI
+ // here, we just treat this as IDLE_NOTIFY
+ // state.
+ if (!is_ack) {
+ DLOG("ASYNC EV ACK state turned into IDLE_NOTIFY state");
+ dev->ppm_state = PPM_STATE_IDLE_NOTIFY;
+ }
+ ppm_common_handle_pending_command(dev);
+ }
+ break;
- default:
- break;
- }
- } while (!dev->cleaning_up);
+ default:
+ break;
+ }
+ } while (!dev->cleaning_up);
- platform_mutex_unlock(dev->ppm_lock);
+ platform_mutex_unlock(dev->ppm_lock);
- platform_task_exit();
+ platform_task_exit();
}
-static int ppm_common_init_and_wait(struct ucsi_ppm_device* device,
- uint8_t num_ports) {
+static int ppm_common_init_and_wait(struct ucsi_ppm_device *device,
+ uint8_t num_ports)
+{
#define MAX_TIMEOUT_MS 1000
#define POLL_EVERY_MS 10
- struct ppm_common_device* dev = DEV_CAST_FROM(device);
- struct ucsi_memory_region* ucsi_data = &dev->ucsi_data;
- bool ready_to_exit = false;
+ struct ppm_common_device *dev = DEV_CAST_FROM(device);
+ struct ucsi_memory_region *ucsi_data = &dev->ucsi_data;
+ bool ready_to_exit = false;
- // First clear the PPM shared memory region.
- platform_memset(ucsi_data, 0, sizeof(*ucsi_data));
+ // First clear the PPM shared memory region.
+ platform_memset(ucsi_data, 0, sizeof(*ucsi_data));
- // Initialize to UCSI version 3.0
- ucsi_data->version.version = 0x0300;
- // TODO - Set real lpm address based on smbus driver.
- ucsi_data->version.lpm_address = 0x0;
+ // Initialize to UCSI version 3.0
+ ucsi_data->version.version = 0x0300;
+ // TODO - Set real lpm address based on smbus driver.
+ ucsi_data->version.lpm_address = 0x0;
- // Init lock to sync PPM task and main task context.
- dev->ppm_lock = platform_mutex_init();
- if (!dev->ppm_lock) {
- return -1;
- }
+ // Init lock to sync PPM task and main task context.
+ dev->ppm_lock = platform_mutex_init();
+ if (!dev->ppm_lock) {
+ return -1;
+ }
- // Init condvar to notify PPM task.
- dev->ppm_condvar = platform_condvar_init();
- if (!dev->ppm_condvar) {
- return -1;
- }
+ // Init condvar to notify PPM task.
+ dev->ppm_condvar = platform_condvar_init();
+ if (!dev->ppm_condvar) {
+ return -1;
+ }
- // Allocate per port status (used for PPM async event notifications).
- dev->num_ports = num_ports;
- dev->per_port_status = platform_calloc(
- dev->num_ports, sizeof(struct ucsiv3_get_connector_status_data));
- dev->last_connector_changed = -1;
+ // Allocate per port status (used for PPM async event notifications).
+ dev->num_ports = num_ports;
+ dev->per_port_status = platform_calloc(
+ dev->num_ports,
+ sizeof(struct ucsiv3_get_connector_status_data));
+ dev->last_connector_changed = -1;
- DLOG("Ready to initialize PPM task!");
+ DLOG("Ready to initialize PPM task!");
- // Initialize the PPM task.
- dev->ppm_task_handle = platform_task_init((void*)ppm_common_task, (void*)dev);
- if (!dev->ppm_task_handle) {
- ELOG("No ppm task created.");
- return -1;
- }
+ // Initialize the PPM task.
+ dev->ppm_task_handle =
+ platform_task_init((void *)ppm_common_task, (void *)dev);
+ if (!dev->ppm_task_handle) {
+ ELOG("No ppm task created.");
+ return -1;
+ }
- DLOG("PPM is waiting for task to run.");
+ DLOG("PPM is waiting for task to run.");
- for (int count = 0; count * POLL_EVERY_MS < MAX_TIMEOUT_MS; count++) {
- platform_mutex_lock(dev->ppm_lock);
- ready_to_exit = dev->ppm_state != PPM_STATE_NOT_READY;
- platform_mutex_unlock(dev->ppm_lock);
+ for (int count = 0; count * POLL_EVERY_MS < MAX_TIMEOUT_MS; count++) {
+ platform_mutex_lock(dev->ppm_lock);
+ ready_to_exit = dev->ppm_state != PPM_STATE_NOT_READY;
+ platform_mutex_unlock(dev->ppm_lock);
- if (ready_to_exit) {
- break;
- }
+ if (ready_to_exit) {
+ break;
+ }
- platform_usleep(POLL_EVERY_MS * 1000);
- }
+ platform_usleep(POLL_EVERY_MS * 1000);
+ }
- DLOG("PPM initialized result: Success=%b", ready_to_exit);
+ DLOG("PPM initialized result: Success=%b", ready_to_exit);
- return (ready_to_exit ? 0 : -1);
+ return (ready_to_exit ? 0 : -1);
}
-struct ucsi_memory_region* ppm_common_get_data_region(
- struct ucsi_ppm_device* device) {
- struct ppm_common_device* dev = DEV_CAST_FROM(device);
- return &dev->ucsi_data;
+struct ucsi_memory_region *
+ppm_common_get_data_region(struct ucsi_ppm_device *device)
+{
+ struct ppm_common_device *dev = DEV_CAST_FROM(device);
+ return &dev->ucsi_data;
}
bool ppm_common_get_next_connector_status(
- struct ucsi_ppm_device* device, uint8_t* out_port_num,
- struct ucsiv3_get_connector_status_data** out_connector_status) {
- struct ppm_common_device* dev = DEV_CAST_FROM(device);
+ struct ucsi_ppm_device *device, uint8_t *out_port_num,
+ struct ucsiv3_get_connector_status_data **out_connector_status)
+{
+ struct ppm_common_device *dev = DEV_CAST_FROM(device);
- if (dev->last_connector_changed != -1) {
- *out_port_num = (uint8_t)dev->last_connector_changed + 1;
- *out_connector_status = &dev->per_port_status[dev->last_connector_changed];
- return true;
- }
+ if (dev->last_connector_changed != -1) {
+ *out_port_num = (uint8_t)dev->last_connector_changed + 1;
+ *out_connector_status =
+ &dev->per_port_status[dev->last_connector_changed];
+ return true;
+ }
- return false;
+ return false;
}
-static int ppm_common_read(struct ucsi_ppm_device* device, unsigned int offset,
- void* buf, size_t length) {
- struct ppm_common_device* dev = DEV_CAST_FROM(device);
+static int ppm_common_read(struct ucsi_ppm_device *device, unsigned int offset,
+ void *buf, size_t length)
+{
+ struct ppm_common_device *dev = DEV_CAST_FROM(device);
- if (!dev) {
- return -1;
- }
+ if (!dev) {
+ return -1;
+ }
- // Validate memory to read and allow any offset for reading.
- if (offset + length >= sizeof(struct ucsi_memory_region)) {
- ELOG("UCSI read exceeds bounds of memory: offset(0x%x), length(0x%x)",
- offset, length);
- return -1;
- }
+ // Validate memory to read and allow any offset for reading.
+ if (offset + length >= sizeof(struct ucsi_memory_region)) {
+ ELOG("UCSI read exceeds bounds of memory: offset(0x%x), length(0x%x)",
+ offset, length);
+ return -1;
+ }
- platform_memcpy(buf, (const void*)((uint8_t*)(&dev->ucsi_data) + offset),
- length);
- return length;
+ platform_memcpy(buf,
+ (const void *)((uint8_t *)(&dev->ucsi_data) + offset),
+ length);
+ return length;
}
-static int ppm_common_handle_control_message(struct ppm_common_device* dev,
- const void* buf, size_t length) {
- const uint8_t* cmd = (const uint8_t*)buf;
- uint8_t prev_cmd;
- uint8_t busy = 0;
+static int ppm_common_handle_control_message(struct ppm_common_device *dev,
+ const void *buf, size_t length)
+{
+ const uint8_t *cmd = (const uint8_t *)buf;
+ uint8_t prev_cmd;
+ uint8_t busy = 0;
- if (length > sizeof(struct ucsi_control)) {
- ELOG("Tried to send control message that is an invalid size (%d)",
- (int)length);
- return -1;
- }
+ if (length > sizeof(struct ucsi_control)) {
+ ELOG("Tried to send control message that is an invalid size (%d)",
+ (int)length);
+ return -1;
+ }
- // If we're currently sending a command, we should immediately discard this
- // call.
- {
- platform_mutex_lock(dev->ppm_lock);
- busy = dev->pending.command || dev->ucsi_data.cci.busy;
- prev_cmd = dev->ucsi_data.control.command;
- platform_mutex_unlock(dev->ppm_lock);
- }
- if (busy) {
- ELOG(
- "Tried to send control message (cmd=0x%x) when one is already pending "
- "(cmd=0x%x).",
- cmd[0], prev_cmd);
- return -1;
- }
+ // If we're currently sending a command, we should immediately discard
+ // this call.
+ {
+ platform_mutex_lock(dev->ppm_lock);
+ busy = dev->pending.command || dev->ucsi_data.cci.busy;
+ prev_cmd = dev->ucsi_data.control.command;
+ platform_mutex_unlock(dev->ppm_lock);
+ }
+ if (busy) {
+ ELOG("Tried to send control message (cmd=0x%x) when one is already pending "
+ "(cmd=0x%x).",
+ cmd[0], prev_cmd);
+ return -1;
+ }
- // If we didn't get a full CONTROL message, zero the region before copying.
- if (length != sizeof(struct ucsi_control)) {
- platform_memset(&dev->ucsi_data.control, 0, sizeof(struct ucsi_control));
- }
- platform_memcpy(&dev->ucsi_data.control, cmd, length);
+ // If we didn't get a full CONTROL message, zero the region before
+ // copying.
+ if (length != sizeof(struct ucsi_control)) {
+ platform_memset(&dev->ucsi_data.control, 0,
+ sizeof(struct ucsi_control));
+ }
+ platform_memcpy(&dev->ucsi_data.control, cmd, length);
- DLOG("Got valid control message: 0x%x (%s)", cmd[0],
- ucsi_command_to_string(cmd[0]));
+ DLOG("Got valid control message: 0x%x (%s)", cmd[0],
+ ucsi_command_to_string(cmd[0]));
- // Schedule command send.
- {
- platform_mutex_lock(dev->ppm_lock);
+ // Schedule command send.
+ {
+ platform_mutex_lock(dev->ppm_lock);
- // Mark command pending.
- dev->pending.command = 1;
- platform_condvar_signal(dev->ppm_condvar);
+ // Mark command pending.
+ dev->pending.command = 1;
+ platform_condvar_signal(dev->ppm_condvar);
- DLOG("Signaled pending command");
+ DLOG("Signaled pending command");
- platform_mutex_unlock(dev->ppm_lock);
- }
+ platform_mutex_unlock(dev->ppm_lock);
+ }
- return 0;
+ return 0;
}
/*
@@ -714,135 +779,139 @@
Any writes into non-aligned offsets (except Message IN) will be discarded.
*/
-static int ppm_common_write(struct ucsi_ppm_device* device, unsigned int offset,
- const void* buf, size_t length) {
- struct ppm_common_device* dev = DEV_CAST_FROM(device);
- bool valid_fixed_offset;
+static int ppm_common_write(struct ucsi_ppm_device *device, unsigned int offset,
+ const void *buf, size_t length)
+{
+ struct ppm_common_device *dev = DEV_CAST_FROM(device);
+ bool valid_fixed_offset;
- if (!buf || length == 0) {
- ELOG("Invalid buffer (%p) or length (%x)", buf, length);
- return -1;
- }
+ if (!buf || length == 0) {
+ ELOG("Invalid buffer (%p) or length (%x)", buf, length);
+ return -1;
+ }
- valid_fixed_offset = (offset == UCSI_VERSION_OFFSET) ||
- (offset == UCSI_CCI_OFFSET) ||
- (offset == UCSI_CONTROL_OFFSET);
+ valid_fixed_offset = (offset == UCSI_VERSION_OFFSET) ||
+ (offset == UCSI_CCI_OFFSET) ||
+ (offset == UCSI_CONTROL_OFFSET);
- if (!valid_fixed_offset &&
- !(offset >= UCSI_MESSAGE_OUT_OFFSET &&
- offset < UCSI_MESSAGE_OUT_OFFSET + MESSAGE_OUT_SIZE)) {
- ELOG("UCSI can't write to invalid offset: 0x%x", offset);
- return -1;
- }
+ if (!valid_fixed_offset &&
+ !(offset >= UCSI_MESSAGE_OUT_OFFSET &&
+ offset < UCSI_MESSAGE_OUT_OFFSET + MESSAGE_OUT_SIZE)) {
+ ELOG("UCSI can't write to invalid offset: 0x%x", offset);
+ return -1;
+ }
- // Handle control messages
- if (offset == UCSI_CONTROL_OFFSET) {
- return ppm_common_handle_control_message(dev, buf, length);
- }
+ // Handle control messages
+ if (offset == UCSI_CONTROL_OFFSET) {
+ return ppm_common_handle_control_message(dev, buf, length);
+ }
- if (offset >= UCSI_MESSAGE_OUT_OFFSET &&
- offset + length >= UCSI_MESSAGE_OUT_OFFSET + MESSAGE_OUT_SIZE) {
- ELOG(
- "UCSI write to MESSAGE_OUT exceeds bounds: offset(0x%x) + size(0x%x) "
- ">= "
- "end(0x%x)",
- offset, length, UCSI_MESSAGE_OUT_OFFSET + MESSAGE_OUT_SIZE);
- return -1;
- }
+ if (offset >= UCSI_MESSAGE_OUT_OFFSET &&
+ offset + length >= UCSI_MESSAGE_OUT_OFFSET + MESSAGE_OUT_SIZE) {
+ ELOG("UCSI write to MESSAGE_OUT exceeds bounds: offset(0x%x) + size(0x%x) "
+ ">= "
+ "end(0x%x)",
+ offset, length,
+ UCSI_MESSAGE_OUT_OFFSET + MESSAGE_OUT_SIZE);
+ return -1;
+ }
- // Copy from input buffer to offset within MESSAGE_OUT.
- platform_memcpy(
- dev->ucsi_data.message_out + (offset - UCSI_MESSAGE_OUT_OFFSET), buf,
- length);
- return 0;
+ // Copy from input buffer to offset within MESSAGE_OUT.
+ platform_memcpy(dev->ucsi_data.message_out +
+ (offset - UCSI_MESSAGE_OUT_OFFSET),
+ buf, length);
+ return 0;
}
-static int ppm_common_register_notify(struct ucsi_ppm_device* device,
- ucsi_ppm_notify* callback,
- void* context) {
- struct ppm_common_device* dev = DEV_CAST_FROM(device);
- if (!dev) {
- return -1;
- }
+static int ppm_common_register_notify(struct ucsi_ppm_device *device,
+ ucsi_ppm_notify *callback, void *context)
+{
+ struct ppm_common_device *dev = DEV_CAST_FROM(device);
+ if (!dev) {
+ return -1;
+ }
- dev->opm_notify = callback;
- dev->opm_context = context;
- return 0;
+ dev->opm_notify = callback;
+ dev->opm_context = context;
+ return 0;
}
-static void ppm_common_lpm_alert(struct ucsi_ppm_device* device,
- uint8_t lpm_id) {
- struct ppm_common_device* dev = DEV_CAST_FROM(device);
+static void ppm_common_lpm_alert(struct ucsi_ppm_device *device, uint8_t lpm_id)
+{
+ struct ppm_common_device *dev = DEV_CAST_FROM(device);
- DLOG("LPM alert seen on port %d!", lpm_id);
+ DLOG("LPM alert seen on port %d!", lpm_id);
- platform_mutex_lock(dev->ppm_lock);
+ platform_mutex_lock(dev->ppm_lock);
- if (lpm_id <= dev->num_ports) {
- // Set async event and mark port status as not read.
- dev->pending.async_event = 1;
- dev->last_connector_alerted = lpm_id;
+ if (lpm_id <= dev->num_ports) {
+ // Set async event and mark port status as not read.
+ dev->pending.async_event = 1;
+ dev->last_connector_alerted = lpm_id;
- platform_condvar_signal(dev->ppm_condvar);
- } else {
- ELOG("Alert id out of range: %d (num_ports = %d)", lpm_id, dev->num_ports);
- }
+ platform_condvar_signal(dev->ppm_condvar);
+ } else {
+ ELOG("Alert id out of range: %d (num_ports = %d)", lpm_id,
+ dev->num_ports);
+ }
- platform_mutex_unlock(dev->ppm_lock);
+ platform_mutex_unlock(dev->ppm_lock);
}
-static void ppm_common_cleanup(struct ucsi_ppm_driver* driver) {
- if (driver->dev) {
- struct ppm_common_device* dev = DEV_CAST_FROM(driver->dev);
+static void ppm_common_cleanup(struct ucsi_ppm_driver *driver)
+{
+ if (driver->dev) {
+ struct ppm_common_device *dev = DEV_CAST_FROM(driver->dev);
- // Signal clean up to waiting thread.
- platform_mutex_lock(dev->ppm_lock);
- dev->cleaning_up = true;
- platform_condvar_signal(dev->ppm_condvar);
- platform_mutex_unlock(dev->ppm_lock);
+ // Signal clean up to waiting thread.
+ platform_mutex_lock(dev->ppm_lock);
+ dev->cleaning_up = true;
+ platform_condvar_signal(dev->ppm_condvar);
+ platform_mutex_unlock(dev->ppm_lock);
- // Wait for task to complete.
- platform_task_complete(dev->ppm_task_handle);
+ // Wait for task to complete.
+ platform_task_complete(dev->ppm_task_handle);
- platform_free(dev->ppm_condvar);
- platform_free(dev->ppm_lock);
+ platform_free(dev->ppm_condvar);
+ platform_free(dev->ppm_lock);
- platform_free(driver->dev);
- driver->dev = NULL;
- }
+ platform_free(driver->dev);
+ driver->dev = NULL;
+ }
}
-struct ucsi_ppm_driver* ppm_open(struct ucsi_pd_driver* pd_driver) {
- struct ppm_common_device* dev = NULL;
- struct ucsi_ppm_driver* drv = NULL;
+struct ucsi_ppm_driver *ppm_open(struct ucsi_pd_driver *pd_driver)
+{
+ struct ppm_common_device *dev = NULL;
+ struct ucsi_ppm_driver *drv = NULL;
- dev = platform_calloc(1, sizeof(struct ppm_common_device));
- if (!dev) {
- goto handle_error;
- }
+ dev = platform_calloc(1, sizeof(struct ppm_common_device));
+ if (!dev) {
+ goto handle_error;
+ }
- dev->pd = pd_driver;
+ dev->pd = pd_driver;
- drv = platform_calloc(1, sizeof(struct ucsi_ppm_driver));
- if (!drv) {
- goto handle_error;
- }
+ drv = platform_calloc(1, sizeof(struct ucsi_ppm_driver));
+ if (!drv) {
+ goto handle_error;
+ }
- drv->dev = (struct ucsi_ppm_device*)dev;
- drv->init_and_wait = ppm_common_init_and_wait;
- drv->get_data_region = ppm_common_get_data_region;
- drv->get_next_connector_status = ppm_common_get_next_connector_status;
- drv->read = ppm_common_read;
- drv->write = ppm_common_write;
- drv->register_notify = ppm_common_register_notify;
- drv->lpm_alert = ppm_common_lpm_alert;
- drv->cleanup = ppm_common_cleanup;
+ drv->dev = (struct ucsi_ppm_device *)dev;
+ drv->init_and_wait = ppm_common_init_and_wait;
+ drv->get_data_region = ppm_common_get_data_region;
+ drv->get_next_connector_status = ppm_common_get_next_connector_status;
+ drv->read = ppm_common_read;
+ drv->write = ppm_common_write;
+ drv->register_notify = ppm_common_register_notify;
+ drv->lpm_alert = ppm_common_lpm_alert;
+ drv->cleanup = ppm_common_cleanup;
- return drv;
+ return drv;
handle_error:
- platform_free(dev);
- platform_free(drv);
+ platform_free(dev);
+ platform_free(drv);
- return NULL;
+ return NULL;
}
diff --git a/ppm_common.h b/ppm_common.h
index 03ec9f8..4c2cf5a 100644
--- a/ppm_common.h
+++ b/ppm_common.h
@@ -6,57 +6,59 @@
#ifndef UM_PPM_PPM_COMMON_H_
#define UM_PPM_PPM_COMMON_H_
-#include <stdbool.h>
-#include <stdint.h>
-
#include "include/platform.h"
#include "include/ppm.h"
+#include <stdbool.h>
+#include <stdint.h>
+
// Forward declarations.
struct ucsi_pd_driver;
enum last_error_type {
- // Error came from LPM; GET_ERROR_STATUS should query the LPM for a value.
- ERROR_LPM,
+ // Error came from LPM; GET_ERROR_STATUS should query the LPM for a
+ // value.
+ ERROR_LPM,
- // Error came from PPM; GET_ERROR_STATUS should return directly from PPM.
- ERROR_PPM,
+ // Error came from PPM; GET_ERROR_STATUS should return directly from
+ // PPM.
+ ERROR_PPM,
};
// Internal data for ppm common implementation.
// Exposed for test purposes.
struct ppm_common_device {
- // Parent PD driver instance. Not OWNED.
- struct ucsi_pd_driver* pd;
+ // Parent PD driver instance. Not OWNED.
+ struct ucsi_pd_driver *pd;
- // Doorbell notification callback (and context).
- ucsi_ppm_notify* opm_notify;
- void* opm_context;
+ // Doorbell notification callback (and context).
+ ucsi_ppm_notify *opm_notify;
+ void *opm_context;
- // PPM task
- struct task_handle* ppm_task_handle;
- struct platform_mutex* ppm_lock;
- struct platform_condvar* ppm_condvar;
+ // PPM task
+ struct task_handle *ppm_task_handle;
+ struct platform_mutex *ppm_lock;
+ struct platform_condvar *ppm_condvar;
- // PPM state
- bool cleaning_up;
- enum ppm_states ppm_state;
- struct ppm_pending_data pending;
+ // PPM state
+ bool cleaning_up;
+ enum ppm_states ppm_state;
+ struct ppm_pending_data pending;
- // Port and status information
- uint8_t num_ports;
- struct ucsiv3_get_connector_status_data* per_port_status;
+ // Port and status information
+ uint8_t num_ports;
+ struct ucsiv3_get_connector_status_data *per_port_status;
- // Port number is 7 bits. 8-th bit can be sign.
- int8_t last_connector_changed;
- int8_t last_connector_alerted;
+ // Port number is 7 bits. 8-th bit can be sign.
+ int8_t last_connector_changed;
+ int8_t last_connector_alerted;
- // Data dedicated to UCSI operation.
- struct ucsi_memory_region ucsi_data;
+ // Data dedicated to UCSI operation.
+ struct ucsi_memory_region ucsi_data;
- // Last error status info.
- enum last_error_type last_error;
- struct ucsiv3_get_error_status_data ppm_error_result;
+ // Last error status info.
+ enum last_error_type last_error;
+ struct ucsiv3_get_error_status_data ppm_error_result;
};
/**
@@ -66,6 +68,6 @@
* up. The PPM will retain a pointer to the pd driver in order to execute
* commands (and any other PD driver specific actions).
*/
-struct ucsi_ppm_driver* ppm_open(struct ucsi_pd_driver* pd_driver);
+struct ucsi_ppm_driver *ppm_open(struct ucsi_pd_driver *pd_driver);
-#endif // UM_PPM_PPM_COMMON_H_
+#endif // UM_PPM_PPM_COMMON_H_
diff --git a/rts5453.c b/rts5453.c
index c81390b..433e815 100644
--- a/rts5453.c
+++ b/rts5453.c
@@ -3,147 +3,152 @@
* found in the LICENSE file.
*/
-#include "rts5453.h"
-
-#include <stdbool.h>
-
#include "include/pd_driver.h"
#include "include/platform.h"
#include "include/ppm.h"
#include "ppm_common.h"
+#include "rts5453.h"
+
+#include <stdbool.h>
#define SMBUS_MAX_BLOCK_SIZE 32
struct rts5453_device {
- // LPM smbus driver.
- struct smbus_driver* smbus;
+ // LPM smbus driver.
+ struct smbus_driver *smbus;
- // PPM driver (common implementation).
- struct ucsi_ppm_driver* ppm;
+ // PPM driver (common implementation).
+ struct ucsi_ppm_driver *ppm;
- // Re-usable command buffer for active command.
- uint8_t cmd_buffer[SMBUS_MAX_BLOCK_SIZE];
+ // Re-usable command buffer for active command.
+ uint8_t cmd_buffer[SMBUS_MAX_BLOCK_SIZE];
- // Configuration for this driver.
- struct pd_driver_config* driver_config;
+ // Configuration for this driver.
+ struct pd_driver_config *driver_config;
- // Number of active ports from |GET_CAPABILITIES|.
- uint8_t active_port_count;
+ // Number of active ports from |GET_CAPABILITIES|.
+ uint8_t active_port_count;
- // IRQ task for LPM interrupts.
- struct task_handle* lpm_interrupt_task;
+ // IRQ task for LPM interrupts.
+ struct task_handle *lpm_interrupt_task;
};
-#define CAST_FROM(v) (struct rts5453_device*)(v)
+#define CAST_FROM(v) (struct rts5453_device *)(v)
enum rts5453_smbus_commands {
- SC_VENDOR_CMD,
- SC_GET_IC_STATUS,
- SC_GET_VDO,
+ SC_VENDOR_CMD,
+ SC_GET_IC_STATUS,
+ SC_GET_VDO,
- SC_WRITE_FLASH_0K_64K,
- SC_WRITE_FLASH_64K_128K,
- SC_WRITE_FLASH_128K_192K,
- SC_WRITE_FLASH_192K_256K,
+ SC_WRITE_FLASH_0K_64K,
+ SC_WRITE_FLASH_64K_128K,
+ SC_WRITE_FLASH_128K_192K,
+ SC_WRITE_FLASH_192K_256K,
- SC_READ_FLASH_0K_64K,
- SC_READ_FLASH_64K_128K,
- SC_READ_FLASH_128K_192K,
- SC_READ_FLASH_192K_256K,
+ SC_READ_FLASH_0K_64K,
+ SC_READ_FLASH_64K_128K,
+ SC_READ_FLASH_128K_192K,
+ SC_READ_FLASH_192K_256K,
- SC_ERASE_FLASH,
- SC_GET_SPI_PROTECT,
- SC_SET_SPI_PROTECT,
- SC_ISP_VALIDATION,
- SC_RESET_TO_FLASH,
+ SC_ERASE_FLASH,
+ SC_GET_SPI_PROTECT,
+ SC_SET_SPI_PROTECT,
+ SC_ISP_VALIDATION,
+ SC_RESET_TO_FLASH,
- // Various ucsi commands
- SC_UCSI_COMMANDS,
- SC_SET_NOTIFICATION_ENABLE,
- SC_ACK_CC_CI,
+ // Various ucsi commands
+ SC_UCSI_COMMANDS,
+ SC_SET_NOTIFICATION_ENABLE,
+ SC_ACK_CC_CI,
- SC_CMD_MAX,
+ SC_CMD_MAX,
};
struct rts5453_command_entry {
- int command;
- uint8_t command_value;
+ int command;
+ uint8_t command_value;
- // Either 0 (for no read), -1 (variable read) or 1-32 for fixed size reads.
- size_t return_length;
+ // Either 0 (for no read), -1 (variable read) or 1-32 for fixed size
+ // reads.
+ size_t return_length;
};
-#define CMD_ENTRY(cmd, cmd_val, ret_length) \
- { .command = SC_##cmd, .command_value = cmd_val, .return_length = ret_length }
+#define CMD_ENTRY(cmd, cmd_val, ret_length) \
+ { \
+ .command = SC_##cmd, .command_value = cmd_val, \
+ .return_length = ret_length \
+ }
struct rts5453_command_entry commands[] = {
- CMD_ENTRY(VENDOR_CMD, 0x1, 0),
- CMD_ENTRY(GET_IC_STATUS, 0x3A, 32),
- CMD_ENTRY(GET_VDO, 0x08, -1),
+ CMD_ENTRY(VENDOR_CMD, 0x1, 0),
+ CMD_ENTRY(GET_IC_STATUS, 0x3A, 32),
+ CMD_ENTRY(GET_VDO, 0x08, -1),
- CMD_ENTRY(WRITE_FLASH_0K_64K, 0x04, 0),
- CMD_ENTRY(WRITE_FLASH_64K_128K, 0x06, 0),
- CMD_ENTRY(WRITE_FLASH_128K_192K, 0x13, 0),
- CMD_ENTRY(WRITE_FLASH_192K_256K, 0x14, 0),
+ CMD_ENTRY(WRITE_FLASH_0K_64K, 0x04, 0),
+ CMD_ENTRY(WRITE_FLASH_64K_128K, 0x06, 0),
+ CMD_ENTRY(WRITE_FLASH_128K_192K, 0x13, 0),
+ CMD_ENTRY(WRITE_FLASH_192K_256K, 0x14, 0),
- CMD_ENTRY(READ_FLASH_0K_64K, 0x24, -1),
- CMD_ENTRY(READ_FLASH_64K_128K, 0x26, -1),
- CMD_ENTRY(READ_FLASH_128K_192K, 0x33, -1),
- CMD_ENTRY(READ_FLASH_192K_256K, 0x34, -1),
+ CMD_ENTRY(READ_FLASH_0K_64K, 0x24, -1),
+ CMD_ENTRY(READ_FLASH_64K_128K, 0x26, -1),
+ CMD_ENTRY(READ_FLASH_128K_192K, 0x33, -1),
+ CMD_ENTRY(READ_FLASH_192K_256K, 0x34, -1),
- CMD_ENTRY(ERASE_FLASH, 0x03, -1),
- CMD_ENTRY(GET_SPI_PROTECT, 0x36, -1),
- CMD_ENTRY(SET_SPI_PROTECT, 0x07, 0),
- CMD_ENTRY(ISP_VALIDATION, 0x16, 0),
- CMD_ENTRY(RESET_TO_FLASH, 0x05, 0),
+ CMD_ENTRY(ERASE_FLASH, 0x03, -1),
+ CMD_ENTRY(GET_SPI_PROTECT, 0x36, -1),
+ CMD_ENTRY(SET_SPI_PROTECT, 0x07, 0),
+ CMD_ENTRY(ISP_VALIDATION, 0x16, 0),
+ CMD_ENTRY(RESET_TO_FLASH, 0x05, 0),
- CMD_ENTRY(UCSI_COMMANDS, 0x0E, -1),
- CMD_ENTRY(SET_NOTIFICATION_ENABLE, 0x08, 0),
- CMD_ENTRY(ACK_CC_CI, 0x0A, 0),
+ CMD_ENTRY(UCSI_COMMANDS, 0x0E, -1),
+ CMD_ENTRY(SET_NOTIFICATION_ENABLE, 0x08, 0),
+ CMD_ENTRY(ACK_CC_CI, 0x0A, 0),
};
struct rts5453_ucsi_commands {
- uint8_t command;
- uint8_t command_copy_length;
+ uint8_t command;
+ uint8_t command_copy_length;
};
-#define UCSI_CMD_ENTRY(cmd, length) \
- { .command = cmd, .command_copy_length = length, }
+#define UCSI_CMD_ENTRY(cmd, length) \
+ { \
+ .command = cmd, .command_copy_length = length, \
+ }
struct rts5453_ucsi_commands ucsi_commands[UCSI_CMD_VENDOR_CMD + 1] = {
- UCSI_CMD_ENTRY(UCSI_CMD_RESERVED, 0),
- UCSI_CMD_ENTRY(UCSI_CMD_PPM_RESET, 0),
- UCSI_CMD_ENTRY(UCSI_CMD_CANCEL, 0),
- UCSI_CMD_ENTRY(UCSI_CMD_CONNECTOR_RESET, 1),
- UCSI_CMD_ENTRY(UCSI_CMD_ACK_CC_CI, 1),
- UCSI_CMD_ENTRY(UCSI_CMD_SET_NOTIFICATION_ENABLE, 3),
- UCSI_CMD_ENTRY(UCSI_CMD_GET_CAPABILITY, 0),
- UCSI_CMD_ENTRY(UCSI_CMD_GET_CONNECTOR_CAPABILITY, 1),
- UCSI_CMD_ENTRY(UCSI_CMD_SET_CCOM, 2),
- UCSI_CMD_ENTRY(UCSI_CMD_SET_UOR, 2),
- UCSI_CMD_ENTRY(obsolete_UCSI_CMD_SET_PDM, 0),
- UCSI_CMD_ENTRY(UCSI_CMD_SET_PDR, 2),
- UCSI_CMD_ENTRY(UCSI_CMD_GET_ALTERNATE_MODES, 4),
- UCSI_CMD_ENTRY(UCSI_CMD_GET_CAM_SUPPORTED, 1),
- UCSI_CMD_ENTRY(UCSI_CMD_GET_CURRENT_CAM, 1),
- UCSI_CMD_ENTRY(UCSI_CMD_SET_NEW_CAM, 6),
- UCSI_CMD_ENTRY(UCSI_CMD_GET_PDOS, 3),
- UCSI_CMD_ENTRY(UCSI_CMD_GET_CABLE_PROPERTY, 1),
- UCSI_CMD_ENTRY(UCSI_CMD_GET_CONNECTOR_STATUS, 1),
- UCSI_CMD_ENTRY(UCSI_CMD_GET_ERROR_STATUS, 1),
- UCSI_CMD_ENTRY(UCSI_CMD_SET_POWER_LEVEL, 6),
- UCSI_CMD_ENTRY(UCSI_CMD_GET_PD_MESSAGE, 4),
- UCSI_CMD_ENTRY(UCSI_CMD_GET_ATTENTION_VDO, 1),
- UCSI_CMD_ENTRY(UCSI_CMD_reserved_0x17, 0),
- UCSI_CMD_ENTRY(UCSI_CMD_GET_CAM_CS, 2),
- UCSI_CMD_ENTRY(UCSI_CMD_LPM_FW_UPDATE_REQUEST, 4),
- UCSI_CMD_ENTRY(UCSI_CMD_SECURITY_REQUEST, 5),
- UCSI_CMD_ENTRY(UCSI_CMD_SET_RETIMER_MODE, 5),
- UCSI_CMD_ENTRY(UCSI_CMD_SET_SINK_PATH, 1),
- UCSI_CMD_ENTRY(UCSI_CMD_SET_PDOS, 3),
- UCSI_CMD_ENTRY(UCSI_CMD_READ_POWER_LEVEL, 3),
- UCSI_CMD_ENTRY(UCSI_CMD_CHUNKING_SUPPORT, 1),
- UCSI_CMD_ENTRY(UCSI_CMD_VENDOR_CMD, 6),
+ UCSI_CMD_ENTRY(UCSI_CMD_RESERVED, 0),
+ UCSI_CMD_ENTRY(UCSI_CMD_PPM_RESET, 0),
+ UCSI_CMD_ENTRY(UCSI_CMD_CANCEL, 0),
+ UCSI_CMD_ENTRY(UCSI_CMD_CONNECTOR_RESET, 1),
+ UCSI_CMD_ENTRY(UCSI_CMD_ACK_CC_CI, 1),
+ UCSI_CMD_ENTRY(UCSI_CMD_SET_NOTIFICATION_ENABLE, 3),
+ UCSI_CMD_ENTRY(UCSI_CMD_GET_CAPABILITY, 0),
+ UCSI_CMD_ENTRY(UCSI_CMD_GET_CONNECTOR_CAPABILITY, 1),
+ UCSI_CMD_ENTRY(UCSI_CMD_SET_CCOM, 2),
+ UCSI_CMD_ENTRY(UCSI_CMD_SET_UOR, 2),
+ UCSI_CMD_ENTRY(obsolete_UCSI_CMD_SET_PDM, 0),
+ UCSI_CMD_ENTRY(UCSI_CMD_SET_PDR, 2),
+ UCSI_CMD_ENTRY(UCSI_CMD_GET_ALTERNATE_MODES, 4),
+ UCSI_CMD_ENTRY(UCSI_CMD_GET_CAM_SUPPORTED, 1),
+ UCSI_CMD_ENTRY(UCSI_CMD_GET_CURRENT_CAM, 1),
+ UCSI_CMD_ENTRY(UCSI_CMD_SET_NEW_CAM, 6),
+ UCSI_CMD_ENTRY(UCSI_CMD_GET_PDOS, 3),
+ UCSI_CMD_ENTRY(UCSI_CMD_GET_CABLE_PROPERTY, 1),
+ UCSI_CMD_ENTRY(UCSI_CMD_GET_CONNECTOR_STATUS, 1),
+ UCSI_CMD_ENTRY(UCSI_CMD_GET_ERROR_STATUS, 1),
+ UCSI_CMD_ENTRY(UCSI_CMD_SET_POWER_LEVEL, 6),
+ UCSI_CMD_ENTRY(UCSI_CMD_GET_PD_MESSAGE, 4),
+ UCSI_CMD_ENTRY(UCSI_CMD_GET_ATTENTION_VDO, 1),
+ UCSI_CMD_ENTRY(UCSI_CMD_reserved_0x17, 0),
+ UCSI_CMD_ENTRY(UCSI_CMD_GET_CAM_CS, 2),
+ UCSI_CMD_ENTRY(UCSI_CMD_LPM_FW_UPDATE_REQUEST, 4),
+ UCSI_CMD_ENTRY(UCSI_CMD_SECURITY_REQUEST, 5),
+ UCSI_CMD_ENTRY(UCSI_CMD_SET_RETIMER_MODE, 5),
+ UCSI_CMD_ENTRY(UCSI_CMD_SET_SINK_PATH, 1),
+ UCSI_CMD_ENTRY(UCSI_CMD_SET_PDOS, 3),
+ UCSI_CMD_ENTRY(UCSI_CMD_READ_POWER_LEVEL, 3),
+ UCSI_CMD_ENTRY(UCSI_CMD_CHUNKING_SUPPORT, 1),
+ UCSI_CMD_ENTRY(UCSI_CMD_VENDOR_CMD, 6),
};
#define PING_DELAY_US 10000
@@ -156,655 +161,691 @@
#define RTS5453_BANK1_START 0x20000
#define RTS5453_BANK1_END 0x40000
-static uint8_t port_to_chip_address(struct rts5453_device* dev, uint8_t port) {
- if (port >= dev->driver_config->max_num_ports) {
- ELOG("Attempted to access invalid port %d. Max port index = %d", port,
- dev->driver_config->max_num_ports - 1);
- return 0;
- }
+static uint8_t port_to_chip_address(struct rts5453_device *dev, uint8_t port)
+{
+ if (port >= dev->driver_config->max_num_ports) {
+ ELOG("Attempted to access invalid port %d. Max port index = %d",
+ port, dev->driver_config->max_num_ports - 1);
+ return 0;
+ }
- return dev->driver_config->port_address_map[port];
+ return dev->driver_config->port_address_map[port];
}
-static int rts5453_ping_status(struct rts5453_device* dev, uint8_t port) {
- int retry_count;
+static int rts5453_ping_status(struct rts5453_device *dev, uint8_t port)
+{
+ int retry_count;
- for (retry_count = 0; retry_count < RETRY_COUNT; ++retry_count) {
- int byte =
- dev->smbus->read_byte(dev->smbus->dev, port_to_chip_address(dev, port));
+ for (retry_count = 0; retry_count < RETRY_COUNT; ++retry_count) {
+ int byte = dev->smbus->read_byte(
+ dev->smbus->dev, port_to_chip_address(dev, port));
- // Ping status failed
- if (byte == -1) {
- ELOG("Ping status got read_error");
- return -1;
- }
+ // Ping status failed
+ if (byte == -1) {
+ ELOG("Ping status got read_error");
+ return -1;
+ }
- // Busy so wait 10ms.
- if (byte == 0) {
- platform_usleep(PING_DELAY_US);
- continue;
- }
+ // Busy so wait 10ms.
+ if (byte == 0) {
+ platform_usleep(PING_DELAY_US);
+ continue;
+ }
- // Valid ping status
- DLOG("Ping status: 0x%02x", (byte & 0xff));
- return (byte & 0xFF);
- }
+ // Valid ping status
+ DLOG("Ping status: 0x%02x", (byte & 0xff));
+ return (byte & 0xFF);
+ }
- DLOG("Timed out on ping status");
- return -1;
+ DLOG("Timed out on ping status");
+ return -1;
}
-static int rts5453_smbus_command(struct rts5453_device* dev, uint8_t port,
- int cmd, uint8_t* cmd_data, size_t length,
- uint8_t* out, size_t out_length) {
- uint8_t cmd_val;
- int read_size;
- uint8_t chip_address = port_to_chip_address(dev, port);
+static int rts5453_smbus_command(struct rts5453_device *dev, uint8_t port,
+ int cmd, uint8_t *cmd_data, size_t length,
+ uint8_t *out, size_t out_length)
+{
+ uint8_t cmd_val;
+ int read_size;
+ uint8_t chip_address = port_to_chip_address(dev, port);
- if (!dev || !dev->smbus || chip_address == 0) {
- ELOG("Dev (%p), smbus(%p) or port (%u) is invalid", dev,
- dev ? dev->smbus : NULL, port);
- return -1;
- }
+ if (!dev || !dev->smbus || chip_address == 0) {
+ ELOG("Dev (%p), smbus(%p) or port (%u) is invalid", dev,
+ dev ? dev->smbus : NULL, port);
+ return -1;
+ }
- if (cmd < 0 || cmd >= SC_CMD_MAX) {
- ELOG("Invalid command sent: %d", cmd);
- return -1;
- }
+ if (cmd < 0 || cmd >= SC_CMD_MAX) {
+ ELOG("Invalid command sent: %d", cmd);
+ return -1;
+ }
- cmd_val = commands[cmd].command_value;
- read_size = commands[cmd].return_length;
+ cmd_val = commands[cmd].command_value;
+ read_size = commands[cmd].return_length;
- if (cmd_val == SC_UCSI_COMMANDS) {
- DLOG("Sending smbus command 0x%x ucsi command 0x%x", cmd_val, cmd_data[0]);
- } else {
- DLOG("Sending smbus command 0x%x", cmd_val);
- }
+ if (cmd_val == SC_UCSI_COMMANDS) {
+ DLOG("Sending smbus command 0x%x ucsi command 0x%x", cmd_val,
+ cmd_data[0]);
+ } else {
+ DLOG("Sending smbus command 0x%x", cmd_val);
+ }
- // Write failed. No point in waiting on ping_status
- if (dev->smbus->write_block(dev->smbus->dev, chip_address, cmd_val, cmd_data,
- length) == -1) {
- ELOG("Write block for command failed");
- return -1;
- }
+ // Write failed. No point in waiting on ping_status
+ if (dev->smbus->write_block(dev->smbus->dev, chip_address, cmd_val,
+ cmd_data, length) == -1) {
+ ELOG("Write block for command failed");
+ return -1;
+ }
- // Error out if ping status is invalid.
- int ping_status = rts5453_ping_status(dev, port);
- if (ping_status == -1 || (ping_status & 0x3) == 0x3) {
- ELOG("Ping status failed with %d", ping_status);
- return -1;
- }
+ // Error out if ping status is invalid.
+ int ping_status = rts5453_ping_status(dev, port);
+ if (ping_status == -1 || (ping_status & 0x3) == 0x3) {
+ ELOG("Ping status failed with %d", ping_status);
+ return -1;
+ }
- if (read_size != 0) {
- if (!out) {
- ELOG("No output buffer to send data");
- return -1;
- }
+ if (read_size != 0) {
+ if (!out) {
+ ELOG("No output buffer to send data");
+ return -1;
+ }
- read_size = read_size != -1 ? read_size : (ping_status >> 2);
+ read_size = read_size != -1 ? read_size : (ping_status >> 2);
- if (read_size == 0) {
- DLOG("Nothing to read.");
- return 0;
- }
+ if (read_size == 0) {
+ DLOG("Nothing to read.");
+ return 0;
+ }
- if (read_size > out_length) {
- ELOG(
- "Truncated read bytes for command [0x%x]. Wanted %d but input buffer "
- "only had %d",
- cmd_val, read_size, out_length);
- read_size = out_length;
- }
+ if (read_size > out_length) {
+ ELOG("Truncated read bytes for command [0x%x]. Wanted %d but input buffer "
+ "only had %d",
+ cmd_val, read_size, out_length);
+ read_size = out_length;
+ }
- int bytes_read = dev->smbus->read_block(dev->smbus->dev, chip_address, 0x80,
- out, out_length);
- DLOG("Read_block at 0x80 read %d bytes", bytes_read);
- return bytes_read;
- }
+ int bytes_read = dev->smbus->read_block(
+ dev->smbus->dev, chip_address, 0x80, out, out_length);
+ DLOG("Read_block at 0x80 read %d bytes", bytes_read);
+ return bytes_read;
+ }
- DLOG("Skipped read and returning");
- return 0;
+ DLOG("Skipped read and returning");
+ return 0;
}
// Call with dev->cmd_buffer already set.
-static int rts5453_set_notification_per_port(struct rts5453_device* dev,
- uint8_t* lpm_data_out) {
- int ret = 0;
- int cmd = SC_SET_NOTIFICATION_ENABLE;
- uint8_t data_size = 4;
+static int rts5453_set_notification_per_port(struct rts5453_device *dev,
+ uint8_t *lpm_data_out)
+{
+ int ret = 0;
+ int cmd = SC_SET_NOTIFICATION_ENABLE;
+ uint8_t data_size = 4;
- // Print out what bits are being set in notifications
- uint32_t* enable_bits = ((uint32_t*)&dev->cmd_buffer[2]);
- DLOG("SET_NOTIFICATION_ENABLE with bits = 0x%04x", *enable_bits);
+ // Print out what bits are being set in notifications
+ uint32_t *enable_bits = ((uint32_t *)&dev->cmd_buffer[2]);
+ DLOG("SET_NOTIFICATION_ENABLE with bits = 0x%04x", *enable_bits);
- for (uint8_t port = dev->active_port_count; port > 0; --port) {
- dev->cmd_buffer[1] = 0; // fixed port-num = 0
- ret = rts5453_smbus_command(dev, port - 1, cmd, dev->cmd_buffer,
- data_size + 2, lpm_data_out,
- SMBUS_MAX_BLOCK_SIZE);
+ for (uint8_t port = dev->active_port_count; port > 0; --port) {
+ dev->cmd_buffer[1] = 0; // fixed port-num = 0
+ ret = rts5453_smbus_command(dev, port - 1, cmd, dev->cmd_buffer,
+ data_size + 2, lpm_data_out,
+ SMBUS_MAX_BLOCK_SIZE);
- if (ret < 0) {
- ELOG("Failed to set notification on port %d", port);
- return ret;
- }
- }
+ if (ret < 0) {
+ ELOG("Failed to set notification on port %d", port);
+ return ret;
+ }
+ }
- return ret;
+ return ret;
}
-static int rts5453_ucsi_execute_cmd(struct ucsi_pd_device* device,
- struct ucsi_control* control,
- uint8_t* lpm_data_out) {
- struct rts5453_device* dev = CAST_FROM(device);
- uint8_t ucsi_command = control->command;
- int cmd;
- // Data size skips command, write size, sub-cmd and port-num.
- // When writing via rts5453_smbus_command, we always add 2 to data_size (for
- // sub-cmd and port-num).
- uint8_t data_size = 0;
- uint8_t port_num = RTS_DEFAULT_PORT;
+static int rts5453_ucsi_execute_cmd(struct ucsi_pd_device *device,
+ struct ucsi_control *control,
+ uint8_t *lpm_data_out)
+{
+ struct rts5453_device *dev = CAST_FROM(device);
+ uint8_t ucsi_command = control->command;
+ int cmd;
+ // Data size skips command, write size, sub-cmd and port-num.
+ // When writing via rts5453_smbus_command, we always add 2 to data_size
+ // (for sub-cmd and port-num).
+ uint8_t data_size = 0;
+ uint8_t port_num = RTS_DEFAULT_PORT;
- if (control->command == 0 || control->command > UCSI_CMD_VENDOR_CMD) {
- ELOG("Invalid command 0x%x", control->command);
- return -1;
- }
+ if (control->command == 0 || control->command > UCSI_CMD_VENDOR_CMD) {
+ ELOG("Invalid command 0x%x", control->command);
+ return -1;
+ }
- switch (ucsi_command) {
- case UCSI_CMD_ACK_CC_CI:
- struct ucsiv3_ack_cc_ci_cmd* ack_cmd =
- (struct ucsiv3_ack_cc_ci_cmd*)control->command_specific;
- struct ucsiv3_get_connector_status_data* next_connector_status = NULL;
+ switch (ucsi_command) {
+ case UCSI_CMD_ACK_CC_CI:
+ struct ucsiv3_ack_cc_ci_cmd *ack_cmd =
+ (struct ucsiv3_ack_cc_ci_cmd *)control->command_specific;
+ struct ucsiv3_get_connector_status_data *next_connector_status =
+ NULL;
- uint8_t local_port_num = RTS_DEFAULT_PORT;
- bool has_pending_ci = dev->ppm->get_next_connector_status(
- dev->ppm->dev, &local_port_num, &next_connector_status);
- cmd = SC_ACK_CC_CI;
- data_size = 5;
- platform_memset(dev->cmd_buffer, 0, data_size + 2);
+ uint8_t local_port_num = RTS_DEFAULT_PORT;
+ bool has_pending_ci = dev->ppm->get_next_connector_status(
+ dev->ppm->dev, &local_port_num, &next_connector_status);
+ cmd = SC_ACK_CC_CI;
+ data_size = 5;
+ platform_memset(dev->cmd_buffer, 0, data_size + 2);
- // Already memset but for reference:
- // dev->cmd_buffer[0] = 0; // Reserved and 0.
- // dev->cmd_buffer[1] = 0x0; // port fixed to 0.
+ // Already memset but for reference:
+ // dev->cmd_buffer[0] = 0; // Reserved and 0.
+ // dev->cmd_buffer[1] = 0x0; // port fixed to 0.
- // Acking on a command or async event?
- if (ack_cmd->command_complete_ack) {
- dev->cmd_buffer[6] = 0x1; // Command completed acknowledge
- }
- // TODO - Do we clear all events on this ack or do we expect OPM to need
- // a separate notification PER event. I think the answer is single ack --
- // double check and clear this comment.
- else if (ack_cmd->connector_change_ack && has_pending_ci) {
- // Copy UCSI status change bits and leave RTK bits alone (4, 5)
- uint16_t mask = next_connector_status->connector_status_change;
- dev->cmd_buffer[1] = 0; // port_num affects chip addressing
- dev->cmd_buffer[2] = mask & 0xff;
- dev->cmd_buffer[3] = (mask >> 8) & 0xff;
- // Always clear the RTK bits (we don't use it in UCSI)
- dev->cmd_buffer[4] = 0xff;
- dev->cmd_buffer[5] = 0xff;
- port_num = local_port_num - 1;
+ // Acking on a command or async event?
+ if (ack_cmd->command_complete_ack) {
+ dev->cmd_buffer[6] = 0x1; // Command completed
+ // acknowledge
+ }
+ // TODO - Do we clear all events on this ack or do we expect OPM
+ // to need a separate notification PER event. I think the answer
+ // is single ack -- double check and clear this comment.
+ else if (ack_cmd->connector_change_ack && has_pending_ci) {
+ // Copy UCSI status change bits and leave RTK bits alone
+ // (4, 5)
+ uint16_t mask =
+ next_connector_status->connector_status_change;
+ dev->cmd_buffer[1] = 0; // port_num affects chip
+ // addressing
+ dev->cmd_buffer[2] = mask & 0xff;
+ dev->cmd_buffer[3] = (mask >> 8) & 0xff;
+ // Always clear the RTK bits (we don't use it in UCSI)
+ dev->cmd_buffer[4] = 0xff;
+ dev->cmd_buffer[5] = 0xff;
+ port_num = local_port_num - 1;
- DLOG(
- "ACK_CC_CI with mask (UCSI 0x%x), RTK [%02x, %02x, %02x, %02x] "
- "on port %d",
- mask, dev->cmd_buffer[2], dev->cmd_buffer[3], dev->cmd_buffer[4],
- dev->cmd_buffer[5], port_num);
- } else {
- ELOG(
- "Ack invalid. Ack byte (0x%x), Has pending Connector "
- "Indication(%b)",
- control->command_specific[0], has_pending_ci);
- return -1;
- }
+ DLOG("ACK_CC_CI with mask (UCSI 0x%x), RTK [%02x, %02x, %02x, %02x] "
+ "on port %d",
+ mask, dev->cmd_buffer[2], dev->cmd_buffer[3],
+ dev->cmd_buffer[4], dev->cmd_buffer[5], port_num);
+ } else {
+ ELOG("Ack invalid. Ack byte (0x%x), Has pending Connector "
+ "Indication(%b)",
+ control->command_specific[0], has_pending_ci);
+ return -1;
+ }
- break;
- case UCSI_CMD_SET_NOTIFICATION_ENABLE:
- cmd = SC_SET_NOTIFICATION_ENABLE;
- data_size = 4;
- platform_memset(dev->cmd_buffer, 0, data_size + 2);
- dev->cmd_buffer[0] = 0x1; // sub-cmd
- dev->cmd_buffer[1] = 0x0; // fixed port-num = 0
+ break;
+ case UCSI_CMD_SET_NOTIFICATION_ENABLE:
+ cmd = SC_SET_NOTIFICATION_ENABLE;
+ data_size = 4;
+ platform_memset(dev->cmd_buffer, 0, data_size + 2);
+ dev->cmd_buffer[0] = 0x1; // sub-cmd
+ dev->cmd_buffer[1] = 0x0; // fixed port-num = 0
- platform_memcpy(&dev->cmd_buffer[2], control->command_specific,
- data_size);
- break;
- case UCSI_CMD_GET_CONNECTOR_STATUS:
- cmd = SC_UCSI_COMMANDS;
- data_size = 0;
- platform_memset(dev->cmd_buffer, 0, 2);
- dev->cmd_buffer[0] = ucsi_command;
- dev->cmd_buffer[1] = 0; // control->command_specific[0]; // Port number
- port_num = control->command_specific[0] - 1;
+ platform_memcpy(&dev->cmd_buffer[2], control->command_specific,
+ data_size);
+ break;
+ case UCSI_CMD_GET_CONNECTOR_STATUS:
+ cmd = SC_UCSI_COMMANDS;
+ data_size = 0;
+ platform_memset(dev->cmd_buffer, 0, 2);
+ dev->cmd_buffer[0] = ucsi_command;
+ dev->cmd_buffer[1] = 0; // control->command_specific[0]; //
+ // Port number
+ port_num = control->command_specific[0] - 1;
- break;
- case UCSI_CMD_GET_PD_MESSAGE:
- // TODO: Update once the Realtek interface supports full identity.
- // This definition is a placeholder and will only respond to a discover
- // identity request with 6 VDOs to mimic the maximum identity response
- // length. The returned data is not partner/cable identity.
- struct ucsiv3_get_pd_message_cmd* get_pd_message_cmd =
- (struct ucsiv3_get_pd_message_cmd*)control->command_specific;
+ break;
+ case UCSI_CMD_GET_PD_MESSAGE:
+ // TODO: Update once the Realtek interface supports full
+ // identity. This definition is a placeholder and will only
+ // respond to a discover identity request with 6 VDOs to mimic
+ // the maximum identity response length. The returned data is
+ // not partner/cable identity.
+ struct ucsiv3_get_pd_message_cmd *get_pd_message_cmd =
+ (struct ucsiv3_get_pd_message_cmd *)
+ control->command_specific;
- if (get_pd_message_cmd->response_message_type != 4) {
- ELOG("Unsupported Response Message type in GET_PD_MESSAGE: %d",
- get_pd_message_cmd->response_message_type);
- return -1;
- }
+ if (get_pd_message_cmd->response_message_type != 4) {
+ ELOG("Unsupported Response Message type in GET_PD_MESSAGE: %d",
+ get_pd_message_cmd->response_message_type);
+ return -1;
+ }
- cmd = SC_GET_VDO;
- data_size = 7; // Number of VDOs + 1 (+2 added later)
- platform_memset(dev->cmd_buffer, 0, data_size + 2);
- dev->cmd_buffer[0] = 0x9A; // GET_VDO sub command
- dev->cmd_buffer[1] = 0x00; // Port Num
- dev->cmd_buffer[2] = 0x0E; // Origin: Port Partner (0x8) | Num Vdos (0x6)
- dev->cmd_buffer[3] = 0x01; // Id Header VDO
- dev->cmd_buffer[4] = 0x02; // Cert Stat VDO
- dev->cmd_buffer[5] = 0x03; // Product VDO
- dev->cmd_buffer[6] = 0x04; // Cable VDO
- dev->cmd_buffer[7] = 0x05; // AMA VDO
- dev->cmd_buffer[8] = 0x06; // SVID Response VDO1
- break;
- default:
- // For most UCSI commands, just set the cmd = 0x0E and copy the additional
- // data from the command to smbus output.
- cmd = SC_UCSI_COMMANDS;
- data_size = ucsi_commands[ucsi_command].command_copy_length;
- platform_memset(dev->cmd_buffer, 0, data_size + 2);
- dev->cmd_buffer[0] = ucsi_command;
- dev->cmd_buffer[1] = data_size;
+ cmd = SC_GET_VDO;
+ data_size = 7; // Number of VDOs + 1 (+2 added later)
+ platform_memset(dev->cmd_buffer, 0, data_size + 2);
+ dev->cmd_buffer[0] = 0x9A; // GET_VDO sub command
+ dev->cmd_buffer[1] = 0x00; // Port Num
+ dev->cmd_buffer[2] = 0x0E; // Origin: Port Partner (0x8) | Num
+ // Vdos (0x6)
+ dev->cmd_buffer[3] = 0x01; // Id Header VDO
+ dev->cmd_buffer[4] = 0x02; // Cert Stat VDO
+ dev->cmd_buffer[5] = 0x03; // Product VDO
+ dev->cmd_buffer[6] = 0x04; // Cable VDO
+ dev->cmd_buffer[7] = 0x05; // AMA VDO
+ dev->cmd_buffer[8] = 0x06; // SVID Response VDO1
+ break;
+ default:
+ // For most UCSI commands, just set the cmd = 0x0E and copy the
+ // additional data from the command to smbus output.
+ cmd = SC_UCSI_COMMANDS;
+ data_size = ucsi_commands[ucsi_command].command_copy_length;
+ platform_memset(dev->cmd_buffer, 0, data_size + 2);
+ dev->cmd_buffer[0] = ucsi_command;
+ dev->cmd_buffer[1] = data_size;
- // Seems like developer error here. We only support up to 6 bytes.
- if (data_size > 6) {
- ELOG(
- "UCSI commands using MESSAGE_OUT are unsupported."
- "Given data_size was %d",
- data_size);
- return -1;
- }
- // Copy any command data
- else if (data_size > 0) {
- platform_memcpy(&dev->cmd_buffer[2], control->command_specific,
- data_size);
- }
+ // Seems like developer error here. We only support up to 6
+ // bytes.
+ if (data_size > 6) {
+ ELOG("UCSI commands using MESSAGE_OUT are unsupported."
+ "Given data_size was %d",
+ data_size);
+ return -1;
+ }
+ // Copy any command data
+ else if (data_size > 0) {
+ platform_memcpy(&dev->cmd_buffer[2],
+ control->command_specific, data_size);
+ }
- break;
- }
+ break;
+ }
- // Note special behavior for SET_NOTIFICATION_ENABLE.
- if (ucsi_command == UCSI_CMD_SET_NOTIFICATION_ENABLE) {
- return rts5453_set_notification_per_port(dev, lpm_data_out);
- }
+ // Note special behavior for SET_NOTIFICATION_ENABLE.
+ if (ucsi_command == UCSI_CMD_SET_NOTIFICATION_ENABLE) {
+ return rts5453_set_notification_per_port(dev, lpm_data_out);
+ }
- return rts5453_smbus_command(dev, port_num, cmd, dev->cmd_buffer,
- data_size + 2, lpm_data_out,
- SMBUS_MAX_BLOCK_SIZE);
+ return rts5453_smbus_command(dev, port_num, cmd, dev->cmd_buffer,
+ data_size + 2, lpm_data_out,
+ SMBUS_MAX_BLOCK_SIZE);
}
-int rts5453_vendor_cmd_internal(struct rts5453_device* dev, uint8_t port,
- uint8_t enable_bits) {
- uint8_t cmd[] = {/*0x3,*/ 0xda, 0x0b, enable_bits};
- return rts5453_smbus_command(dev, port, SC_VENDOR_CMD, cmd, ARRAY_SIZE(cmd),
- NULL, 0);
+int rts5453_vendor_cmd_internal(struct rts5453_device *dev, uint8_t port,
+ uint8_t enable_bits)
+{
+ uint8_t cmd[] = { /*0x3,*/ 0xda, 0x0b, enable_bits };
+ return rts5453_smbus_command(dev, port, SC_VENDOR_CMD, cmd,
+ ARRAY_SIZE(cmd), NULL, 0);
}
-int rts5453_vendor_cmd_disable(struct rts5453_device* dev, uint8_t port) {
- return rts5453_vendor_cmd_internal(dev, port, 0);
+int rts5453_vendor_cmd_disable(struct rts5453_device *dev, uint8_t port)
+{
+ return rts5453_vendor_cmd_internal(dev, port, 0);
}
-int rts5453_vendor_cmd_enable_smbus(struct rts5453_device* dev, uint8_t port) {
- return rts5453_vendor_cmd_internal(dev, port, 0x1);
+int rts5453_vendor_cmd_enable_smbus(struct rts5453_device *dev, uint8_t port)
+{
+ return rts5453_vendor_cmd_internal(dev, port, 0x1);
}
-int rts5453_vendor_cmd_enable_smbus_flash_access(struct rts5453_device* dev,
- uint8_t port) {
- return rts5453_vendor_cmd_internal(dev, port, 0x3);
+int rts5453_vendor_cmd_enable_smbus_flash_access(struct rts5453_device *dev,
+ uint8_t port)
+{
+ return rts5453_vendor_cmd_internal(dev, port, 0x3);
}
-int rts5453_set_flash_protection(struct rts5453_device* dev,
- int flash_protect) {
- uint8_t cmd[] = {/*0x1,*/ flash_protect ? 0x1 : 0x0};
- return rts5453_smbus_command(dev, RTS_DEFAULT_PORT, SC_SET_SPI_PROTECT, cmd,
- ARRAY_SIZE(cmd), NULL, 0);
+int rts5453_set_flash_protection(struct rts5453_device *dev, int flash_protect)
+{
+ uint8_t cmd[] = { /*0x1,*/ flash_protect ? 0x1 : 0x0 };
+ return rts5453_smbus_command(dev, RTS_DEFAULT_PORT, SC_SET_SPI_PROTECT,
+ cmd, ARRAY_SIZE(cmd), NULL, 0);
}
-int rts5453_isp_validation(struct rts5453_device* dev) {
- uint8_t cmd[] = {/*0x1,*/ 0x1};
- return rts5453_smbus_command(dev, RTS_DEFAULT_PORT, SC_ISP_VALIDATION, cmd,
- ARRAY_SIZE(cmd), NULL, 0);
+int rts5453_isp_validation(struct rts5453_device *dev)
+{
+ uint8_t cmd[] = { /*0x1,*/ 0x1 };
+ return rts5453_smbus_command(dev, RTS_DEFAULT_PORT, SC_ISP_VALIDATION,
+ cmd, ARRAY_SIZE(cmd), NULL, 0);
}
-int rts5453_reset_to_flash(struct rts5453_device* dev) {
- uint8_t cmd[] = {/*0x3,*/ 0xDA, 0x0B, 0x01};
- return rts5453_smbus_command(dev, RTS_DEFAULT_PORT, SC_RESET_TO_FLASH, cmd,
- ARRAY_SIZE(cmd), NULL, 0);
+int rts5453_reset_to_flash(struct rts5453_device *dev)
+{
+ uint8_t cmd[] = { /*0x3,*/ 0xDA, 0x0B, 0x01 };
+ return rts5453_smbus_command(dev, RTS_DEFAULT_PORT, SC_RESET_TO_FLASH,
+ cmd, ARRAY_SIZE(cmd), NULL, 0);
}
-int rts5453_write_to_flash(struct rts5453_device* dev, int flash_bank,
- const char* inbuf, uint8_t size, size_t offset) {
- int flash_cmd = SC_WRITE_FLASH_0K_64K;
- uint8_t cmd[SMBUS_MAX_BLOCK_SIZE];
- uint16_t addr_h = 0;
- uint16_t addr_l = 0;
+int rts5453_write_to_flash(struct rts5453_device *dev, int flash_bank,
+ const char *inbuf, uint8_t size, size_t offset)
+{
+ int flash_cmd = SC_WRITE_FLASH_0K_64K;
+ uint8_t cmd[SMBUS_MAX_BLOCK_SIZE];
+ uint16_t addr_h = 0;
+ uint16_t addr_l = 0;
- // Bounds check
- int start = RTS5453_BANK0_START + offset;
- int end = RTS5453_BANK0_END;
- if (flash_bank != 0) {
- start = RTS5453_BANK1_START + offset;
- end = RTS5453_BANK1_END;
- }
+ // Bounds check
+ int start = RTS5453_BANK0_START + offset;
+ int end = RTS5453_BANK0_END;
+ if (flash_bank != 0) {
+ start = RTS5453_BANK1_START + offset;
+ end = RTS5453_BANK1_END;
+ }
- // Get addr_h and addr_l
- addr_h = (uint16_t)((start >> 16) & 0xFFFF);
- addr_l = (uint16_t)(start & 0xFFFF);
+ // Get addr_h and addr_l
+ addr_h = (uint16_t)((start >> 16) & 0xFFFF);
+ addr_l = (uint16_t)(start & 0xFFFF);
- // Limited by smbus block size
- if (size > FW_BLOCK_CHUNK_SIZE) {
- ELOG("Can't write with size=%d > max smbus size=%d", size,
- FW_BLOCK_CHUNK_SIZE);
- return -1;
- }
+ // Limited by smbus block size
+ if (size > FW_BLOCK_CHUNK_SIZE) {
+ ELOG("Can't write with size=%d > max smbus size=%d", size,
+ FW_BLOCK_CHUNK_SIZE);
+ return -1;
+ }
- // We can't write more than flash exists
- if (start + size > end) {
- ELOG(
- "Write to flash exceeds bounds of flash: bank %d, start(0x%x), "
- "size(0x%x), end(0x%x)",
- flash_bank, start, size, end);
- return -1;
- }
+ // We can't write more than flash exists
+ if (start + size > end) {
+ ELOG("Write to flash exceeds bounds of flash: bank %d, start(0x%x), "
+ "size(0x%x), end(0x%x)",
+ flash_bank, start, size, end);
+ return -1;
+ }
- // Determine which smbus write command to use.
- switch (addr_h) {
- case 3:
- flash_cmd = SC_WRITE_FLASH_192K_256K;
- break;
- case 2:
- flash_cmd = SC_WRITE_FLASH_128K_192K;
- break;
- case 1:
- flash_cmd = SC_WRITE_FLASH_64K_128K;
- break;
- case 0:
- flash_cmd = SC_WRITE_FLASH_0K_64K;
- break;
- case 4:
- default:
- ELOG("Addr_h %d is out of bounds", addr_h);
- return -1;
- }
+ // Determine which smbus write command to use.
+ switch (addr_h) {
+ case 3:
+ flash_cmd = SC_WRITE_FLASH_192K_256K;
+ break;
+ case 2:
+ flash_cmd = SC_WRITE_FLASH_128K_192K;
+ break;
+ case 1:
+ flash_cmd = SC_WRITE_FLASH_64K_128K;
+ break;
+ case 0:
+ flash_cmd = SC_WRITE_FLASH_0K_64K;
+ break;
+ case 4:
+ default:
+ ELOG("Addr_h %d is out of bounds", addr_h);
+ return -1;
+ }
- // Build the command.
- // cmd[0] = ADDR_L
- // cmd[1] = ADDR_H
- // cmd[2] = write size
+ // Build the command.
+ // cmd[0] = ADDR_L
+ // cmd[1] = ADDR_H
+ // cmd[2] = write size
- cmd[0] = (uint8_t)(addr_l & 0xFF);
- cmd[1] = (uint8_t)((addr_l >> 8) & 0xFF);
- cmd[2] = size;
- platform_memcpy(&cmd[3], inbuf, size);
+ cmd[0] = (uint8_t)(addr_l & 0xFF);
+ cmd[1] = (uint8_t)((addr_l >> 8) & 0xFF);
+ cmd[2] = size;
+ platform_memcpy(&cmd[3], inbuf, size);
- size = size + 3;
+ size = size + 3;
- return rts5453_smbus_command(dev, RTS_DEFAULT_PORT, flash_cmd, cmd, size,
- NULL, 0);
+ return rts5453_smbus_command(dev, RTS_DEFAULT_PORT, flash_cmd, cmd,
+ size, NULL, 0);
}
-int rts5453_get_ic_status(struct rts5453_device* dev,
- struct rts5453_ic_status* status) {
- uint8_t cmd[] = {/*0x3,*/ 0x0, 0x0, 0x1F};
- uint8_t out[SMBUS_MAX_BLOCK_SIZE];
- platform_memset(out, 0, SMBUS_MAX_BLOCK_SIZE);
+int rts5453_get_ic_status(struct rts5453_device *dev,
+ struct rts5453_ic_status *status)
+{
+ uint8_t cmd[] = { /*0x3,*/ 0x0, 0x0, 0x1F };
+ uint8_t out[SMBUS_MAX_BLOCK_SIZE];
+ platform_memset(out, 0, SMBUS_MAX_BLOCK_SIZE);
- if (!status) {
- return -1;
- }
+ if (!status) {
+ return -1;
+ }
- int ret = rts5453_smbus_command(dev, RTS_DEFAULT_PORT, SC_GET_IC_STATUS, cmd,
- ARRAY_SIZE(cmd), out, SMBUS_MAX_BLOCK_SIZE);
+ int ret = rts5453_smbus_command(dev, RTS_DEFAULT_PORT, SC_GET_IC_STATUS,
+ cmd, ARRAY_SIZE(cmd), out,
+ SMBUS_MAX_BLOCK_SIZE);
- DLOG("Smbus command returned: %d", ret);
- DLOG_START("Raw value: [");
- for (int i = 0; i < SMBUS_MAX_BLOCK_SIZE; ++i) {
- DLOG_LOOP("0x%02x, ", out[i]);
- }
- DLOG_END("]");
+ DLOG("Smbus command returned: %d", ret);
+ DLOG_START("Raw value: [");
+ for (int i = 0; i < SMBUS_MAX_BLOCK_SIZE; ++i) {
+ DLOG_LOOP("0x%02x, ", out[i]);
+ }
+ DLOG_END("]");
- if (ret == 31) {
- platform_memcpy((void*)status, out, 31);
- }
+ if (ret == 31) {
+ platform_memcpy((void *)status, out, 31);
+ }
- return ret;
+ return ret;
}
-static int rts5453_ppm_reset(struct rts5453_device* dev, uint8_t port) {
- uint8_t cmd[] = {/* 0x0e , */ 0x01, 0x00};
- uint8_t unused_out[SMBUS_MAX_BLOCK_SIZE];
+static int rts5453_ppm_reset(struct rts5453_device *dev, uint8_t port)
+{
+ uint8_t cmd[] = { /* 0x0e , */ 0x01, 0x00 };
+ uint8_t unused_out[SMBUS_MAX_BLOCK_SIZE];
- return rts5453_smbus_command(dev, port, SC_UCSI_COMMANDS, cmd,
- ARRAY_SIZE(cmd), unused_out,
- SMBUS_MAX_BLOCK_SIZE);
+ return rts5453_smbus_command(dev, port, SC_UCSI_COMMANDS, cmd,
+ ARRAY_SIZE(cmd), unused_out,
+ SMBUS_MAX_BLOCK_SIZE);
}
-static int rts5453_set_notification_enable(struct rts5453_device* dev,
- uint8_t port, uint32_t mask) {
- uint8_t cmd[] = {/* 0x06 , */
- 0x01,
- 0x00,
- mask & 0xFF,
- (mask >> 8) && 0xFF,
- (mask >> 16) & 0xFF,
- (mask >> 24) & 0xff};
+static int rts5453_set_notification_enable(struct rts5453_device *dev,
+ uint8_t port, uint32_t mask)
+{
+ uint8_t cmd[] = { /* 0x06 , */
+ 0x01,
+ 0x00,
+ mask & 0xFF,
+ (mask >> 8) && 0xFF,
+ (mask >> 16) & 0xFF,
+ (mask >> 24) & 0xff
+ };
- return rts5453_smbus_command(dev, port, SC_SET_NOTIFICATION_ENABLE, cmd,
- ARRAY_SIZE(cmd), NULL, 0);
+ return rts5453_smbus_command(dev, port, SC_SET_NOTIFICATION_ENABLE, cmd,
+ ARRAY_SIZE(cmd), NULL, 0);
}
-static int rts5453_get_capabilities(struct rts5453_device* dev, uint8_t* out,
- size_t size) {
- uint8_t cmd[] = {/* 0x02, */ 0x06, 0x00};
+static int rts5453_get_capabilities(struct rts5453_device *dev, uint8_t *out,
+ size_t size)
+{
+ uint8_t cmd[] = { /* 0x02, */ 0x06, 0x00 };
- return rts5453_smbus_command(dev, RTS_DEFAULT_PORT, SC_UCSI_COMMANDS, cmd,
- ARRAY_SIZE(cmd), out, size);
+ return rts5453_smbus_command(dev, RTS_DEFAULT_PORT, SC_UCSI_COMMANDS,
+ cmd, ARRAY_SIZE(cmd), out, size);
}
-static void rts5453_ucsi_cleanup(struct ucsi_pd_driver* driver) {
- if (driver->dev) {
- struct rts5453_device* dev = CAST_FROM(driver->dev);
+static void rts5453_ucsi_cleanup(struct ucsi_pd_driver *driver)
+{
+ if (driver->dev) {
+ struct rts5453_device *dev = CAST_FROM(driver->dev);
- // Clean up PPM first AND then smbus.
- if (dev->ppm) {
- dev->ppm->cleanup(dev->ppm);
- platform_free(dev->ppm);
- }
+ // Clean up PPM first AND then smbus.
+ if (dev->ppm) {
+ dev->ppm->cleanup(dev->ppm);
+ platform_free(dev->ppm);
+ }
- if (dev->smbus) {
- dev->smbus->cleanup(dev->smbus);
+ if (dev->smbus) {
+ dev->smbus->cleanup(dev->smbus);
- // If there was an interrupt task, it will end when SMBUS is cleaned up.
- if (dev->lpm_interrupt_task) {
- platform_task_complete(dev->lpm_interrupt_task);
- }
+ // If there was an interrupt task, it will end when
+ // SMBUS is cleaned up.
+ if (dev->lpm_interrupt_task) {
+ platform_task_complete(dev->lpm_interrupt_task);
+ }
- platform_free(dev->smbus);
- }
+ platform_free(dev->smbus);
+ }
- platform_free(driver->dev);
- driver->dev = NULL;
- }
+ platform_free(driver->dev);
+ driver->dev = NULL;
+ }
}
#define ALERT_RECEIVING_ADDRESS 0xC
// Query ARA (alert receiving address) and forward as lpm_id to PPM. If we
// received an alert on an unexpected address, raise an error.
-static int rts5453_ucsi_handle_interrupt(struct rts5453_device* dev) {
- const struct pd_driver_config* config = dev->driver_config;
- uint8_t port_id = 0;
- uint8_t ara_address;
+static int rts5453_ucsi_handle_interrupt(struct rts5453_device *dev)
+{
+ const struct pd_driver_config *config = dev->driver_config;
+ uint8_t port_id = 0;
+ uint8_t ara_address;
- int ret = dev->smbus->read_ara(dev->smbus->dev, ALERT_RECEIVING_ADDRESS);
- if (ret < 0) {
- return -1;
- }
+ int ret =
+ dev->smbus->read_ara(dev->smbus->dev, ALERT_RECEIVING_ADDRESS);
+ if (ret < 0) {
+ return -1;
+ }
- ara_address = ret & 0xff;
- for (int i = 0; i < config->max_num_ports; ++i) {
- if (ara_address == config->port_address_map[i]) {
- port_id = i + 1;
- break;
- }
- }
+ ara_address = ret & 0xff;
+ for (int i = 0; i < config->max_num_ports; ++i) {
+ if (ara_address == config->port_address_map[i]) {
+ port_id = i + 1;
+ break;
+ }
+ }
- // If we got a valid port (one we expected), send LPM alert to PPM.
- if (port_id > 0) {
- dev->ppm->lpm_alert(dev->ppm->dev, port_id);
- } else {
- ELOG("Alerted by unexpected chip: 0x%x", ara_address);
- }
+ // If we got a valid port (one we expected), send LPM alert to PPM.
+ if (port_id > 0) {
+ dev->ppm->lpm_alert(dev->ppm->dev, port_id);
+ } else {
+ ELOG("Alerted by unexpected chip: 0x%x", ara_address);
+ }
- return port_id > 0 ? 0 : -1;
+ return port_id > 0 ? 0 : -1;
}
-static void rts5453_lpm_irq_task(void* context) {
- struct rts5453_device* dev = CAST_FROM(context);
- struct smbus_driver* smbus = dev->smbus;
+static void rts5453_lpm_irq_task(void *context)
+{
+ struct rts5453_device *dev = CAST_FROM(context);
+ struct smbus_driver *smbus = dev->smbus;
- DLOG("LPM IRQ task started");
- while (smbus->block_for_interrupt(smbus->dev) != -1) {
- rts5453_ucsi_handle_interrupt(dev);
- }
+ DLOG("LPM IRQ task started");
+ while (smbus->block_for_interrupt(smbus->dev) != -1) {
+ rts5453_ucsi_handle_interrupt(dev);
+ }
- ELOG("LPM IRQ task ended. This is fatal.");
+ ELOG("LPM IRQ task ended. This is fatal.");
}
-static int rts5453_ucsi_configure_lpm_irq(struct ucsi_pd_device* device) {
- struct rts5453_device* dev = CAST_FROM(device);
+static int rts5453_ucsi_configure_lpm_irq(struct ucsi_pd_device *device)
+{
+ struct rts5453_device *dev = CAST_FROM(device);
- if (dev->lpm_interrupt_task != NULL) {
- return 0;
- }
+ if (dev->lpm_interrupt_task != NULL) {
+ return 0;
+ }
- dev->lpm_interrupt_task = platform_task_init(rts5453_lpm_irq_task, dev);
- if (dev->lpm_interrupt_task == NULL) {
- return -1;
- }
+ dev->lpm_interrupt_task = platform_task_init(rts5453_lpm_irq_task, dev);
+ if (dev->lpm_interrupt_task == NULL) {
+ return -1;
+ }
- return 0;
+ return 0;
}
-static int rts5453_ucsi_init_ppm(struct ucsi_pd_device* device) {
- struct rts5453_device* dev = CAST_FROM(device);
- uint8_t caps[16];
- int bytes_read;
- uint8_t num_ports = 0;
- uint8_t max_num_ports = dev->driver_config->max_num_ports;
+static int rts5453_ucsi_init_ppm(struct ucsi_pd_device *device)
+{
+ struct rts5453_device *dev = CAST_FROM(device);
+ uint8_t caps[16];
+ int bytes_read;
+ uint8_t num_ports = 0;
+ uint8_t max_num_ports = dev->driver_config->max_num_ports;
- // Init flow for RTS5453:
- // - First run VENDOR_CMD_ENABLE
- // - SET NOTIFICATION to very basic set to set to IDLE mode.
- // - PPM reset.
- // - Get capability to get number of ports (necessary for handling
- // notifications and correct setting CCI). This may not match max num ports
- // if firmware doesn't enable all ports that driver config has.
+ // Init flow for RTS5453:
+ // - First run VENDOR_CMD_ENABLE
+ // - SET NOTIFICATION to very basic set to set to IDLE mode.
+ // - PPM reset.
+ // - Get capability to get number of ports (necessary for handling
+ // notifications and correct setting CCI). This may not match max num
+ // ports if firmware doesn't enable all ports that driver config has.
- for (uint8_t port = 0; port < max_num_ports; ++port) {
- if (rts5453_vendor_cmd_enable_smbus(dev, port) == -1) {
- ELOG("Failed in PPM_INIT: enable vendor commands");
- return -1;
- }
+ for (uint8_t port = 0; port < max_num_ports; ++port) {
+ if (rts5453_vendor_cmd_enable_smbus(dev, port) == -1) {
+ ELOG("Failed in PPM_INIT: enable vendor commands");
+ return -1;
+ }
- if (rts5453_ppm_reset(dev, port) == -1) {
- ELOG("Failed in PPM_INIT: ppm reset");
- return -1;
- }
+ if (rts5453_ppm_reset(dev, port) == -1) {
+ ELOG("Failed in PPM_INIT: ppm reset");
+ return -1;
+ }
- if (rts5453_set_notification_enable(dev, port, 0x0) == -1) {
- ELOG("Failed in PPM_INIT: clear notifications enabled");
- return -1;
- }
- }
+ if (rts5453_set_notification_enable(dev, port, 0x0) == -1) {
+ ELOG("Failed in PPM_INIT: clear notifications enabled");
+ return -1;
+ }
+ }
- bytes_read = rts5453_get_capabilities(dev, caps, 16);
- if (bytes_read == -1 || bytes_read < 16) {
- ELOG("Failed in PPM_INIT: get_capabilities returned %d", bytes_read);
- DLOG_START("Capabilities bytes: [");
- for (int i = 0; i < bytes_read; ++i) {
- DLOG_LOOP("0x%x, ", caps[i]);
- }
- DLOG_END("]");
- return -1;
- }
+ bytes_read = rts5453_get_capabilities(dev, caps, 16);
+ if (bytes_read == -1 || bytes_read < 16) {
+ ELOG("Failed in PPM_INIT: get_capabilities returned %d",
+ bytes_read);
+ DLOG_START("Capabilities bytes: [");
+ for (int i = 0; i < bytes_read; ++i) {
+ DLOG_LOOP("0x%x, ", caps[i]);
+ }
+ DLOG_END("]");
+ return -1;
+ }
- num_ports = caps[4];
+ num_ports = caps[4];
- // Limit the number of ports to maximum configured number of ports.
- if (num_ports > max_num_ports) {
- ELOG("Truncated number of ports from %d to %d", num_ports, max_num_ports);
- num_ports = max_num_ports;
- }
+ // Limit the number of ports to maximum configured number of ports.
+ if (num_ports > max_num_ports) {
+ ELOG("Truncated number of ports from %d to %d", num_ports,
+ max_num_ports);
+ num_ports = max_num_ports;
+ }
- dev->active_port_count = num_ports;
+ dev->active_port_count = num_ports;
- DLOG("RTS5453 PPM is ready to init.");
- return dev->ppm->init_and_wait(dev->ppm->dev, num_ports);
+ DLOG("RTS5453 PPM is ready to init.");
+ return dev->ppm->init_and_wait(dev->ppm->dev, num_ports);
}
-static struct ucsi_ppm_driver* rts5453_ucsi_get_ppm(
- struct ucsi_pd_device* device) {
- struct rts5453_device* dev = CAST_FROM(device);
- return dev->ppm;
+static struct ucsi_ppm_driver *
+rts5453_ucsi_get_ppm(struct ucsi_pd_device *device)
+{
+ struct rts5453_device *dev = CAST_FROM(device);
+ return dev->ppm;
}
-struct ucsi_pd_driver* rts5453_open(struct smbus_driver* smbus,
- struct pd_driver_config* config) {
- struct rts5453_device* dev = NULL;
- struct ucsi_pd_driver* drv = NULL;
+struct ucsi_pd_driver *rts5453_open(struct smbus_driver *smbus,
+ struct pd_driver_config *config)
+{
+ struct rts5453_device *dev = NULL;
+ struct ucsi_pd_driver *drv = NULL;
- dev = platform_calloc(1, sizeof(struct rts5453_device));
- if (!dev) {
- goto handle_error;
- }
+ dev = platform_calloc(1, sizeof(struct rts5453_device));
+ if (!dev) {
+ goto handle_error;
+ }
- dev->smbus = smbus;
- dev->driver_config = config;
+ dev->smbus = smbus;
+ dev->driver_config = config;
- drv = platform_calloc(1, sizeof(struct ucsi_pd_driver));
- if (!drv) {
- goto handle_error;
- }
+ drv = platform_calloc(1, sizeof(struct ucsi_pd_driver));
+ if (!drv) {
+ goto handle_error;
+ }
- drv->dev = (struct ucsi_pd_device*)dev;
+ drv->dev = (struct ucsi_pd_device *)dev;
- drv->configure_lpm_irq = rts5453_ucsi_configure_lpm_irq;
- drv->init_ppm = rts5453_ucsi_init_ppm;
- drv->get_ppm = rts5453_ucsi_get_ppm;
- drv->execute_cmd = rts5453_ucsi_execute_cmd;
- drv->cleanup = rts5453_ucsi_cleanup;
+ drv->configure_lpm_irq = rts5453_ucsi_configure_lpm_irq;
+ drv->init_ppm = rts5453_ucsi_init_ppm;
+ drv->get_ppm = rts5453_ucsi_get_ppm;
+ drv->execute_cmd = rts5453_ucsi_execute_cmd;
+ drv->cleanup = rts5453_ucsi_cleanup;
- // Initialize the PPM.
- dev->ppm = ppm_open(drv);
- if (!dev->ppm) {
- ELOG("Failed to open PPM");
- goto handle_error;
- }
+ // Initialize the PPM.
+ dev->ppm = ppm_open(drv);
+ if (!dev->ppm) {
+ ELOG("Failed to open PPM");
+ goto handle_error;
+ }
- return drv;
+ return drv;
handle_error:
- if (dev && dev->ppm) {
- dev->ppm->cleanup(dev->ppm);
- dev->ppm = NULL;
- }
+ if (dev && dev->ppm) {
+ dev->ppm->cleanup(dev->ppm);
+ dev->ppm = NULL;
+ }
- platform_free(dev);
- platform_free(drv);
+ platform_free(dev);
+ platform_free(drv);
- return NULL;
+ return NULL;
}
-struct pd_driver_config rts5453_get_driver_config() {
- struct pd_driver_config config = {
+struct pd_driver_config rts5453_get_driver_config()
+{
+ struct pd_driver_config config = {
.max_num_ports = 2,
.port_address_map =
{
@@ -813,5 +854,5 @@
},
};
- return config;
+ return config;
}
diff --git a/rts5453.h b/rts5453.h
index 2921d80..cbb042e 100644
--- a/rts5453.h
+++ b/rts5453.h
@@ -9,43 +9,44 @@
#include "include/pd_driver.h"
#include "include/smbus.h"
-#define RTS_DEFAULT_PORT 0
+#define RTS_DEFAULT_PORT 0
/* Forward declaration only. */
struct rts5453_device;
struct rts5453_ic_status {
- uint8_t code_location;
- uint16_t reserved_0;
+ uint8_t code_location;
+ uint16_t reserved_0;
- uint8_t major_version;
- uint8_t minor_version;
- uint8_t patch_version;
- uint16_t reserved_1;
+ uint8_t major_version;
+ uint8_t minor_version;
+ uint8_t patch_version;
+ uint16_t reserved_1;
- uint8_t pd_typec_status;
- uint8_t vid_pid[4];
- uint8_t reserved_2;
+ uint8_t pd_typec_status;
+ uint8_t vid_pid[4];
+ uint8_t reserved_2;
- uint8_t flash_bank;
- uint8_t reserved_3[16];
+ uint8_t flash_bank;
+ uint8_t reserved_3[16];
} __attribute__((__packed__));
enum rts5453_flash_protect {
- RTS5453_FLASH_PROTECT_DISABLE = 0,
- RTS5453_FLASH_PROTECT_ENABLE = 1,
+ RTS5453_FLASH_PROTECT_DISABLE = 0,
+ RTS5453_FLASH_PROTECT_ENABLE = 1,
};
// 32 - 3 [Count; ADDR_L; ADDR_H; WR_DATA_COUNT]
#define FW_BLOCK_CHUNK_SIZE 29
-int rts5453_vendor_cmd_disable(struct rts5453_device* dev, uint8_t port);
-int rts5453_vendor_cmd_enable_smbus(struct rts5453_device* dev, uint8_t port);
-int rts5453_vendor_cmd_enable_smbus_flash_access(struct rts5453_device* dev, uint8_t port);
+int rts5453_vendor_cmd_disable(struct rts5453_device *dev, uint8_t port);
+int rts5453_vendor_cmd_enable_smbus(struct rts5453_device *dev, uint8_t port);
+int rts5453_vendor_cmd_enable_smbus_flash_access(struct rts5453_device *dev,
+ uint8_t port);
-int rts5453_set_flash_protection(struct rts5453_device* dev, int flash_protect);
-int rts5453_isp_validation(struct rts5453_device* dev);
-int rts5453_reset_to_flash(struct rts5453_device* dev);
+int rts5453_set_flash_protection(struct rts5453_device *dev, int flash_protect);
+int rts5453_isp_validation(struct rts5453_device *dev);
+int rts5453_reset_to_flash(struct rts5453_device *dev);
/**
* Write data to a specific flash bank at a specific offset.
@@ -56,18 +57,18 @@
* @param size - Size of |inbuf|.
* @param offset - Offset in flash to write at.
*/
-int rts5453_write_to_flash(struct rts5453_device* dev, int flash_bank,
- const char* inbuf, uint8_t size, size_t offset);
+int rts5453_write_to_flash(struct rts5453_device *dev, int flash_bank,
+ const char *inbuf, uint8_t size, size_t offset);
-int rts5453_get_ic_status(struct rts5453_device* dev,
- struct rts5453_ic_status* status);
+int rts5453_get_ic_status(struct rts5453_device *dev,
+ struct rts5453_ic_status *status);
// Establish connection and get basic info about the PD controller.
-int rts5453_get_info(struct ucsi_pd_driver* pd);
+int rts5453_get_info(struct ucsi_pd_driver *pd);
// Firmware update for the PD controller.
-int rts5453_do_firmware_update(struct ucsi_pd_driver* pd, const char* filepath,
- int dry_run);
+int rts5453_do_firmware_update(struct ucsi_pd_driver *pd, const char *filepath,
+ int dry_run);
/**
* Open RTS5453 device using SMBUS driver.
@@ -75,12 +76,12 @@
* @param smbus_driver: Already open smbus connection.
* @param config: Configuration for this driver.
*/
-struct ucsi_pd_driver* rts5453_open(struct smbus_driver* smbus,
- struct pd_driver_config* config);
+struct ucsi_pd_driver *rts5453_open(struct smbus_driver *smbus,
+ struct pd_driver_config *config);
/**
* Get the driver configuration for the RTS5453 driver.
*/
struct pd_driver_config rts5453_get_driver_config();
-#endif // UM_PPM_RTS5453_H_
+#endif // UM_PPM_RTS5453_H_
diff --git a/smbus_usermode.c b/smbus_usermode.c
index eb6810e..ee9d760 100644
--- a/smbus_usermode.c
+++ b/smbus_usermode.c
@@ -3,22 +3,22 @@
* found in the LICENSE file.
*/
+#include "include/platform.h"
#include "smbus_usermode.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
#include <fcntl.h>
#include <gpiod.h>
#include <i2c/smbus.h>
#include <linux/i2c-dev.h>
#include <pthread.h>
-#include <stdio.h>
-#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
-#include <time.h>
#include <unistd.h>
-#include "include/platform.h"
-
#define MAX_PATH_SIZE 32
// 10ms timeout for gpiod wakeup
@@ -30,366 +30,377 @@
* Internal structure for usermode smbus implementation.
*/
struct smbus_usermode_device {
- int fd;
+ int fd;
- // Currently active chip address.
- uint8_t chip_address;
+ // Currently active chip address.
+ uint8_t chip_address;
- pthread_mutex_t cmd_lock;
- pthread_mutex_t gpio_lock;
- struct gpiod_chip* chip;
- struct gpiod_line* line;
+ pthread_mutex_t cmd_lock;
+ pthread_mutex_t gpio_lock;
+ struct gpiod_chip *chip;
+ struct gpiod_line *line;
- volatile bool cleaning_up;
+ volatile bool cleaning_up;
};
-#define CAST_FROM(v) (struct smbus_usermode_device*)(v)
+#define CAST_FROM(v) (struct smbus_usermode_device *)(v)
-int __smbus_switch_address_nolock(struct smbus_usermode_device* dev,
- uint8_t chip_address) {
- int ret;
+int __smbus_switch_address_nolock(struct smbus_usermode_device *dev,
+ uint8_t chip_address)
+{
+ int ret;
- // No-op since we're already on the active chip.
- if (dev->chip_address == chip_address) {
- return 0;
- }
+ // No-op since we're already on the active chip.
+ if (dev->chip_address == chip_address) {
+ return 0;
+ }
- // Make sure this returns -1 or 0.
- ret = ioctl(dev->fd, I2C_SLAVE, chip_address);
- if (ret < 0) {
- ELOG("IOCTL switch to chip_address 0x%02x failed: %d", chip_address, ret);
- return -1;
- }
+ // Make sure this returns -1 or 0.
+ ret = ioctl(dev->fd, I2C_SLAVE, chip_address);
+ if (ret < 0) {
+ ELOG("IOCTL switch to chip_address 0x%02x failed: %d",
+ chip_address, ret);
+ return -1;
+ }
- dev->chip_address = chip_address;
+ dev->chip_address = chip_address;
- return 0;
+ return 0;
}
-int __smbus_um_read_byte_nolock(struct smbus_usermode_device* dev) {
- return i2c_smbus_read_byte(dev->fd);
+int __smbus_um_read_byte_nolock(struct smbus_usermode_device *dev)
+{
+ return i2c_smbus_read_byte(dev->fd);
}
-int smbus_um_read_byte(struct smbus_device* device, uint8_t chip_address) {
- struct smbus_usermode_device* dev = CAST_FROM(device);
- int ret = 0;
+int smbus_um_read_byte(struct smbus_device *device, uint8_t chip_address)
+{
+ struct smbus_usermode_device *dev = CAST_FROM(device);
+ int ret = 0;
- if (dev->fd < 0) {
- ELOG("Saw fd of %d", dev->fd);
- return -1;
- }
+ if (dev->fd < 0) {
+ ELOG("Saw fd of %d", dev->fd);
+ return -1;
+ }
- pthread_mutex_lock(&dev->cmd_lock);
- ret = __smbus_switch_address_nolock(dev, chip_address);
- if (ret == 0) {
- ret = __smbus_um_read_byte_nolock(dev);
- }
- pthread_mutex_unlock(&dev->cmd_lock);
+ pthread_mutex_lock(&dev->cmd_lock);
+ ret = __smbus_switch_address_nolock(dev, chip_address);
+ if (ret == 0) {
+ ret = __smbus_um_read_byte_nolock(dev);
+ }
+ pthread_mutex_unlock(&dev->cmd_lock);
- return ret;
+ return ret;
}
-int smbus_um_read_block(struct smbus_device* device, uint8_t chip_address,
- uint8_t address, void* buf, size_t length) {
- struct smbus_usermode_device* dev = CAST_FROM(device);
- uint8_t local_data[32];
- int ret = 0;
+int smbus_um_read_block(struct smbus_device *device, uint8_t chip_address,
+ uint8_t address, void *buf, size_t length)
+{
+ struct smbus_usermode_device *dev = CAST_FROM(device);
+ uint8_t local_data[32];
+ int ret = 0;
- if (dev->fd < 0) {
- ELOG("Saw fd of %d", dev->fd);
- return -1;
- }
+ if (dev->fd < 0) {
+ ELOG("Saw fd of %d", dev->fd);
+ return -1;
+ }
- // Block read will read at most 32 bytes.
- if (length > 32) {
- ELOG("Got length > 32 for block read");
- return -1;
- }
+ // Block read will read at most 32 bytes.
+ if (length > 32) {
+ ELOG("Got length > 32 for block read");
+ return -1;
+ }
- pthread_mutex_lock(&dev->cmd_lock);
+ pthread_mutex_lock(&dev->cmd_lock);
- DLOG("[0x%02x]: Reading block at 0x%02x", chip_address, address);
+ DLOG("[0x%02x]: Reading block at 0x%02x", chip_address, address);
- ret = __smbus_switch_address_nolock(dev, chip_address);
- if (ret != 0) {
- goto unlock;
- }
+ ret = __smbus_switch_address_nolock(dev, chip_address);
+ if (ret != 0) {
+ goto unlock;
+ }
- ret = i2c_smbus_read_block_data(dev->fd, address, local_data);
- if (ret <= 0) {
- goto unlock;
- }
+ ret = i2c_smbus_read_block_data(dev->fd, address, local_data);
+ if (ret <= 0) {
+ goto unlock;
+ }
- if (ret != length) {
- length = ret;
- }
+ if (ret != length) {
+ length = ret;
+ }
- platform_memcpy(buf, local_data, length);
- DLOG_START("[0x%02x]: Reading data from %02x [", chip_address, address);
- for (int i = 0; i < length; ++i) {
- DLOG_LOOP("%02x, ", ((uint8_t*)buf)[i]);
- }
- DLOG_END("]");
-
+ platform_memcpy(buf, local_data, length);
+ DLOG_START("[0x%02x]: Reading data from %02x [", chip_address, address);
+ for (int i = 0; i < length; ++i) {
+ DLOG_LOOP("%02x, ", ((uint8_t *)buf)[i]);
+ }
+ DLOG_END("]");
unlock:
- pthread_mutex_unlock(&dev->cmd_lock);
- return ret;
+ pthread_mutex_unlock(&dev->cmd_lock);
+ return ret;
}
-int smbus_um_write_block(struct smbus_device* device, uint8_t chip_address,
- uint8_t address, void* buf, size_t length) {
- struct smbus_usermode_device* dev = CAST_FROM(device);
- int ret = 0;
+int smbus_um_write_block(struct smbus_device *device, uint8_t chip_address,
+ uint8_t address, void *buf, size_t length)
+{
+ struct smbus_usermode_device *dev = CAST_FROM(device);
+ int ret = 0;
- if (dev->fd < 0) {
- ELOG("Saw fd of %d", dev->fd);
- return -1;
- }
+ if (dev->fd < 0) {
+ ELOG("Saw fd of %d", dev->fd);
+ return -1;
+ }
- DLOG_START("[0x%02x]: Sending data to %02x [", chip_address, address);
- for (int i = 0; i < length; ++i) {
- DLOG_LOOP("%02x, ", ((uint8_t*)buf)[i]);
- }
- DLOG_END("]");
+ DLOG_START("[0x%02x]: Sending data to %02x [", chip_address, address);
+ for (int i = 0; i < length; ++i) {
+ DLOG_LOOP("%02x, ", ((uint8_t *)buf)[i]);
+ }
+ DLOG_END("]");
- pthread_mutex_lock(&dev->cmd_lock);
- ret = __smbus_switch_address_nolock(dev, chip_address);
- if (ret != 0) {
- goto unlock;
- }
- ret = i2c_smbus_write_block_data(dev->fd, address, length, buf);
+ pthread_mutex_lock(&dev->cmd_lock);
+ ret = __smbus_switch_address_nolock(dev, chip_address);
+ if (ret != 0) {
+ goto unlock;
+ }
+ ret = i2c_smbus_write_block_data(dev->fd, address, length, buf);
unlock:
- pthread_mutex_unlock(&dev->cmd_lock);
- return ret;
+ pthread_mutex_unlock(&dev->cmd_lock);
+ return ret;
}
-int smbus_um_read_ara(struct smbus_device* device, uint8_t ara_address) {
- struct smbus_usermode_device* dev = CAST_FROM(device);
- uint8_t chip_address;
- uint8_t ara_byte_result;
- int ret;
+int smbus_um_read_ara(struct smbus_device *device, uint8_t ara_address)
+{
+ struct smbus_usermode_device *dev = CAST_FROM(device);
+ uint8_t chip_address;
+ uint8_t ara_byte_result;
+ int ret;
- pthread_mutex_lock(&dev->cmd_lock);
+ pthread_mutex_lock(&dev->cmd_lock);
- // Restore to this address.
- chip_address = dev->chip_address;
+ // Restore to this address.
+ chip_address = dev->chip_address;
- do {
- // First set the I2C address to the alert receiving address (0xC)
- if (ioctl(dev->fd, I2C_SLAVE, ara_address) < 0) {
- ELOG("Couldn't switch to alert receiving address: 0x%x!",
- ara_address);
- ret = -1;
- break;
- }
+ do {
+ // First set the I2C address to the alert receiving address
+ // (0xC)
+ if (ioctl(dev->fd, I2C_SLAVE, ara_address) < 0) {
+ ELOG("Couldn't switch to alert receiving address: 0x%x!",
+ ara_address);
+ ret = -1;
+ break;
+ }
- // ARA address will have 8 bits with top 7 bits of address. Right shift to
- // get actual chip address. Even if ARA is wrong, we still need to restore
- // slave address so don't exit yet.
- ara_byte_result = __smbus_um_read_byte_nolock(dev);
- ret = ara_byte_result >> 1;
+ // ARA address will have 8 bits with top 7 bits of address.
+ // Right shift to get actual chip address. Even if ARA is wrong,
+ // we still need to restore slave address so don't exit yet.
+ ara_byte_result = __smbus_um_read_byte_nolock(dev);
+ ret = ara_byte_result >> 1;
- if (ioctl(dev->fd, I2C_SLAVE, chip_address) < 0) {
- ELOG("Couldn't restore chip address: 0x%x. ARA was 0x%x", chip_address,
- ret);
- ret = -1;
- break;
- }
+ if (ioctl(dev->fd, I2C_SLAVE, chip_address) < 0) {
+ ELOG("Couldn't restore chip address: 0x%x. ARA was 0x%x",
+ chip_address, ret);
+ ret = -1;
+ break;
+ }
- } while (false);
+ } while (false);
- pthread_mutex_unlock(&dev->cmd_lock);
+ pthread_mutex_unlock(&dev->cmd_lock);
- return ret;
+ return ret;
}
-int smbus_um_block_for_interrupt(struct smbus_device* device) {
- struct smbus_usermode_device* dev = CAST_FROM(device);
- int ret = 0;
- bool cleaning_up = false;
- struct timespec ts;
+int smbus_um_block_for_interrupt(struct smbus_device *device)
+{
+ struct smbus_usermode_device *dev = CAST_FROM(device);
+ int ret = 0;
+ bool cleaning_up = false;
+ struct timespec ts;
- if (!(dev->chip && dev->line)) {
- ELOG("Gpio not initialized for polling.");
- return -1;
- }
+ if (!(dev->chip && dev->line)) {
+ ELOG("Gpio not initialized for polling.");
+ return -1;
+ }
- if (dev->cleaning_up) {
- return -1;
- }
+ if (dev->cleaning_up) {
+ return -1;
+ }
- ts.tv_sec = 0;
- ts.tv_nsec = GPIOD_WAIT_TIMEOUT_NS;
+ ts.tv_sec = 0;
+ ts.tv_nsec = GPIOD_WAIT_TIMEOUT_NS;
- DLOG("Polling for smbus interrupt.");
+ DLOG("Polling for smbus interrupt.");
- do {
- pthread_mutex_lock(&dev->gpio_lock);
+ do {
+ pthread_mutex_lock(&dev->gpio_lock);
- ret = gpiod_line_event_wait(dev->line, &ts);
- cleaning_up = dev->cleaning_up;
+ ret = gpiod_line_event_wait(dev->line, &ts);
+ cleaning_up = dev->cleaning_up;
- pthread_mutex_unlock(&dev->gpio_lock);
+ pthread_mutex_unlock(&dev->gpio_lock);
- // If we're cleaning up, exit out with an error.
- if (cleaning_up) {
- ret = -1;
- break;
- }
+ // If we're cleaning up, exit out with an error.
+ if (cleaning_up) {
+ ret = -1;
+ break;
+ }
- // Either error or result will break here. Otherwise, continue.
- if (ret == 1 || ret == -1) {
- break;
- }
- } while (true);
+ // Either error or result will break here. Otherwise, continue.
+ if (ret == 1 || ret == -1) {
+ break;
+ }
+ } while (true);
- // Got an event. Clear the event before forwarding interrupt.
- if (ret == 1) {
- struct gpiod_line_event event;
- DLOG("Got SMBUS interrupt!");
+ // Got an event. Clear the event before forwarding interrupt.
+ if (ret == 1) {
+ struct gpiod_line_event event;
+ DLOG("Got SMBUS interrupt!");
- // First clear the line event.
- if (gpiod_line_event_read(dev->line, &event) == -1) {
- ELOG("Failed to read line event.");
- ret = -1;
- }
- } else {
- DLOG("Smbus polling resulted in ret %d", ret);
- }
+ // First clear the line event.
+ if (gpiod_line_event_read(dev->line, &event) == -1) {
+ ELOG("Failed to read line event.");
+ ret = -1;
+ }
+ } else {
+ DLOG("Smbus polling resulted in ret %d", ret);
+ }
- return ret == 1 ? 0 : -1;
+ return ret == 1 ? 0 : -1;
}
-void smbus_um_cleanup(struct smbus_driver* driver) {
- if (driver->dev) {
- struct smbus_usermode_device* dev = CAST_FROM(driver->dev);
- if (dev->fd) {
- close(dev->fd);
- }
+void smbus_um_cleanup(struct smbus_driver *driver)
+{
+ if (driver->dev) {
+ struct smbus_usermode_device *dev = CAST_FROM(driver->dev);
+ if (dev->fd) {
+ close(dev->fd);
+ }
- dev->cleaning_up = true;
- pthread_mutex_lock(&dev->gpio_lock);
- pthread_mutex_unlock(&dev->gpio_lock);
+ dev->cleaning_up = true;
+ pthread_mutex_lock(&dev->gpio_lock);
+ pthread_mutex_unlock(&dev->gpio_lock);
- free(driver->dev);
- driver->dev = NULL;
- }
+ free(driver->dev);
+ driver->dev = NULL;
+ }
}
-static int init_interrupt(struct smbus_usermode_device* dev, int gpio_chip,
- int gpio_line) {
- struct gpiod_chip* chip = NULL;
- struct gpiod_line* line = NULL;
- char filename[MAX_PATH_SIZE];
+static int init_interrupt(struct smbus_usermode_device *dev, int gpio_chip,
+ int gpio_line)
+{
+ struct gpiod_chip *chip = NULL;
+ struct gpiod_line *line = NULL;
+ char filename[MAX_PATH_SIZE];
- if (pthread_mutex_init(&dev->gpio_lock, NULL) != 0) {
- ELOG("Failed to init gpio mutex");
- return -1;
- }
+ if (pthread_mutex_init(&dev->gpio_lock, NULL) != 0) {
+ ELOG("Failed to init gpio mutex");
+ return -1;
+ }
- if (pthread_mutex_init(&dev->cmd_lock, NULL) != 0) {
- ELOG("Failed to init command lock");
- return -1;
- }
+ if (pthread_mutex_init(&dev->cmd_lock, NULL) != 0) {
+ ELOG("Failed to init command lock");
+ return -1;
+ }
- // Request gpiochip and lines
- snprintf(filename, MAX_PATH_SIZE - 1, "/dev/gpiochip%d", gpio_chip);
- chip = gpiod_chip_open(filename);
- if (!chip) {
- ELOG("Failed to open %s", filename);
- goto cleanup;
- }
+ // Request gpiochip and lines
+ snprintf(filename, MAX_PATH_SIZE - 1, "/dev/gpiochip%d", gpio_chip);
+ chip = gpiod_chip_open(filename);
+ if (!chip) {
+ ELOG("Failed to open %s", filename);
+ goto cleanup;
+ }
- line = gpiod_chip_get_line(chip, gpio_line);
- if (!line) {
- ELOG("Failed to get line %d", gpio_line);
- goto cleanup;
- }
+ line = gpiod_chip_get_line(chip, gpio_line);
+ if (!line) {
+ ELOG("Failed to get line %d", gpio_line);
+ goto cleanup;
+ }
- if (gpiod_line_request_falling_edge_events(line, GPIOD_CONSUMER) != 0) {
- ELOG("Failed to set line config.");
- goto cleanup;
- }
+ if (gpiod_line_request_falling_edge_events(line, GPIOD_CONSUMER) != 0) {
+ ELOG("Failed to set line config.");
+ goto cleanup;
+ }
- dev->chip = chip;
- dev->line = line;
+ dev->chip = chip;
+ dev->line = line;
- return 0;
+ return 0;
cleanup:
- if (line) {
- gpiod_line_release(line);
- }
+ if (line) {
+ gpiod_line_release(line);
+ }
- if (chip) {
- gpiod_chip_close(chip);
- }
+ if (chip) {
+ gpiod_chip_close(chip);
+ }
- return -1;
+ return -1;
}
-struct smbus_driver* smbus_um_open(int bus_num, uint8_t chip_address,
- int gpio_chip, int gpio_line) {
- struct smbus_usermode_device* dev = NULL;
- struct smbus_driver* drv = NULL;
- int fd = -1;
- char filename[MAX_PATH_SIZE];
+struct smbus_driver *smbus_um_open(int bus_num, uint8_t chip_address,
+ int gpio_chip, int gpio_line)
+{
+ struct smbus_usermode_device *dev = NULL;
+ struct smbus_driver *drv = NULL;
+ int fd = -1;
+ char filename[MAX_PATH_SIZE];
- // Make sure we can open the i2c device.
- snprintf(filename, MAX_PATH_SIZE - 1, "/dev/i2c-%d", bus_num);
- fd = open(filename, O_RDWR);
- if (fd < 0) {
- ELOG("Could not open i2c device.");
- return NULL;
- }
+ // Make sure we can open the i2c device.
+ snprintf(filename, MAX_PATH_SIZE - 1, "/dev/i2c-%d", bus_num);
+ fd = open(filename, O_RDWR);
+ if (fd < 0) {
+ ELOG("Could not open i2c device.");
+ return NULL;
+ }
- // Switch to a specific chip address.
- if (ioctl(fd, I2C_SLAVE, chip_address) < 0) {
- ELOG("Could not switch to given chip address.");
- goto handle_error;
- }
+ // Switch to a specific chip address.
+ if (ioctl(fd, I2C_SLAVE, chip_address) < 0) {
+ ELOG("Could not switch to given chip address.");
+ goto handle_error;
+ }
- dev = calloc(1, sizeof(struct smbus_usermode_device));
- if (!dev) {
- goto handle_error;
- }
+ dev = calloc(1, sizeof(struct smbus_usermode_device));
+ if (!dev) {
+ goto handle_error;
+ }
- dev->fd = fd;
- dev->chip_address = chip_address;
+ dev->fd = fd;
+ dev->chip_address = chip_address;
- // Initialize the gpio lines
- if (init_interrupt(dev, gpio_chip, gpio_line) == -1) {
- ELOG("Failed to initialize gpio for interrupt.");
- goto handle_error;
- }
+ // Initialize the gpio lines
+ if (init_interrupt(dev, gpio_chip, gpio_line) == -1) {
+ ELOG("Failed to initialize gpio for interrupt.");
+ goto handle_error;
+ }
- drv = calloc(1, sizeof(struct smbus_driver));
- if (!drv) {
- goto handle_error;
- }
+ drv = calloc(1, sizeof(struct smbus_driver));
+ if (!drv) {
+ goto handle_error;
+ }
- drv->dev = (struct smbus_device*)dev;
- drv->read_byte = smbus_um_read_byte;
- drv->read_block = smbus_um_read_block;
- drv->write_block = smbus_um_write_block;
- drv->read_ara = smbus_um_read_ara;
- drv->block_for_interrupt = smbus_um_block_for_interrupt;
- drv->cleanup = smbus_um_cleanup;
+ drv->dev = (struct smbus_device *)dev;
+ drv->read_byte = smbus_um_read_byte;
+ drv->read_block = smbus_um_read_block;
+ drv->write_block = smbus_um_write_block;
+ drv->read_ara = smbus_um_read_ara;
+ drv->block_for_interrupt = smbus_um_block_for_interrupt;
+ drv->cleanup = smbus_um_cleanup;
- // Make sure chip address is valid before returning.
- if (smbus_um_read_byte((struct smbus_device*)dev, chip_address) < 0) {
- ELOG("Could not read byte at given chip address.");
- goto handle_error;
- }
+ // Make sure chip address is valid before returning.
+ if (smbus_um_read_byte((struct smbus_device *)dev, chip_address) < 0) {
+ ELOG("Could not read byte at given chip address.");
+ goto handle_error;
+ }
- return drv;
+ return drv;
handle_error:
- close(fd);
- free(dev);
- free(drv);
+ close(fd);
+ free(dev);
+ free(drv);
- return NULL;
+ return NULL;
}
diff --git a/smbus_usermode.h b/smbus_usermode.h
index 0f2e3e5..612e72a 100644
--- a/smbus_usermode.h
+++ b/smbus_usermode.h
@@ -18,7 +18,7 @@
*
* @return Smbus driver for chosen bus + chip + gpio (alert#) or NULL on error.
*/
-struct smbus_driver* smbus_um_open(int bus_num, uint8_t chip_address,
- int gpio_chip, int gpio_line);
+struct smbus_driver *smbus_um_open(int bus_num, uint8_t chip_address,
+ int gpio_chip, int gpio_line);
-#endif // UM_PPM_SMBUS_USERMODE_H_
+#endif // UM_PPM_SMBUS_USERMODE_H_
diff --git a/um_ppm_chardev.c b/um_ppm_chardev.c
index 5921dbc..a300aed 100644
--- a/um_ppm_chardev.c
+++ b/um_ppm_chardev.c
@@ -3,286 +3,304 @@
* found in the LICENSE file.
*/
-#include "um_ppm_chardev.h"
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
#include "include/pd_driver.h"
#include "include/platform.h"
#include "include/ppm.h"
#include "include/smbus.h"
+#include "um_ppm_chardev.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <unistd.h>
// Packed message skeleton for cdev communication.
struct um_message_skeleton {
- uint8_t type;
- uint32_t offset;
- uint32_t data_length;
- uint8_t data[];
+ uint8_t type;
+ uint32_t offset;
+ uint32_t data_length;
+ uint8_t data[];
} __attribute__((__packed__));
#define MAX_DATA_SIZE 256
#define MAX_MESSAGE_DATA_SIZE \
- (MAX_DATA_SIZE + sizeof(struct um_message_skeleton))
+ (MAX_DATA_SIZE + sizeof(struct um_message_skeleton))
enum um_message_types {
- // Notify kernel
- UM_MSG_NOTIFY = 0x1,
+ // Notify kernel
+ UM_MSG_NOTIFY = 0x1,
- // Kernel reads from userspace
- UM_MSG_READ = 0x2,
+ // Kernel reads from userspace
+ UM_MSG_READ = 0x2,
- // Userspace responds to kernel read
- UM_MSG_READ_RSP = 0x3,
+ // Userspace responds to kernel read
+ UM_MSG_READ_RSP = 0x3,
- // Kernel writes to userspace
- UM_MSG_WRITE = 0x4,
+ // Kernel writes to userspace
+ UM_MSG_WRITE = 0x4,
- // Ready for communication
- UM_MSG_USERSPACE_READY = 0x5,
+ // Ready for communication
+ UM_MSG_USERSPACE_READY = 0x5,
- // Closing down
- UM_MSG_USERSPACE_CLOSING = 0x6,
+ // Closing down
+ UM_MSG_USERSPACE_CLOSING = 0x6,
};
-const char* message_type_strings[UM_MSG_USERSPACE_CLOSING + 1] = {
- "MSGTYPE_Invalid", "MSGTYPE_Notify", "MSGTYPE_Read",
- "MSGTYPE_Read_Response", "MSGTYPE_Write", "MSGTYPE_Userspace_Ready",
- "MSGTYPE_Userspace_Closing",
+const char *message_type_strings[UM_MSG_USERSPACE_CLOSING + 1] = {
+ "MSGTYPE_Invalid",
+ "MSGTYPE_Notify",
+ "MSGTYPE_Read",
+ "MSGTYPE_Read_Response",
+ "MSGTYPE_Write",
+ "MSGTYPE_Userspace_Ready",
+ "MSGTYPE_Userspace_Closing",
};
-const char* message_type_to_string(uint8_t type) {
- if (type > UM_MSG_USERSPACE_CLOSING) {
- return "MSGTYPE_Out_Of_Bounds";
- }
+const char *message_type_to_string(uint8_t type)
+{
+ if (type > UM_MSG_USERSPACE_CLOSING) {
+ return "MSGTYPE_Out_Of_Bounds";
+ }
- return message_type_strings[type];
+ return message_type_strings[type];
}
struct um_ppm_cdev {
- int fd;
+ int fd;
- struct ucsi_pd_driver* pd;
- struct ucsi_ppm_driver* ppm;
- struct smbus_driver* smbus;
- struct pd_driver_config* driver_config;
+ struct ucsi_pd_driver *pd;
+ struct ucsi_ppm_driver *ppm;
+ struct smbus_driver *smbus;
+ struct pd_driver_config *driver_config;
};
-#define READ_NOINTR(fd, buf, size) \
- do { \
- if (read(fd, buf, size) == -1 && errno == -EINTR) { \
- continue; \
- } \
- } while (false)
+#define READ_NOINTR(fd, buf, size) \
+ do { \
+ if (read(fd, buf, size) == -1 && errno == -EINTR) { \
+ continue; \
+ } \
+ } while (false)
-#define WRITE_NOINTR(fd, buf, size) \
- do { \
- if (write(fd, buf, size) == -1 && errno == -EINTR) { \
- continue; \
- } \
- } while (false)
+#define WRITE_NOINTR(fd, buf, size) \
+ do { \
+ if (write(fd, buf, size) == -1 && errno == -EINTR) { \
+ continue; \
+ } \
+ } while (false)
-static void write_to_cdev(int fd, void* buf, size_t size) {
- DLOG("Writing to cdev (%d total bytes)", size);
- WRITE_NOINTR(fd, buf, size);
+static void write_to_cdev(int fd, void *buf, size_t size)
+{
+ DLOG("Writing to cdev (%d total bytes)", size);
+ WRITE_NOINTR(fd, buf, size);
}
-static void pretty_print_message(const char* prefix,
- const struct um_message_skeleton* msg) {
- DLOG_START("%s: Type 0x%x (%s): ", prefix, msg->type,
- message_type_to_string(msg->type));
+static void pretty_print_message(const char *prefix,
+ const struct um_message_skeleton *msg)
+{
+ DLOG_START("%s: Type 0x%x (%s): ", prefix, msg->type,
+ message_type_to_string(msg->type));
- // All message types will have offset + data length.
- DLOG_LOOP("Offset = 0x%x, Data Length = 0x%x, ", msg->offset,
- msg->data_length);
+ // All message types will have offset + data length.
+ DLOG_LOOP("Offset = 0x%x, Data Length = 0x%x, ", msg->offset,
+ msg->data_length);
- // Only write and read responses will have valid data within.
- switch (msg->type) {
- case UM_MSG_WRITE:
- case UM_MSG_READ_RSP:
- DLOG_LOOP("[ ");
- for (int i = 0; i < msg->data_length; ++i) {
- DLOG_LOOP("0x%x, ", msg->data[i]);
- }
- DLOG_LOOP("]");
- break;
- }
+ // Only write and read responses will have valid data within.
+ switch (msg->type) {
+ case UM_MSG_WRITE:
+ case UM_MSG_READ_RSP:
+ DLOG_LOOP("[ ");
+ for (int i = 0; i < msg->data_length; ++i) {
+ DLOG_LOOP("0x%x, ", msg->data[i]);
+ }
+ DLOG_LOOP("]");
+ break;
+ }
- DLOG_END("");
+ DLOG_END("");
}
-static void um_ppm_notify(void* context) {
- struct um_ppm_cdev* cdev = (struct um_ppm_cdev*)context;
- uint8_t data[sizeof(struct um_message_skeleton)];
+static void um_ppm_notify(void *context)
+{
+ struct um_ppm_cdev *cdev = (struct um_ppm_cdev *)context;
+ uint8_t data[sizeof(struct um_message_skeleton)];
- struct um_message_skeleton* msg = (struct um_message_skeleton*)data;
- msg->type = UM_MSG_NOTIFY;
- msg->offset = 0;
- msg->data_length = 0;
+ struct um_message_skeleton *msg = (struct um_message_skeleton *)data;
+ msg->type = UM_MSG_NOTIFY;
+ msg->offset = 0;
+ msg->data_length = 0;
- pretty_print_message("Notify", msg);
- write_to_cdev(cdev->fd, msg, sizeof(struct um_message_skeleton));
+ pretty_print_message("Notify", msg);
+ write_to_cdev(cdev->fd, msg, sizeof(struct um_message_skeleton));
}
-struct um_ppm_cdev* um_ppm_cdev_open(char* devpath, struct ucsi_pd_driver* pd,
- struct smbus_driver* smbus,
- struct pd_driver_config* driver_config) {
- struct um_ppm_cdev* cdev = NULL;
- int fd = -1;
+struct um_ppm_cdev *um_ppm_cdev_open(char *devpath, struct ucsi_pd_driver *pd,
+ struct smbus_driver *smbus,
+ struct pd_driver_config *driver_config)
+{
+ struct um_ppm_cdev *cdev = NULL;
+ int fd = -1;
- fd = open(devpath, O_RDWR);
- if (fd < 0) {
- ELOG("Could not open PPM char device.");
- return NULL;
- }
+ fd = open(devpath, O_RDWR);
+ if (fd < 0) {
+ ELOG("Could not open PPM char device.");
+ return NULL;
+ }
- cdev = calloc(1, sizeof(struct um_ppm_cdev));
- if (!cdev) {
- goto handle_error;
- }
+ cdev = calloc(1, sizeof(struct um_ppm_cdev));
+ if (!cdev) {
+ goto handle_error;
+ }
- cdev->fd = fd;
- cdev->pd = pd;
- cdev->ppm = pd->get_ppm(pd->dev);
- cdev->smbus = smbus;
- cdev->driver_config = driver_config;
+ cdev->fd = fd;
+ cdev->pd = pd;
+ cdev->ppm = pd->get_ppm(pd->dev);
+ cdev->smbus = smbus;
+ cdev->driver_config = driver_config;
- cdev->ppm->register_notify(cdev->ppm->dev, um_ppm_notify, (void*)cdev);
+ cdev->ppm->register_notify(cdev->ppm->dev, um_ppm_notify, (void *)cdev);
- return cdev;
+ return cdev;
handle_error:
- close(fd);
- free(cdev);
+ close(fd);
+ free(cdev);
- return NULL;
+ return NULL;
}
-void um_ppm_cdev_cleanup(struct um_ppm_cdev* cdev) {
- if (cdev) {
- // Clean up the notify task first.
- cdev->smbus->cleanup(cdev->smbus);
+void um_ppm_cdev_cleanup(struct um_ppm_cdev *cdev)
+{
+ if (cdev) {
+ // Clean up the notify task first.
+ cdev->smbus->cleanup(cdev->smbus);
- // Now clean up the cdev file (stopping communication).
- if (cdev->fd >= 0) {
- close(cdev->fd);
- cdev->fd = -1;
- }
+ // Now clean up the cdev file (stopping communication).
+ if (cdev->fd >= 0) {
+ close(cdev->fd);
+ cdev->fd = -1;
+ }
- // Finally, clean up the pd driver.
- cdev->pd->cleanup(cdev->pd);
+ // Finally, clean up the pd driver.
+ cdev->pd->cleanup(cdev->pd);
- free(cdev);
- }
+ free(cdev);
+ }
}
-static void um_ppm_notify_ready(struct um_ppm_cdev* cdev) {
- uint8_t data[sizeof(struct um_message_skeleton)];
+static void um_ppm_notify_ready(struct um_ppm_cdev *cdev)
+{
+ uint8_t data[sizeof(struct um_message_skeleton)];
- struct um_message_skeleton* msg = (struct um_message_skeleton*)data;
- msg->type = UM_MSG_USERSPACE_READY;
- msg->offset = 0;
- msg->data_length = 0;
+ struct um_message_skeleton *msg = (struct um_message_skeleton *)data;
+ msg->type = UM_MSG_USERSPACE_READY;
+ msg->offset = 0;
+ msg->data_length = 0;
- pretty_print_message("Ready", msg);
- write_to_cdev(cdev->fd, msg, sizeof(struct um_message_skeleton));
+ pretty_print_message("Ready", msg);
+ write_to_cdev(cdev->fd, msg, sizeof(struct um_message_skeleton));
}
-static int um_ppm_handle_message(struct um_ppm_cdev* cdev,
- struct um_message_skeleton* msg) {
- int ret = 0;
- struct ucsi_ppm_driver* ppm = cdev->ppm;
+static int um_ppm_handle_message(struct um_ppm_cdev *cdev,
+ struct um_message_skeleton *msg)
+{
+ int ret = 0;
+ struct ucsi_ppm_driver *ppm = cdev->ppm;
- switch (msg->type) {
- case UM_MSG_READ:
- // Read and write response on success.
- ret = ppm->read(ppm->dev, msg->offset, msg->data, msg->data_length);
- if (ret != -1) {
- msg->data_length = ret;
- msg->type = UM_MSG_READ_RSP;
+ switch (msg->type) {
+ case UM_MSG_READ:
+ // Read and write response on success.
+ ret = ppm->read(ppm->dev, msg->offset, msg->data,
+ msg->data_length);
+ if (ret != -1) {
+ msg->data_length = ret;
+ msg->type = UM_MSG_READ_RSP;
- pretty_print_message("Read response", msg);
- write_to_cdev(cdev->fd, msg,
- sizeof(struct um_message_skeleton) + msg->data_length);
- } else {
- ELOG("Error on read (%d) at offset 0x%x, length 0x%x", ret, msg->offset,
- msg->data_length);
- }
- break;
- case UM_MSG_WRITE:
- ret = ppm->write(ppm->dev, msg->offset, msg->data, msg->data_length);
- if (ret == -1) {
- ELOG("Error on write (%d) at offset 0x%x, length 0x%x", ret,
- msg->offset, msg->data_length);
- }
- break;
+ pretty_print_message("Read response", msg);
+ write_to_cdev(cdev->fd, msg,
+ sizeof(struct um_message_skeleton) +
+ msg->data_length);
+ } else {
+ ELOG("Error on read (%d) at offset 0x%x, length 0x%x",
+ ret, msg->offset, msg->data_length);
+ }
+ break;
+ case UM_MSG_WRITE:
+ ret = ppm->write(ppm->dev, msg->offset, msg->data,
+ msg->data_length);
+ if (ret == -1) {
+ ELOG("Error on write (%d) at offset 0x%x, length 0x%x",
+ ret, msg->offset, msg->data_length);
+ }
+ break;
- default:
- ELOG(
- "Unhandled um_ppm message of type (%d): offset(0x%x), data-len(0x%x)",
- msg->type, msg->offset, msg->data_length);
- return -1;
- }
+ default:
+ ELOG("Unhandled um_ppm message of type (%d): offset(0x%x), data-len(0x%x)",
+ msg->type, msg->offset, msg->data_length);
+ return -1;
+ }
- return 0;
+ return 0;
}
-void um_ppm_cdev_mainloop(struct um_ppm_cdev* cdev) {
- int bytes = 0;
+void um_ppm_cdev_mainloop(struct um_ppm_cdev *cdev)
+{
+ int bytes = 0;
- uint8_t data[MAX_MESSAGE_DATA_SIZE];
- platform_memset(data, 0, MAX_MESSAGE_DATA_SIZE);
+ uint8_t data[MAX_MESSAGE_DATA_SIZE];
+ platform_memset(data, 0, MAX_MESSAGE_DATA_SIZE);
- // Make sure IRQ is configured before continuing.
- if (cdev->pd->configure_lpm_irq(cdev->pd->dev) != 0) {
- ELOG("Failed to configure LPM IRQ!");
- return;
- }
+ // Make sure IRQ is configured before continuing.
+ if (cdev->pd->configure_lpm_irq(cdev->pd->dev) != 0) {
+ ELOG("Failed to configure LPM IRQ!");
+ return;
+ }
- // Wait for ppm to be ready before starting.
- cdev->pd->init_ppm(cdev->pd->dev);
+ // Wait for ppm to be ready before starting.
+ cdev->pd->init_ppm(cdev->pd->dev);
- // Let kernel know we're ready to handle events.
- um_ppm_notify_ready(cdev);
+ // Let kernel know we're ready to handle events.
+ um_ppm_notify_ready(cdev);
- do {
- // Clear read data and re-read
- platform_memset(data, 0, MAX_MESSAGE_DATA_SIZE);
- bytes = read(cdev->fd, data, MAX_MESSAGE_DATA_SIZE);
+ do {
+ // Clear read data and re-read
+ platform_memset(data, 0, MAX_MESSAGE_DATA_SIZE);
+ bytes = read(cdev->fd, data, MAX_MESSAGE_DATA_SIZE);
- // We got a valid message.
- if (bytes >= sizeof(struct um_message_skeleton)) {
- // If there's additional data left, read it out. Only valid for writes.
- struct um_message_skeleton* msg = (struct um_message_skeleton*)data;
- pretty_print_message("Read from cdev", msg);
+ // We got a valid message.
+ if (bytes >= sizeof(struct um_message_skeleton)) {
+ // If there's additional data left, read it out. Only
+ // valid for writes.
+ struct um_message_skeleton *msg =
+ (struct um_message_skeleton *)data;
+ pretty_print_message("Read from cdev", msg);
- // Handle the message.
- if (um_ppm_handle_message(cdev, msg) == -1) {
- break;
- }
- }
- // Nothing to read at this time (not sure why we woke up).
- else if (bytes == 0) {
- DLOG("Got back zero bytes from read. Shouldn't we block here?");
- break;
- } else if (bytes == -1) {
- if (errno == -EINTR) {
- continue;
- }
- DLOG("Failed to read from cdev due to errno=%d", errno);
- break;
- }
- } while (true);
+ // Handle the message.
+ if (um_ppm_handle_message(cdev, msg) == -1) {
+ break;
+ }
+ }
+ // Nothing to read at this time (not sure why we woke up).
+ else if (bytes == 0) {
+ DLOG("Got back zero bytes from read. Shouldn't we block here?");
+ break;
+ } else if (bytes == -1) {
+ if (errno == -EINTR) {
+ continue;
+ }
+ DLOG("Failed to read from cdev due to errno=%d", errno);
+ break;
+ }
+ } while (true);
}
-void um_ppm_handle_signal(struct um_ppm_cdev* cdev, int signal) {
- ELOG("Handling signal %d", signal);
+void um_ppm_handle_signal(struct um_ppm_cdev *cdev, int signal)
+{
+ ELOG("Handling signal %d", signal);
- if (cdev) {
- um_ppm_cdev_cleanup(cdev);
- }
+ if (cdev) {
+ um_ppm_cdev_cleanup(cdev);
+ }
}
diff --git a/um_ppm_chardev.h b/um_ppm_chardev.h
index 31578ef..80b9e17 100644
--- a/um_ppm_chardev.h
+++ b/um_ppm_chardev.h
@@ -13,14 +13,14 @@
struct um_ppm_cdev;
// Handle sigterm and sigkill.
-void um_ppm_handle_signal(struct um_ppm_cdev* cdev, int signal);
+void um_ppm_handle_signal(struct um_ppm_cdev *cdev, int signal);
// Initialize the um_ppm chardev.
-struct um_ppm_cdev* um_ppm_cdev_open(char* devpath, struct ucsi_pd_driver* pd,
- struct smbus_driver* smbus,
- struct pd_driver_config* driver_config);
+struct um_ppm_cdev *um_ppm_cdev_open(char *devpath, struct ucsi_pd_driver *pd,
+ struct smbus_driver *smbus,
+ struct pd_driver_config *driver_config);
// Loop handle the cdev communication and interrupts.
-void um_ppm_cdev_mainloop(struct um_ppm_cdev* cdev);
+void um_ppm_cdev_mainloop(struct um_ppm_cdev *cdev);
-#endif // UM_PPM_CHARDEV_H_
+#endif // UM_PPM_CHARDEV_H_