[PATCH v6 4/6] mfd: cros_ec: Add more definitions for PD commands

2016-03-19 Thread Tomeu Vizoso
Copy a few structs and commands from the EC firmware headers so we can
communicate with the EC regarding PD functionality.

Signed-off-by: Tomeu Vizoso 
---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 include/linux/mfd/cros_ec_commands.h | 324 ++-
 1 file changed, 319 insertions(+), 5 deletions(-)

diff --git a/include/linux/mfd/cros_ec_commands.h 
b/include/linux/mfd/cros_ec_commands.h
index d86526f0bd8e..4f056d2747ff 100644
--- a/include/linux/mfd/cros_ec_commands.h
+++ b/include/linux/mfd/cros_ec_commands.h
@@ -286,6 +286,9 @@ enum host_event_code {
/* Hang detect logic detected a hang and warm rebooted the AP */
EC_HOST_EVENT_HANG_REBOOT = 21,
 
+   /* PD MCU triggering host event */
+   EC_HOST_EVENT_PD_MCU = 22,
+
/*
 * The high bit of the event mask is not used as a host event code.  If
 * it reads back as set, then the entire event mask should be
@@ -2273,6 +2276,13 @@ struct ec_params_ext_power_current_limit {
uint32_t limit; /* in mA */
 } __packed;
 
+struct ec_params_external_power_limit_v1 {
+   uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
+   uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
+} __packed;
+
+#define EC_POWER_LIMIT_NONE 0x
+
 /*/
 /* Smart battery pass-through */
 
@@ -2527,8 +2537,6 @@ struct ec_params_reboot_ec {
  */
 #define EC_CMD_VERSION0 0xdc
 
-#endif  /* !__ACPI__ */
-
 /*/
 /*
  * PD commands
@@ -2538,16 +2546,51 @@ struct ec_params_reboot_ec {
 
 /* EC to PD MCU exchange status command */
 #define EC_CMD_PD_EXCHANGE_STATUS 0x100
+#define EC_VER_PD_EXCHANGE_STATUS 2
+
+enum pd_charge_state {
+   PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
+   PD_CHARGE_NONE,  /* No charging allowed */
+   PD_CHARGE_5V,/* 5V charging only */
+   PD_CHARGE_MAX/* Charge at max voltage */
+};
 
 /* Status of EC being sent to PD */
+#define EC_STATUS_HIBERNATING  (1 << 0)
+
 struct ec_params_pd_status {
-   int8_t batt_soc; /* battery state of charge */
+   uint8_t status;   /* EC status */
+   int8_t batt_soc;  /* battery state of charge */
+   uint8_t charge_state; /* charging state (from enum pd_charge_state) */
 } __packed;
 
 /* Status of PD being sent back to EC */
+#define PD_STATUS_HOST_EVENT  (1 << 0) /* Forward host event to AP */
+#define PD_STATUS_IN_RW   (1 << 1) /* Running RW image */
+#define PD_STATUS_JUMPED_TO_IMAGE (1 << 2) /* Current image was jumped to */
+#define PD_STATUS_TCPC_ALERT_0(1 << 3) /* Alert active in port 0 TCPC */
+#define PD_STATUS_TCPC_ALERT_1(1 << 4) /* Alert active in port 1 TCPC */
+#define PD_STATUS_TCPC_ALERT_2(1 << 5) /* Alert active in port 2 TCPC */
+#define PD_STATUS_TCPC_ALERT_3(1 << 6) /* Alert active in port 3 TCPC */
+#define PD_STATUS_EC_INT_ACTIVE  (PD_STATUS_TCPC_ALERT_0 | \
+ PD_STATUS_TCPC_ALERT_1 | \
+ PD_STATUS_HOST_EVENT)
 struct ec_response_pd_status {
-   int8_t status;/* PD MCU status */
-   uint32_t curr_lim_ma; /* input current limit */
+   uint32_t curr_lim_ma;   /* input current limit */
+   uint16_t status;/* PD MCU status */
+   int8_t active_charge_port;  /* active charging port */
+} __packed;
+
+/* AP to PD MCU host event status command, cleared on read */
+#define EC_CMD_PD_HOST_EVENT_STATUS 0x104
+
+/* PD MCU host event status bits */
+#define PD_EVENT_UPDATE_DEVICE (1 << 0)
+#define PD_EVENT_POWER_CHANGE  (1 << 1)
+#define PD_EVENT_IDENTITY_RECEIVED (1 << 2)
+#define PD_EVENT_DATA_SWAP (1 << 3)
+struct ec_response_host_event_status {
+   uint32_t status;  /* PD MCU host event status */
 } __packed;
 
 /* Set USB type-C port role and muxes */
@@ -2559,6 +2602,7 @@ enum usb_pd_control_role {
USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
USB_PD_CTRL_ROLE_FORCE_SINK = 3,
USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
+   USB_PD_CTRL_ROLE_COUNT
 };
 
 enum usb_pd_control_mux {
@@ -2568,14 +2612,284 @@ enum usb_pd_control_mux {
USB_PD_CTRL_MUX_DP = 3,
USB_PD_CTRL_MUX_DOCK = 4,
USB_PD_CTRL_MUX_AUTO = 5,
+   USB_PD_CTRL_MUX_COUNT
+};
+
+enum usb_pd_control_swap {
+   USB_PD_CTRL_SWAP_NONE = 0,
+   USB_PD_CTRL_SWAP_DATA = 1,
+   USB_PD_CTRL_SWAP_POWER = 2,
+   USB_PD_CTRL_SWAP_VCONN = 3,
+   USB_PD_CTRL_SWAP_COUNT
 };
 
 struct ec_params_usb_pd_control {
uint8_t port;
uint8_t role;
uint8_t mux;
+   uint8_t swap;
+} __packed;
+
+#define PD_CTRL_RESP_ENABLED_COMMS  (1 << 0) /* Communication enabled */
+#define 

[PATCH v6 4/6] mfd: cros_ec: Add more definitions for PD commands

2016-03-19 Thread Tomeu Vizoso
Copy a few structs and commands from the EC firmware headers so we can
communicate with the EC regarding PD functionality.

Signed-off-by: Tomeu Vizoso 
---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 include/linux/mfd/cros_ec_commands.h | 324 ++-
 1 file changed, 319 insertions(+), 5 deletions(-)

diff --git a/include/linux/mfd/cros_ec_commands.h 
b/include/linux/mfd/cros_ec_commands.h
index d86526f0bd8e..4f056d2747ff 100644
--- a/include/linux/mfd/cros_ec_commands.h
+++ b/include/linux/mfd/cros_ec_commands.h
@@ -286,6 +286,9 @@ enum host_event_code {
/* Hang detect logic detected a hang and warm rebooted the AP */
EC_HOST_EVENT_HANG_REBOOT = 21,
 
+   /* PD MCU triggering host event */
+   EC_HOST_EVENT_PD_MCU = 22,
+
/*
 * The high bit of the event mask is not used as a host event code.  If
 * it reads back as set, then the entire event mask should be
@@ -2273,6 +2276,13 @@ struct ec_params_ext_power_current_limit {
uint32_t limit; /* in mA */
 } __packed;
 
+struct ec_params_external_power_limit_v1 {
+   uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
+   uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
+} __packed;
+
+#define EC_POWER_LIMIT_NONE 0x
+
 /*/
 /* Smart battery pass-through */
 
@@ -2527,8 +2537,6 @@ struct ec_params_reboot_ec {
  */
 #define EC_CMD_VERSION0 0xdc
 
-#endif  /* !__ACPI__ */
-
 /*/
 /*
  * PD commands
@@ -2538,16 +2546,51 @@ struct ec_params_reboot_ec {
 
 /* EC to PD MCU exchange status command */
 #define EC_CMD_PD_EXCHANGE_STATUS 0x100
+#define EC_VER_PD_EXCHANGE_STATUS 2
+
+enum pd_charge_state {
+   PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
+   PD_CHARGE_NONE,  /* No charging allowed */
+   PD_CHARGE_5V,/* 5V charging only */
+   PD_CHARGE_MAX/* Charge at max voltage */
+};
 
 /* Status of EC being sent to PD */
+#define EC_STATUS_HIBERNATING  (1 << 0)
+
 struct ec_params_pd_status {
-   int8_t batt_soc; /* battery state of charge */
+   uint8_t status;   /* EC status */
+   int8_t batt_soc;  /* battery state of charge */
+   uint8_t charge_state; /* charging state (from enum pd_charge_state) */
 } __packed;
 
 /* Status of PD being sent back to EC */
+#define PD_STATUS_HOST_EVENT  (1 << 0) /* Forward host event to AP */
+#define PD_STATUS_IN_RW   (1 << 1) /* Running RW image */
+#define PD_STATUS_JUMPED_TO_IMAGE (1 << 2) /* Current image was jumped to */
+#define PD_STATUS_TCPC_ALERT_0(1 << 3) /* Alert active in port 0 TCPC */
+#define PD_STATUS_TCPC_ALERT_1(1 << 4) /* Alert active in port 1 TCPC */
+#define PD_STATUS_TCPC_ALERT_2(1 << 5) /* Alert active in port 2 TCPC */
+#define PD_STATUS_TCPC_ALERT_3(1 << 6) /* Alert active in port 3 TCPC */
+#define PD_STATUS_EC_INT_ACTIVE  (PD_STATUS_TCPC_ALERT_0 | \
+ PD_STATUS_TCPC_ALERT_1 | \
+ PD_STATUS_HOST_EVENT)
 struct ec_response_pd_status {
-   int8_t status;/* PD MCU status */
-   uint32_t curr_lim_ma; /* input current limit */
+   uint32_t curr_lim_ma;   /* input current limit */
+   uint16_t status;/* PD MCU status */
+   int8_t active_charge_port;  /* active charging port */
+} __packed;
+
+/* AP to PD MCU host event status command, cleared on read */
+#define EC_CMD_PD_HOST_EVENT_STATUS 0x104
+
+/* PD MCU host event status bits */
+#define PD_EVENT_UPDATE_DEVICE (1 << 0)
+#define PD_EVENT_POWER_CHANGE  (1 << 1)
+#define PD_EVENT_IDENTITY_RECEIVED (1 << 2)
+#define PD_EVENT_DATA_SWAP (1 << 3)
+struct ec_response_host_event_status {
+   uint32_t status;  /* PD MCU host event status */
 } __packed;
 
 /* Set USB type-C port role and muxes */
@@ -2559,6 +2602,7 @@ enum usb_pd_control_role {
USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
USB_PD_CTRL_ROLE_FORCE_SINK = 3,
USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
+   USB_PD_CTRL_ROLE_COUNT
 };
 
 enum usb_pd_control_mux {
@@ -2568,14 +2612,284 @@ enum usb_pd_control_mux {
USB_PD_CTRL_MUX_DP = 3,
USB_PD_CTRL_MUX_DOCK = 4,
USB_PD_CTRL_MUX_AUTO = 5,
+   USB_PD_CTRL_MUX_COUNT
+};
+
+enum usb_pd_control_swap {
+   USB_PD_CTRL_SWAP_NONE = 0,
+   USB_PD_CTRL_SWAP_DATA = 1,
+   USB_PD_CTRL_SWAP_POWER = 2,
+   USB_PD_CTRL_SWAP_VCONN = 3,
+   USB_PD_CTRL_SWAP_COUNT
 };
 
 struct ec_params_usb_pd_control {
uint8_t port;
uint8_t role;
uint8_t mux;
+   uint8_t swap;
+} __packed;
+
+#define PD_CTRL_RESP_ENABLED_COMMS  (1 << 0) /* Communication enabled */
+#define PD_CTRL_RESP_ENABLED_CONNECTED  (1