platform/chrome: Add Type C connector class driver
cover platform/chrome: Add Type C connector class driver
The following series introduces a Type C port driver for Chrome OS devices that have an EC (Embedded Controller). It derives port information from ACPI or DT entries. This patch series adds basic support, including registering ports, and setting certain basic attributes.
I thought I’d send it out as an RFC to get some comments on whether the general approach is right. Subsequent iterations of the series will include adding port partner information as well as integration with mux agents. This might tie in with Heikki’s work here:
https://github.com/krohei/linux/commit/976378fbfe4a29b892d39ade07efce042640ff4c
Based on feedback, I can incorporate comments or adopt another approach altogether.
Prashant Malani (3):
platform/chrome: Add Type C connector class driver platform/chrome: typec: Get PD_CONTORL version platform/chrome: Update Type C port info from EC
drivers/platform/chrome/Kconfig | 11 + drivers/platform/chrome/Makefile | 1 + drivers/platform/chrome/cros_ec_typec.c | 319 ++++++++++++++++++++++++ 3 files changed, 331 insertions(+) create mode 100644 drivers/platform/chrome/cros_ec_typec.c
Signature · 1 line
2.25.0.341.g760bfbb309-goog
RFC 1/3 platform/chrome: Add Type C connector class driver
Add a the Type C connector class port driver for Chrome OS devices with an EC (Embedded Controllers).
The driver relies on firmware device specifications for various port attributes. On ACPI platforms, this is specified using the logical device with HID GOOG0014. On DT platforms, this is specified using the DT node with compatible string "google,cros-ec-typec".
This patch reads the device FW node and uses the port attributes to register the typec ports with the Type C connector class framework, but doesn't do much else.
Subsequent patches will add more functionality to the driver, including obtaining current port information (polarity, vconn role, current power role etc.) after querying the EC.
--- drivers/platform/chrome/Kconfig | 11 ++ drivers/platform/chrome/Makefile | 1 + drivers/platform/chrome/cros_ec_typec.c | 198 ++++++++++++++++++++++++ 3 files changed, 210 insertions(+) create mode 100644 drivers/platform/chrome/cros_ec_typec.c
drivers/platform/chrome/Kconfig +11 -0
@@ -214,6 +214,17 @@ config CROS_EC_SYSFS To compile this driver as a module, choose M here: the module will be called cros_ec_sysfs. +config CROS_EC_TYPEC + tristate "ChromeOS EC Type-C Connector Control" + depends on CROS_EC && TYPEC + default n + help + If you say Y here, you get support for accessing Type C connector + information from the Chrome OS EC. + + To compile this driver as a module, choose M here: the module will be + called cros_ec_typec. + config CROS_USBPD_LOGGER tristate "Logging driver for USB PD charger" depends on CHARGER_CROS_USBPD
drivers/platform/chrome/Makefile +1 -0
@@ -12,6 +12,7 @@ obj-$(CONFIG_CROS_EC_ISHTP) += cros_ec_ishtp.o obj-$(CONFIG_CROS_EC_RPMSG) += cros_ec_rpmsg.o obj-$(CONFIG_CROS_EC_SPI) += cros_ec_spi.o cros_ec_lpcs-objs := cros_ec_lpc.o cros_ec_lpc_mec.o +obj-$(CONFIG_CROS_EC_TYPEC) += cros_ec_typec.o obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpcs.o obj-$(CONFIG_CROS_EC_PROTO) += cros_ec_proto.o cros_ec_trace.o obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o
drivers/platform/chrome/cros_ec_typec.c new file +198 -0
198 lines not on this page · raw message
Signature · 1 line
2.25.0.341.g760bfbb309-goog
RFC 2/3 platform/chrome: typec: Get PD_CONTORL version
In reply to Prashant MalaniQuery the EC to determine the version number of the USB_PD_CONTROL command which is supported by the EC. Also store this value in the Type C data struct since it will be used to determine how to parse the response to queries for port information from the EC.
--- drivers/platform/chrome/cros_ec_typec.c | 35 ++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)
drivers/platform/chrome/cros_ec_typec.c +34 -1
@@ -22,6 +22,7 @@ struct cros_typec_data {struct device *dev;struct cros_ec_device *ec;int num_ports; +unsigned int cmd_ver;/* Array of ports, indexed by port number. */ struct typec_port *ports[EC_USB_PD_MAX_PORTS ]; };
@@ -137,6 +138,32 @@ static int cros_typec_get_num_ports(struct cros_typec_data *typec)return 0 ; } +static int cros_typec_get_cmd_version (struct cros_typec_data *typec) +{ +struct ec_params_get_cmd_versions_v1 req_v1; +struct ec_response_get_cmd_versions resp; +int ret; + +/* We're interested in the PD control command version. */ + req_v1.cmd =EC_CMD_USB_PD_CONTROL ; + ret =cros_ec_send_cmd_msg (typec->ec,1 ,EC_CMD_GET_CMD_VERSIONS , + &req_v1,sizeof (req_v1), &resp, +sizeof (resp)); +if (ret <0 ) { +return ret; + } + +if (resp.version_mask &EC_VER_MASK (1 )) + typec->cmd_ver =1 ; +else + typec->cmd_ver =0 ; + +dev_dbg (typec->dev,"PD Control has version mask 0x%hhx\n" , + typec->cmd_ver); + +return 0 ; +} +static int cros_typec_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -160,8 +187,14 @@ static int cros_typec_probe(struct platform_device *pdev)return -EOVERFLOW ; } + ret =cros_typec_get_cmd_version (typec); +if (ret <0 ) { +dev_err (dev,"failed to get PD command version info\n" ); +return ret; + } + ret =cros_typec_init_ports (typec); -if (!ret) +if (ret <0 )return ret;return 0 ;
Signature · 1 line
2.25.0.341.g760bfbb309-goog
RFC 3/3 platform/chrome: typec: Update port info from EC
In reply to Prashant MalaniAfter registering the ports at probe, get the current port information from EC and update the Type C connector class ports accordingly.
--- drivers/platform/chrome/cros_ec_typec.c | 90 ++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-)
drivers/platform/chrome/cros_ec_typec.c +89 -1
@@ -27,6 +27,82 @@ struct cros_typec_data {struct typec_port *ports[EC_USB_PD_MAX_PORTS ]; }; +static void cros_typec_set_port_params_v0 (struct cros_typec_data *typec, +int port_num,struct ec_response_usb_pd_control *resp) +{ +struct typec_port *port = typec->ports[port_num]; +enum typec_orientation polarity; + +if (!resp->enabled) + polarity =TYPEC_ORIENTATION_NONE ; +else if (!resp->polarity) + polarity =TYPEC_ORIENTATION_NORMAL ; +else + polarity =TYPEC_ORIENTATION_REVERSE ; + +typec_set_pwr_role (port, resp->role ?TYPEC_SOURCE :TYPEC_SINK ); +typec_set_orientation (port, polarity); +} + + +static void cros_typec_set_port_params_v1 (struct cros_typec_data *typec, +int port_num,struct ec_response_usb_pd_control_v1 *resp) +{ +struct typec_port *port = typec->ports[port_num]; +enum typec_orientation polarity; + +if (!(resp->enabled &PD_CTRL_RESP_ENABLED_CONNECTED )) + polarity =TYPEC_ORIENTATION_NONE ; +else if (!resp->polarity) + polarity =TYPEC_ORIENTATION_NORMAL ; +else + polarity =TYPEC_ORIENTATION_REVERSE ; +typec_set_orientation (port, polarity); +typec_set_data_role (port, resp->role &PD_CTRL_RESP_ROLE_DATA ? +TYPEC_HOST :TYPEC_DEVICE ); +typec_set_pwr_role (port, resp->role &PD_CTRL_RESP_ROLE_POWER ? +TYPEC_SOURCE :TYPEC_SINK ); +typec_set_vconn_role (port, resp->role &PD_CTRL_RESP_ROLE_VCONN ? +TYPEC_SOURCE :TYPEC_SINK ); +} + +static int cros_typec_port_update (struct cros_typec_data *typec,int port_num) +{ +struct ec_params_usb_pd_control req; +struct ec_response_usb_pd_control_v1 resp; +int ret; + +if (port_num <0 || port_num >= typec->num_ports) { +dev_err (typec->dev,"cannot get status for invalid port %d\n" , + port_num); +return -EINVAL ; + } + + req.port = port_num; + req.role =USB_PD_CTRL_ROLE_NO_CHANGE ; + req.mux =USB_PD_CTRL_MUX_NO_CHANGE ; + req.swap =USB_PD_CTRL_SWAP_NONE ; + + ret =cros_ec_send_cmd_msg (typec->ec, typec->cmd_ver, +EC_CMD_USB_PD_CONTROL , + &req,sizeof (req), &resp,sizeof (resp)); +if (ret <0 ) +return ret; + +dev_dbg (typec->dev,"Enabled %d: 0x%hhx\n" , port_num, resp.enabled); +dev_dbg (typec->dev,"Role %d: 0x%hhx\n" , port_num, resp.role); +dev_dbg (typec->dev,"Polarity %d: 0x%hhx\n" , port_num, resp.polarity); +dev_dbg (typec->dev,"State %d: %s\n" , port_num, resp.state); + +if (typec->cmd_ver ==1 ) +cros_typec_set_port_params_v1 (typec, port_num, &resp); +else +cros_typec_set_port_params_v0 (typec, port_num, + (struct ec_response_usb_pd_control *) &resp); + +return 0 ; +} +void cros_typec_parse_port_props (struct typec_capability *cap,const struct fwnode_handle *fwnode,struct device *dev)
@@ -168,7 +244,7 @@ static int cros_typec_probe(struct platform_device *pdev) {struct device *dev = &pdev->dev;struct cros_typec_data *typec; -int ret; +int ret, i; typec =devm_kzalloc (dev,sizeof (*typec),GFP_KERNEL );if (!typec)
@@ -197,7 +273,19 @@ static int cros_typec_probe(struct platform_device *pdev)if (ret <0 )return ret; +for (i =0 ; i < typec->num_ports; i++) { + ret =cros_typec_port_update (typec, i); +if (ret <0 ) + goto unregister_ports; + } +return 0 ; + +unregister_ports: +for (i =0 ; i < typec->num_ports; i++) +if (typec->ports[i]) +typec_unregister_port (typec->ports[i]); +return ret; }#ifdef CONFIG_ACPI
Signature · 1 line
2.25.0.341.g760bfbb309-goog