Received: by 10.223.148.5 with SMTP id 5csp6147700wrq; Wed, 17 Jan 2018 10:01:36 -0800 (PST) X-Google-Smtp-Source: ACJfBovN5Fjj7OEb6Xe9rvpwv31cHiFWPKv8NjmYTVMI/IY2SV7jSDf5kjkYbRQ2bQNPBA1SPXwj X-Received: by 10.98.138.21 with SMTP id y21mr10572186pfd.147.1516212096098; Wed, 17 Jan 2018 10:01:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516212096; cv=none; d=google.com; s=arc-20160816; b=ZzGLLo1sjTreec0338XAGXJRBjmJoSZv1fyVbwhtzvx8GusdawBxc/7ZwMy3o67kse TCgo6Vpv5xXkPWuSwKn/1QDyj2JDUaDfcpV93XGQhBxQpES035nvL2rLHhzsaDFG0Rvx oBeVN+7W5KXU4fqmVCPu0aTJK0ukwJxLwowr3I5VBznPzOBEombeLK1exOJWSiVMnULG fw9/SW3CIL3NOBxkCqrXvt3rob5/xXiC/6QXOEJiHL0v6ETP2hEmwdwtsZ6dGoFyUqCx Ch3pgCJPwwSRmXcGNXYrJb/LgGS7gBm6o6wzlucIo0/BtQYnWc7a7WipLcnSpg574p1+ gSvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Xb6T+qSHm6TbbCNFfX3ulh9cJyHBJocOxpy8rbmJ83s=; b=lwhpjwURK15iSnWbotQuVLxFxY0yxZSLitO6IkYO69fq+g894LVqMP+3H6qfiaUzf/ efBeAduE5yk3GgqWfPKG1Fr1E9VtAKHlOUu5Zm1ChZMcqKbmKs5YX2BSVk3qe6p/fD9x ThfjJ6FewqKVHBMG+HtMYuleEN0RzLWXWj35RxYv2eyWaaxdtGdATFRzuI2OAWNl/+9G M/mg0u06lThu0TSLqUpj7/O1niywA6NAF62dxzknKPaCjKWdSSX/7YU/tWc6YSf8EI+u QwJncE6w/y0mV8JQfL+/l8jL6FsajH2ccL/i9XELTaugsCdhW7fBJYHmobVP6g2hEr5q CoXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v11si4952787plz.285.2018.01.17.10.01.17; Wed, 17 Jan 2018 10:01:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932082AbeAQSAX (ORCPT + 99 others); Wed, 17 Jan 2018 13:00:23 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:39972 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753843AbeAQR7m (ORCPT ); Wed, 17 Jan 2018 12:59:42 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 4BA972726C0 From: Enric Balletbo i Serra To: Lee Jones , Sebastian Reichel Cc: Gwendal Grignou , Benson Leung , Guenter Roeck , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Sameer Nanda Subject: [PATCH 1/3] mfd: cros_ec: Add USBPD charger commands and struct definitions. Date: Wed, 17 Jan 2018 18:59:30 +0100 Message-Id: <20180117175932.20636-2-enric.balletbo@collabora.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180117175932.20636-1-enric.balletbo@collabora.com> References: <20180117175932.20636-1-enric.balletbo@collabora.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sameer Nanda The USB PD charger driver gets information from the ChromeOS EC, this patch adds the USBPD charger definitions needed by this driver. Signed-off-by: Sameer Nanda Signed-off-by: Enric Balletbo i Serra --- include/linux/mfd/cros_ec_commands.h | 135 +++++++++++++++++++++++++++++++++-- 1 file changed, 131 insertions(+), 4 deletions(-) diff --git a/include/linux/mfd/cros_ec_commands.h b/include/linux/mfd/cros_ec_commands.h index 2b96e630e3b6..94dcf331796c 100644 --- a/include/linux/mfd/cros_ec_commands.h +++ b/include/linux/mfd/cros_ec_commands.h @@ -2593,14 +2593,18 @@ struct ec_params_current_limit { } __packed; /* - * Set maximum external power current. + * Set maximum external voltage / current. */ -#define EC_CMD_EXT_POWER_CURRENT_LIMIT 0xa2 +#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2 -struct ec_params_ext_power_current_limit { - uint32_t limit; /* in mA */ +/* Command v0 is used only on Spring and is obsolete + unsupported */ +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 0xffff + /* Inform the EC when entering a sleep state */ #define EC_CMD_HOST_SLEEP_EVENT 0xa9 @@ -2948,6 +2952,9 @@ struct ec_response_usb_pd_control_v1 { #define EC_CMD_USB_PD_PORTS 0x102 +/* Maximum number of PD ports on a device, num_ports will be <= this */ +#define EC_USB_PD_MAX_PORTS 8 + struct ec_response_usb_pd_ports { uint8_t num_ports; } __packed; @@ -2971,6 +2978,12 @@ enum usb_chg_type { USB_CHG_TYPE_VBUS, USB_CHG_TYPE_UNKNOWN, }; +enum usb_power_roles { + USB_PD_PORT_POWER_DISCONNECTED, + USB_PD_PORT_POWER_SOURCE, + USB_PD_PORT_POWER_SINK, + USB_PD_PORT_POWER_SINK_NOT_CHARGING, +}; struct usb_chg_measures { uint16_t voltage_max; @@ -2988,6 +3001,120 @@ struct ec_response_usb_pd_power_info { uint32_t max_power; } __packed; +struct ec_params_usb_pd_info_request { + uint8_t port; +} __packed; + +/* Read USB-PD Device discovery info */ +#define EC_CMD_USB_PD_DISCOVERY 0x0113 +struct ec_params_usb_pd_discovery_entry { + uint16_t vid; /* USB-IF VID */ + uint16_t pid; /* USB-IF PID */ + uint8_t ptype; /* product type (hub,periph,cable,ama) */ +} __packed; + +/* Override default charge behavior */ +#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114 + +/* Negative port parameters have special meaning */ +enum usb_pd_override_ports { + OVERRIDE_DONT_CHARGE = -2, + OVERRIDE_OFF = -1, + /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */ +}; + +struct ec_params_charge_port_override { + int16_t override_port; /* Override port# */ +} __packed; + +/* Read (and delete) one entry of PD event log */ +#define EC_CMD_PD_GET_LOG_ENTRY 0x0115 + +struct ec_response_pd_log { + uint32_t timestamp; /* relative timestamp in milliseconds */ + uint8_t type; /* event type : see PD_EVENT_xx below */ + uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */ + uint16_t data; /* type-defined data payload */ + uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */ +} __packed; + +/* The timestamp is the microsecond counter shifted to get about a ms. */ +#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */ + +#define PD_LOG_SIZE_MASK 0x1f +#define PD_LOG_PORT_MASK 0xe0 +#define PD_LOG_PORT_SHIFT 5 +#define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \ + ((size) & PD_LOG_SIZE_MASK)) +#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT) +#define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK) + +/* PD event log : entry types */ +/* PD MCU events */ +#define PD_EVENT_MCU_BASE 0x00 +#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0) +#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1) +/* Reserved for custom board event */ +#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2) +/* PD generic accessory events */ +#define PD_EVENT_ACC_BASE 0x20 +#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0) +#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1) +/* PD power supply events */ +#define PD_EVENT_PS_BASE 0x40 +#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0) +/* PD video dongles events */ +#define PD_EVENT_VIDEO_BASE 0x60 +#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0) +#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1) +/* Returned in the "type" field, when there is no entry available */ +#define PD_EVENT_NO_ENTRY 0xff + +/* + * PD_EVENT_MCU_CHARGE event definition : + * the payload is "struct usb_chg_measures" + * the data field contains the port state flags as defined below : + */ +/* Port partner is a dual role device */ +#define CHARGE_FLAGS_DUAL_ROLE (1 << 15) +/* Port is the pending override port */ +#define CHARGE_FLAGS_DELAYED_OVERRIDE (1 << 14) +/* Port is the override port */ +#define CHARGE_FLAGS_OVERRIDE (1 << 13) +/* Charger type */ +#define CHARGE_FLAGS_TYPE_SHIFT 3 +#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT) +/* Power delivery role */ +#define CHARGE_FLAGS_ROLE_MASK (7 << 0) + +/* + * PD_EVENT_PS_FAULT data field flags definition : + */ +#define PS_FAULT_OCP 1 +#define PS_FAULT_FAST_OCP 2 +#define PS_FAULT_OVP 3 +#define PS_FAULT_DISCH 4 + +/* + * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info". + */ +struct mcdp_version { + uint8_t major; + uint8_t minor; + uint16_t build; +} __packed; + +struct mcdp_info { + uint8_t family[2]; + uint8_t chipid[2]; + struct mcdp_version irom; + struct mcdp_version fw; +} __packed; + +/* struct mcdp_info field decoding */ +#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1]) +#define MCDP_FAMILY(family) ((family[0] << 8) | family[1]) + /* Get info about USB-C SS muxes */ #define EC_CMD_USB_PD_MUX_INFO 0x11a -- 2.15.1