[08/10] platform/chrome: cros_ec_typec: Add initial VDM support
Commit Message
Add ops to support USB PD VDM (Vendor Defined Message) from the port
driver. This enables the port driver to interface with alternate mode
drivers and communicate with connected peripherals.
The initial support just contains an implementation of the Enter
Mode command.
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
---
MAINTAINERS | 1 +
drivers/platform/chrome/Makefile | 2 +-
drivers/platform/chrome/cros_ec_typec.c | 3 ++
drivers/platform/chrome/cros_typec_vdm.c | 43 ++++++++++++++++++++++++
drivers/platform/chrome/cros_typec_vdm.h | 10 ++++++
5 files changed, 58 insertions(+), 1 deletion(-)
create mode 100644 drivers/platform/chrome/cros_typec_vdm.c
create mode 100644 drivers/platform/chrome/cros_typec_vdm.h
Comments
On Wed, Dec 28, 2022 at 12:45:11AM +0000, Prashant Malani wrote:
> Add ops to support USB PD VDM (Vendor Defined Message) from the port
> driver. This enables the port driver to interface with alternate mode
> drivers and communicate with connected peripherals.
>
> The initial support just contains an implementation of the Enter
> Mode command.
>
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
> ---
> MAINTAINERS | 1 +
> drivers/platform/chrome/Makefile | 2 +-
> drivers/platform/chrome/cros_ec_typec.c | 3 ++
> drivers/platform/chrome/cros_typec_vdm.c | 43 ++++++++++++++++++++++++
> drivers/platform/chrome/cros_typec_vdm.h | 10 ++++++
> 5 files changed, 58 insertions(+), 1 deletion(-)
> create mode 100644 drivers/platform/chrome/cros_typec_vdm.c
> create mode 100644 drivers/platform/chrome/cros_typec_vdm.h
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 8219b646ab50..cfccbbbb083f 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -5000,6 +5000,7 @@ L: chrome-platform@lists.linux.dev
> S: Maintained
> F: drivers/platform/chrome/cros_ec_typec.*
> F: drivers/platform/chrome/cros_typec_switch.c
> +F: drivers/platform/chrome/cros_typec_vdm.*
>
> CHROMEOS EC USB PD NOTIFY DRIVER
> M: Prashant Malani <pmalani@chromium.org>
> diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile
> index fd29fa74ba33..dae0ed3c8656 100644
> --- a/drivers/platform/chrome/Makefile
> +++ b/drivers/platform/chrome/Makefile
> @@ -16,7 +16,7 @@ obj-$(CONFIG_CROS_TYPEC_SWITCH) += cros_typec_switch.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
> -cros-ec-typec-objs := cros_ec_typec.o
> +cros-ec-typec-objs := cros_ec_typec.o cros_typec_vdm.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
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index a4eff590ca56..1e28d56b094d 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -17,6 +17,7 @@
> #include <linux/usb/typec_tbt.h>
>
> #include "cros_ec_typec.h"
> +#include "cros_typec_vdm.h"
>
> #define DRV_NAME "cros-ec-typec"
>
> @@ -272,6 +273,7 @@ static int cros_typec_register_port_altmodes(struct cros_typec_data *typec,
> return PTR_ERR(amode);
> port->port_altmode[CROS_EC_ALTMODE_DP] = amode;
> typec_altmode_set_drvdata(amode, port);
> + amode->ops = &port_amode_ops;
>
> /*
> * Register TBT compatibility alt mode. The EC will not enter the mode
> @@ -286,6 +288,7 @@ static int cros_typec_register_port_altmodes(struct cros_typec_data *typec,
> return PTR_ERR(amode);
> port->port_altmode[CROS_EC_ALTMODE_TBT] = amode;
> typec_altmode_set_drvdata(amode, port);
> + amode->ops = &port_amode_ops;
>
> port->state.alt = NULL;
> port->state.mode = TYPEC_STATE_USB;
> diff --git a/drivers/platform/chrome/cros_typec_vdm.c b/drivers/platform/chrome/cros_typec_vdm.c
> new file mode 100644
> index 000000000000..df0102ca3a18
> --- /dev/null
> +++ b/drivers/platform/chrome/cros_typec_vdm.c
> @@ -0,0 +1,43 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * USB Power Delivery Vendor Defined Message (VDM) support code.
> + *
> + * Copyright 2023 Google LLC
> + * Author: Prashant Malani <pmalani@chromium.org>
> + */
> +
> +#include <linux/module.h>
> +#include <linux/platform_data/cros_ec_commands.h>
> +#include <linux/usb/pd_vdo.h>
> +
> +#include "cros_ec_typec.h"
> +#include "cros_typec_vdm.h"
> +
> +static int cros_typec_port_amode_enter(struct typec_altmode *amode, u32 *vdo)
> +{
> + struct cros_typec_port *port = typec_altmode_get_drvdata(amode);
> + struct ec_params_typec_control req = {
> + .port = port->port_num,
> + .command = TYPEC_CONTROL_COMMAND_SEND_VDM_REQ,
> + };
> + struct typec_vdm_req vdm_req = {};
> + u32 hdr;
> +
> + hdr = VDO(amode->svid, 1, SVDM_VER_2_0, CMD_ENTER_MODE);
> + hdr |= VDO_OPOS(amode->mode);
> +
> + vdm_req.vdm_data[0] = hdr;
> + vdm_req.vdm_data_objects = 1;
> + vdm_req.partner_type = TYPEC_PARTNER_SOP;
> + req.vdm_req_params = vdm_req;
> +
> + dev_dbg(port->typec_data->dev, "Sending EnterMode VDM, hdr: %x, port: %d\n",
> + hdr, port->port_num);
> +
> + return cros_ec_cmd(port->typec_data->ec, 0, EC_CMD_TYPEC_CONTROL, &req,
> + sizeof(req), NULL, 0);
> +}
> +
> +struct typec_altmode_ops port_amode_ops = {
> + .enter = cros_typec_port_amode_enter,
> +};
> diff --git a/drivers/platform/chrome/cros_typec_vdm.h b/drivers/platform/chrome/cros_typec_vdm.h
> new file mode 100644
> index 000000000000..7e282d168a98
> --- /dev/null
> +++ b/drivers/platform/chrome/cros_typec_vdm.h
> @@ -0,0 +1,10 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +
> +#ifndef __CROS_TYPEC_VDM__
> +#define __CROS_TYPEC_VDM__
> +
> +#include <linux/usb/typec_altmode.h>
> +
> +extern struct typec_altmode_ops port_amode_ops;
> +
> +#endif /* __CROS_TYPEC_VDM__ */
> --
> 2.39.0.314.g84b9a713c41-goog
>
>
@@ -5000,6 +5000,7 @@ L: chrome-platform@lists.linux.dev
S: Maintained
F: drivers/platform/chrome/cros_ec_typec.*
F: drivers/platform/chrome/cros_typec_switch.c
+F: drivers/platform/chrome/cros_typec_vdm.*
CHROMEOS EC USB PD NOTIFY DRIVER
M: Prashant Malani <pmalani@chromium.org>
@@ -16,7 +16,7 @@ obj-$(CONFIG_CROS_TYPEC_SWITCH) += cros_typec_switch.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
-cros-ec-typec-objs := cros_ec_typec.o
+cros-ec-typec-objs := cros_ec_typec.o cros_typec_vdm.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
@@ -17,6 +17,7 @@
#include <linux/usb/typec_tbt.h>
#include "cros_ec_typec.h"
+#include "cros_typec_vdm.h"
#define DRV_NAME "cros-ec-typec"
@@ -272,6 +273,7 @@ static int cros_typec_register_port_altmodes(struct cros_typec_data *typec,
return PTR_ERR(amode);
port->port_altmode[CROS_EC_ALTMODE_DP] = amode;
typec_altmode_set_drvdata(amode, port);
+ amode->ops = &port_amode_ops;
/*
* Register TBT compatibility alt mode. The EC will not enter the mode
@@ -286,6 +288,7 @@ static int cros_typec_register_port_altmodes(struct cros_typec_data *typec,
return PTR_ERR(amode);
port->port_altmode[CROS_EC_ALTMODE_TBT] = amode;
typec_altmode_set_drvdata(amode, port);
+ amode->ops = &port_amode_ops;
port->state.alt = NULL;
port->state.mode = TYPEC_STATE_USB;
new file mode 100644
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * USB Power Delivery Vendor Defined Message (VDM) support code.
+ *
+ * Copyright 2023 Google LLC
+ * Author: Prashant Malani <pmalani@chromium.org>
+ */
+
+#include <linux/module.h>
+#include <linux/platform_data/cros_ec_commands.h>
+#include <linux/usb/pd_vdo.h>
+
+#include "cros_ec_typec.h"
+#include "cros_typec_vdm.h"
+
+static int cros_typec_port_amode_enter(struct typec_altmode *amode, u32 *vdo)
+{
+ struct cros_typec_port *port = typec_altmode_get_drvdata(amode);
+ struct ec_params_typec_control req = {
+ .port = port->port_num,
+ .command = TYPEC_CONTROL_COMMAND_SEND_VDM_REQ,
+ };
+ struct typec_vdm_req vdm_req = {};
+ u32 hdr;
+
+ hdr = VDO(amode->svid, 1, SVDM_VER_2_0, CMD_ENTER_MODE);
+ hdr |= VDO_OPOS(amode->mode);
+
+ vdm_req.vdm_data[0] = hdr;
+ vdm_req.vdm_data_objects = 1;
+ vdm_req.partner_type = TYPEC_PARTNER_SOP;
+ req.vdm_req_params = vdm_req;
+
+ dev_dbg(port->typec_data->dev, "Sending EnterMode VDM, hdr: %x, port: %d\n",
+ hdr, port->port_num);
+
+ return cros_ec_cmd(port->typec_data->ec, 0, EC_CMD_TYPEC_CONTROL, &req,
+ sizeof(req), NULL, 0);
+}
+
+struct typec_altmode_ops port_amode_ops = {
+ .enter = cros_typec_port_amode_enter,
+};
new file mode 100644
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __CROS_TYPEC_VDM__
+#define __CROS_TYPEC_VDM__
+
+#include <linux/usb/typec_altmode.h>
+
+extern struct typec_altmode_ops port_amode_ops;
+
+#endif /* __CROS_TYPEC_VDM__ */