Commit ad74b864 authored by Heikki Krogerus's avatar Heikki Krogerus Committed by Greg Kroah-Hartman

usb: typec: ucsi: Preliminary support for alternate modes

With UCSI the alternate modes, just like everything else
related to USB Type-C connectors, are handled in firmware.
The operating system can see the status and is allowed to
request certain things, for example entering and exiting the
modes, but the support for alternate modes is very limited
in UCSI. The feature is also optional, which means that even
when the platform supports alternate modes, the operating
system may not be even made aware of them.

UCSI does not support direct VDM reading or writing.
Instead, alternate modes can be entered and exited using a
single custom command which takes also an optional SVID
specific configuration value as parameter. That means every
supported alternate mode has to be handled separately in
UCSI driver.

This commit does not include support for any specific
alternate mode. The discovered alternate modes are now
registered, but binding a driver to an alternate mode will
not be possible until support for that alternate mode is
added to the UCSI driver.
Tested-by: default avatarAjay Gupta <ajayg@nvidia.com>
Signed-off-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 5c9ae5a8
......@@ -60,3 +60,15 @@ const char *ucsi_cci_str(u32 cci)
return "";
}
static const char * const ucsi_recipient_strs[] = {
[UCSI_RECIPIENT_CON] = "port",
[UCSI_RECIPIENT_SOP] = "partner",
[UCSI_RECIPIENT_SOP_P] = "plug (prime)",
[UCSI_RECIPIENT_SOP_PP] = "plug (double prime)",
};
const char *ucsi_recipient_str(u8 recipient)
{
return ucsi_recipient_strs[recipient];
}
......@@ -7,6 +7,7 @@
#define __UCSI_TRACE_H
#include <linux/tracepoint.h>
#include <linux/usb/typec_altmode.h>
const char *ucsi_cmd_str(u64 raw_cmd);
const char *ucsi_ack_str(u8 ack);
......@@ -134,6 +135,31 @@ DEFINE_EVENT(ucsi_log_connector_status, ucsi_register_port,
TP_ARGS(port, status)
);
DECLARE_EVENT_CLASS(ucsi_log_register_altmode,
TP_PROTO(u8 recipient, struct typec_altmode *alt),
TP_ARGS(recipient, alt),
TP_STRUCT__entry(
__field(u8, recipient)
__field(u16, svid)
__field(u8, mode)
__field(u32, vdo)
),
TP_fast_assign(
__entry->recipient = recipient;
__entry->svid = alt->svid;
__entry->mode = alt->mode;
__entry->vdo = alt->vdo;
),
TP_printk("%s alt mode: svid %04x, mode %d vdo %x",
ucsi_recipient_str(__entry->recipient), __entry->svid,
__entry->mode, __entry->vdo)
);
DEFINE_EVENT(ucsi_log_register_altmode, ucsi_register_altmode,
TP_PROTO(u8 recipient, struct typec_altmode *alt),
TP_ARGS(recipient, alt)
);
#endif /* __UCSI_TRACE_H */
/* This part must be outside protection */
......
This diff is collapsed.
......@@ -6,6 +6,7 @@
#include <linux/bitops.h>
#include <linux/device.h>
#include <linux/types.h>
#include <linux/usb/typec.h>
/* -------------------------------------------------------------------------- */
......@@ -60,6 +61,20 @@ struct ucsi_uor_cmd {
u16:6; /* reserved */
} __packed;
/* Get Alternate Modes Command structure */
struct ucsi_altmode_cmd {
u8 cmd;
u8 length;
u8 recipient;
#define UCSI_RECIPIENT_CON 0
#define UCSI_RECIPIENT_SOP 1
#define UCSI_RECIPIENT_SOP_P 2
#define UCSI_RECIPIENT_SOP_PP 3
u8 con_num;
u8 offset;
u8 num_altmodes;
} __packed;
struct ucsi_control {
union {
u64 raw_cmd;
......@@ -67,6 +82,7 @@ struct ucsi_control {
struct ucsi_uor_cmd uor;
struct ucsi_ack_cmd ack;
struct ucsi_con_rst con_rst;
struct ucsi_altmode_cmd alt;
};
};
......@@ -112,6 +128,30 @@ struct ucsi_control {
(_ctrl_).cmd.data = _con_; \
}
/* Helper for preparing ucsi_control for GET_ALTERNATE_MODES command. */
#define UCSI_CMD_GET_ALTERNATE_MODES(_ctrl_, _r_, _con_num_, _o_, _num_)\
{ \
__UCSI_CMD((_ctrl_), UCSI_GET_ALTERNATE_MODES) \
_ctrl_.alt.recipient = (_r_); \
_ctrl_.alt.con_num = (_con_num_); \
_ctrl_.alt.offset = (_o_); \
_ctrl_.alt.num_altmodes = (_num_) - 1; \
}
/* Helper for preparing ucsi_control for GET_CAM_SUPPORTED command. */
#define UCSI_CMD_GET_CAM_SUPPORTED(_ctrl_, _con_) \
{ \
__UCSI_CMD((_ctrl_), UCSI_GET_CAM_SUPPORTED) \
_ctrl_.cmd.data = (_con_); \
}
/* Helper for preparing ucsi_control for GET_CAM_SUPPORTED command. */
#define UCSI_CMD_GET_CURRENT_CAM(_ctrl_, _con_) \
{ \
__UCSI_CMD((_ctrl_), UCSI_GET_CURRENT_CAM) \
_ctrl_.cmd.data = (_con_); \
}
/* Helper for preparing ucsi_control for GET_CONNECTOR_STATUS command. */
#define UCSI_CMD_GET_CONNECTOR_STATUS(_ctrl_, _con_) \
{ \
......@@ -334,4 +374,61 @@ struct ucsi *ucsi_register_ppm(struct device *dev, struct ucsi_ppm *ppm);
void ucsi_unregister_ppm(struct ucsi *ucsi);
void ucsi_notify(struct ucsi *ucsi);
/* -------------------------------------------------------------------------- */
enum ucsi_status {
UCSI_IDLE = 0,
UCSI_BUSY,
UCSI_ERROR,
};
struct ucsi {
struct device *dev;
struct ucsi_ppm *ppm;
enum ucsi_status status;
struct completion complete;
struct ucsi_capability cap;
struct ucsi_connector *connector;
struct work_struct work;
/* PPM Communication lock */
struct mutex ppm_lock;
/* PPM communication flags */
unsigned long flags;
#define EVENT_PENDING 0
#define COMMAND_PENDING 1
#define ACK_PENDING 2
};
#define UCSI_MAX_SVID 5
#define UCSI_MAX_ALTMODES (UCSI_MAX_SVID * 6)
struct ucsi_connector {
int num;
struct ucsi *ucsi;
struct mutex lock; /* port lock */
struct work_struct work;
struct completion complete;
struct typec_port *port;
struct typec_partner *partner;
struct typec_altmode *port_altmode[UCSI_MAX_ALTMODES];
struct typec_altmode *partner_altmode[UCSI_MAX_ALTMODES];
struct typec_capability typec_cap;
struct ucsi_connector_status status;
struct ucsi_connector_capability cap;
};
int ucsi_send_command(struct ucsi *ucsi, struct ucsi_control *ctrl,
void *retval, size_t size);
void ucsi_altmode_update_active(struct ucsi_connector *con);
#endif /* __DRIVER_USB_TYPEC_UCSI_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment