aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2019-06-03 14:33:50 -0400
committerLee Jones <lee.jones@linaro.org>2019-06-10 04:15:08 -0400
commite16efdf12105d921b44b78a0012acf2487f3245b (patch)
tree4d9cda2bdc312ef23dbcd705f5ecbe205c5b968c /include/linux
parent170309b438a3826b09401a84f3de911db5b627a7 (diff)
mfd: cros_ec: Complete Power and USB PD API
Improve API for USB Powe delivery and power management. Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com> Acked-by: Benson Leung <bleung@chromium.org> Reviewed-by: Fabien Lahoudere <fabien.lahoudere@collabora.com> Signed-off-by: Lee Jones <lee.jones@linaro.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/mfd/cros_ec_commands.h236
1 files changed, 228 insertions, 8 deletions
diff --git a/include/linux/mfd/cros_ec_commands.h b/include/linux/mfd/cros_ec_commands.h
index 9a84aad7475a..e05cdcb12481 100644
--- a/include/linux/mfd/cros_ec_commands.h
+++ b/include/linux/mfd/cros_ec_commands.h
@@ -2796,7 +2796,8 @@ struct ec_params_config_power_button {
2796 2796
2797struct ec_params_usb_charge_set_mode { 2797struct ec_params_usb_charge_set_mode {
2798 uint8_t usb_port_id; 2798 uint8_t usb_port_id;
2799 uint8_t mode; 2799 uint8_t mode:7;
2800 uint8_t inhibit_charge:1;
2800} __ec_align1; 2801} __ec_align1;
2801 2802
2802/*****************************************************************************/ 2803/*****************************************************************************/
@@ -3933,6 +3934,11 @@ enum charge_state_params {
3933 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */ 3934 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
3934 CS_PARAM_CHG_STATUS, /* charger-specific status */ 3935 CS_PARAM_CHG_STATUS, /* charger-specific status */
3935 CS_PARAM_CHG_OPTION, /* charger-specific options */ 3936 CS_PARAM_CHG_OPTION, /* charger-specific options */
3937 CS_PARAM_LIMIT_POWER, /*
3938 * Check if power is limited due to
3939 * low battery and / or a weak external
3940 * charger. READ ONLY.
3941 */
3936 /* How many so far? */ 3942 /* How many so far? */
3937 CS_NUM_BASE_PARAMS, 3943 CS_NUM_BASE_PARAMS,
3938 3944
@@ -3940,6 +3946,17 @@ enum charge_state_params {
3940 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000, 3946 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
3941 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff, 3947 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
3942 3948
3949 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
3950 CS_PARAM_DEBUG_MIN = 0x20000,
3951 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
3952 CS_PARAM_DEBUG_MANUAL_MODE,
3953 CS_PARAM_DEBUG_SEEMS_DEAD,
3954 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
3955 CS_PARAM_DEBUG_BATT_REMOVED,
3956 CS_PARAM_DEBUG_MANUAL_CURRENT,
3957 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
3958 CS_PARAM_DEBUG_MAX = 0x2ffff,
3959
3943 /* Other custom param ranges go here... */ 3960 /* Other custom param ranges go here... */
3944}; 3961};
3945 3962
@@ -4000,6 +4017,16 @@ struct ec_params_external_power_limit_v1 {
4000 4017
4001#define EC_POWER_LIMIT_NONE 0xffff 4018#define EC_POWER_LIMIT_NONE 0xffff
4002 4019
4020/*
4021 * Set maximum voltage & current of a dedicated charge port
4022 */
4023#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
4024
4025struct ec_params_dedicated_charger_limit {
4026 uint16_t current_lim; /* in mA */
4027 uint16_t voltage_lim; /* in mV */
4028} __ec_align2;
4029
4003/* Inform the EC when entering a sleep state */ 4030/* Inform the EC when entering a sleep state */
4004#define EC_CMD_HOST_SLEEP_EVENT 0x00A9 4031#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
4005 4032
@@ -4385,18 +4412,53 @@ struct ec_params_reboot_ec {
4385 4412
4386/* EC to PD MCU exchange status command */ 4413/* EC to PD MCU exchange status command */
4387#define EC_CMD_PD_EXCHANGE_STATUS 0x0100 4414#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
4415#define EC_VER_PD_EXCHANGE_STATUS 2
4416
4417enum pd_charge_state {
4418 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
4419 PD_CHARGE_NONE, /* No charging allowed */
4420 PD_CHARGE_5V, /* 5V charging only */
4421 PD_CHARGE_MAX /* Charge at max voltage */
4422};
4388 4423
4389/* Status of EC being sent to PD */ 4424/* Status of EC being sent to PD */
4425#define EC_STATUS_HIBERNATING BIT(0)
4426
4390struct ec_params_pd_status { 4427struct ec_params_pd_status {
4391 int8_t batt_soc; /* battery state of charge */ 4428 uint8_t status; /* EC status */
4429 int8_t batt_soc; /* battery state of charge */
4430 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
4392} __ec_align1; 4431} __ec_align1;
4393 4432
4394/* Status of PD being sent back to EC */ 4433/* Status of PD being sent back to EC */
4434#define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */
4435#define PD_STATUS_IN_RW BIT(1) /* Running RW image */
4436#define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */
4437#define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */
4438#define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */
4439#define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */
4440#define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */
4441#define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
4442 PD_STATUS_TCPC_ALERT_1 | \
4443 PD_STATUS_HOST_EVENT)
4395struct ec_response_pd_status { 4444struct ec_response_pd_status {
4396 int8_t status; /* PD MCU status */ 4445 uint32_t curr_lim_ma; /* input current limit */
4397 uint32_t curr_lim_ma; /* input current limit */ 4446 uint16_t status; /* PD MCU status */
4447 int8_t active_charge_port; /* active charging port */
4398} __ec_align_size1; 4448} __ec_align_size1;
4399 4449
4450/* AP to PD MCU host event status command, cleared on read */
4451#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
4452
4453/* PD MCU host event status bits */
4454#define PD_EVENT_UPDATE_DEVICE BIT(0)
4455#define PD_EVENT_POWER_CHANGE BIT(1)
4456#define PD_EVENT_IDENTITY_RECEIVED BIT(2)
4457#define PD_EVENT_DATA_SWAP BIT(3)
4458struct ec_response_host_event_status {
4459 uint32_t status; /* PD MCU host event status */
4460} __ec_align4;
4461
4400/* Set USB type-C port role and muxes */ 4462/* Set USB type-C port role and muxes */
4401#define EC_CMD_USB_PD_CONTROL 0x0101 4463#define EC_CMD_USB_PD_CONTROL 0x0101
4402 4464
@@ -4406,6 +4468,8 @@ enum usb_pd_control_role {
4406 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2, 4468 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
4407 USB_PD_CTRL_ROLE_FORCE_SINK = 3, 4469 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
4408 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4, 4470 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
4471 USB_PD_CTRL_ROLE_FREEZE = 5,
4472 USB_PD_CTRL_ROLE_COUNT
4409}; 4473};
4410 4474
4411enum usb_pd_control_mux { 4475enum usb_pd_control_mux {
@@ -4415,6 +4479,7 @@ enum usb_pd_control_mux {
4415 USB_PD_CTRL_MUX_DP = 3, 4479 USB_PD_CTRL_MUX_DP = 3,
4416 USB_PD_CTRL_MUX_DOCK = 4, 4480 USB_PD_CTRL_MUX_DOCK = 4,
4417 USB_PD_CTRL_MUX_AUTO = 5, 4481 USB_PD_CTRL_MUX_AUTO = 5,
4482 USB_PD_CTRL_MUX_COUNT
4418}; 4483};
4419 4484
4420enum usb_pd_control_swap { 4485enum usb_pd_control_swap {
@@ -4444,6 +4509,13 @@ struct ec_params_usb_pd_control {
4444#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */ 4509#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
4445#define PD_CTRL_RESP_ROLE_EXT_POWERED BIT(6) /* Partner externally powerd */ 4510#define PD_CTRL_RESP_ROLE_EXT_POWERED BIT(6) /* Partner externally powerd */
4446 4511
4512struct ec_response_usb_pd_control {
4513 uint8_t enabled;
4514 uint8_t role;
4515 uint8_t polarity;
4516 uint8_t state;
4517} __ec_align1;
4518
4447struct ec_response_usb_pd_control_v1 { 4519struct ec_response_usb_pd_control_v1 {
4448 uint8_t enabled; 4520 uint8_t enabled;
4449 uint8_t role; 4521 uint8_t role;
@@ -4451,6 +4523,25 @@ struct ec_response_usb_pd_control_v1 {
4451 char state[32]; 4523 char state[32];
4452} __ec_align1; 4524} __ec_align1;
4453 4525
4526/* Values representing usbc PD CC state */
4527#define USBC_PD_CC_NONE 0 /* No accessory connected */
4528#define USBC_PD_CC_NO_UFP 1 /* No UFP accessory connected */
4529#define USBC_PD_CC_AUDIO_ACC 2 /* Audio accessory connected */
4530#define USBC_PD_CC_DEBUG_ACC 3 /* Debug accessory connected */
4531#define USBC_PD_CC_UFP_ATTACHED 4 /* UFP attached to usbc */
4532#define USBC_PD_CC_DFP_ATTACHED 5 /* DPF attached to usbc */
4533
4534struct ec_response_usb_pd_control_v2 {
4535 uint8_t enabled;
4536 uint8_t role;
4537 uint8_t polarity;
4538 char state[32];
4539 uint8_t cc_state; /* USBC_PD_CC_*Encoded cc state */
4540 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
4541 /* CL:1500994 Current cable type */
4542 uint8_t reserved_cable_type;
4543} __ec_align1;
4544
4454#define EC_CMD_USB_PD_PORTS 0x0102 4545#define EC_CMD_USB_PD_PORTS 0x0102
4455 4546
4456/* Maximum number of PD ports on a device, num_ports will be <= this */ 4547/* Maximum number of PD ports on a device, num_ports will be <= this */
@@ -4478,6 +4569,7 @@ enum usb_chg_type {
4478 USB_CHG_TYPE_OTHER, 4569 USB_CHG_TYPE_OTHER,
4479 USB_CHG_TYPE_VBUS, 4570 USB_CHG_TYPE_VBUS,
4480 USB_CHG_TYPE_UNKNOWN, 4571 USB_CHG_TYPE_UNKNOWN,
4572 USB_CHG_TYPE_DEDICATED,
4481}; 4573};
4482enum usb_power_roles { 4574enum usb_power_roles {
4483 USB_PD_PORT_POWER_DISCONNECTED, 4575 USB_PD_PORT_POWER_DISCONNECTED,
@@ -4502,9 +4594,6 @@ struct ec_response_usb_pd_power_info {
4502 uint32_t max_power; 4594 uint32_t max_power;
4503} __ec_align4; 4595} __ec_align4;
4504 4596
4505struct ec_params_usb_pd_info_request {
4506 uint8_t port;
4507} __ec_align1;
4508 4597
4509/* 4598/*
4510 * This command will return the number of USB PD charge port + the number 4599 * This command will return the number of USB PD charge port + the number
@@ -4516,6 +4605,46 @@ struct ec_response_charge_port_count {
4516 uint8_t port_count; 4605 uint8_t port_count;
4517} __ec_align1; 4606} __ec_align1;
4518 4607
4608/* Write USB-PD device FW */
4609#define EC_CMD_USB_PD_FW_UPDATE 0x0110
4610
4611enum usb_pd_fw_update_cmds {
4612 USB_PD_FW_REBOOT,
4613 USB_PD_FW_FLASH_ERASE,
4614 USB_PD_FW_FLASH_WRITE,
4615 USB_PD_FW_ERASE_SIG,
4616};
4617
4618struct ec_params_usb_pd_fw_update {
4619 uint16_t dev_id;
4620 uint8_t cmd;
4621 uint8_t port;
4622 uint32_t size; /* Size to write in bytes */
4623 /* Followed by data to write */
4624} __ec_align4;
4625
4626/* Write USB-PD Accessory RW_HASH table entry */
4627#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
4628/* RW hash is first 20 bytes of SHA-256 of RW section */
4629#define PD_RW_HASH_SIZE 20
4630struct ec_params_usb_pd_rw_hash_entry {
4631 uint16_t dev_id;
4632 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
4633 uint8_t reserved; /*
4634 * For alignment of current_image
4635 * TODO(rspangler) but it's not aligned!
4636 * Should have been reserved[2].
4637 */
4638 uint32_t current_image; /* One of ec_current_image */
4639} __ec_align1;
4640
4641/* Read USB-PD Accessory info */
4642#define EC_CMD_USB_PD_DEV_INFO 0x0112
4643
4644struct ec_params_usb_pd_info_request {
4645 uint8_t port;
4646} __ec_align1;
4647
4519/* Read USB-PD Device discovery info */ 4648/* Read USB-PD Device discovery info */
4520#define EC_CMD_USB_PD_DISCOVERY 0x0113 4649#define EC_CMD_USB_PD_DISCOVERY 0x0113
4521struct ec_params_usb_pd_discovery_entry { 4650struct ec_params_usb_pd_discovery_entry {
@@ -4538,7 +4667,11 @@ struct ec_params_charge_port_override {
4538 int16_t override_port; /* Override port# */ 4667 int16_t override_port; /* Override port# */
4539} __ec_align2; 4668} __ec_align2;
4540 4669
4541/* Read (and delete) one entry of PD event log */ 4670/*
4671 * Read (and delete) one entry of PD event log.
4672 * TODO(crbug.com/751742): Make this host command more generic to accommodate
4673 * future non-PD logs that use the same internal EC event_log.
4674 */
4542#define EC_CMD_PD_GET_LOG_ENTRY 0x0115 4675#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
4543 4676
4544struct ec_response_pd_log { 4677struct ec_response_pd_log {
@@ -4626,6 +4759,60 @@ struct mcdp_info {
4626#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1]) 4759#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
4627#define MCDP_FAMILY(family) ((family[0] << 8) | family[1]) 4760#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
4628 4761
4762/* Get/Set USB-PD Alternate mode info */
4763#define EC_CMD_USB_PD_GET_AMODE 0x0116
4764struct ec_params_usb_pd_get_mode_request {
4765 uint16_t svid_idx; /* SVID index to get */
4766 uint8_t port; /* port */
4767} __ec_align_size1;
4768
4769struct ec_params_usb_pd_get_mode_response {
4770 uint16_t svid; /* SVID */
4771 uint16_t opos; /* Object Position */
4772 uint32_t vdo[6]; /* Mode VDOs */
4773} __ec_align4;
4774
4775#define EC_CMD_USB_PD_SET_AMODE 0x0117
4776
4777enum pd_mode_cmd {
4778 PD_EXIT_MODE = 0,
4779 PD_ENTER_MODE = 1,
4780 /* Not a command. Do NOT remove. */
4781 PD_MODE_CMD_COUNT,
4782};
4783
4784struct ec_params_usb_pd_set_mode_request {
4785 uint32_t cmd; /* enum pd_mode_cmd */
4786 uint16_t svid; /* SVID to set */
4787 uint8_t opos; /* Object Position */
4788 uint8_t port; /* port */
4789} __ec_align4;
4790
4791/* Ask the PD MCU to record a log of a requested type */
4792#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
4793
4794struct ec_params_pd_write_log_entry {
4795 uint8_t type; /* event type : see PD_EVENT_xx above */
4796 uint8_t port; /* port#, or 0 for events unrelated to a given port */
4797} __ec_align1;
4798
4799
4800/* Control USB-PD chip */
4801#define EC_CMD_PD_CONTROL 0x0119
4802
4803enum ec_pd_control_cmd {
4804 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
4805 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
4806 PD_RESET, /* Force reset the PD chip */
4807 PD_CONTROL_DISABLE, /* Disable further calls to this command */
4808 PD_CHIP_ON, /* Power on the PD chip */
4809};
4810
4811struct ec_params_pd_control {
4812 uint8_t chip; /* chip id */
4813 uint8_t subcmd;
4814} __ec_align1;
4815
4629/* Get info about USB-C SS muxes */ 4816/* Get info about USB-C SS muxes */
4630#define EC_CMD_USB_PD_MUX_INFO 0x011A 4817#define EC_CMD_USB_PD_MUX_INFO 0x011A
4631 4818
@@ -4638,10 +4825,43 @@ struct ec_params_usb_pd_mux_info {
4638#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */ 4825#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
4639#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */ 4826#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
4640#define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */ 4827#define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
4828#define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
4641 4829
4642struct ec_response_usb_pd_mux_info { 4830struct ec_response_usb_pd_mux_info {
4643 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */ 4831 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
4644} __ec_align1; 4832} __ec_align1;
4833
4834#define EC_CMD_PD_CHIP_INFO 0x011B
4835
4836struct ec_params_pd_chip_info {
4837 uint8_t port; /* USB-C port number */
4838 uint8_t renew; /* Force renewal */
4839} __ec_align1;
4840
4841struct ec_response_pd_chip_info {
4842 uint16_t vendor_id;
4843 uint16_t product_id;
4844 uint16_t device_id;
4845 union {
4846 uint8_t fw_version_string[8];
4847 uint64_t fw_version_number;
4848 };
4849} __ec_align2;
4850
4851struct ec_response_pd_chip_info_v1 {
4852 uint16_t vendor_id;
4853 uint16_t product_id;
4854 uint16_t device_id;
4855 union {
4856 uint8_t fw_version_string[8];
4857 uint64_t fw_version_number;
4858 };
4859 union {
4860 uint8_t min_req_fw_version_string[8];
4861 uint64_t min_req_fw_version_number;
4862 };
4863} __ec_align2;
4864
4645/*****************************************************************************/ 4865/*****************************************************************************/
4646/* 4866/*
4647 * Reserve a range of host commands for board-specific, experimental, or 4867 * Reserve a range of host commands for board-specific, experimental, or