Commit fb893de3 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'tag-chrome-platform-for-v5.9' of...

Merge tag 'tag-chrome-platform-for-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux

Pull chrome platform updates from Benson Leung:
 "cros_ec_typec:

   - Add support for switch control and alternate modes to the Chrome EC
     Type C port driver

   - Add basic suspend/resume support

  sensorhub:

   - Fix timestamp overflow issue

   - Fix legacy timestamp spreading on Nami systems

  cros_ec_proto:

   - After removing all users of, stop exporting cros_ec_cmd_xfer

   - Check for missing EC_CMD_HOST_EVENT_GET_WAKE_MASK and ignore
     wakeups on old ECs

  misc:

   - Documentation warning cleanup

   - Fix double unlock issue in ishtp"

* tag 'tag-chrome-platform-for-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux: (21 commits)
  platform/chrome: cros_ec_proto: check for missing EC_CMD_HOST_EVENT_GET_WAKE_MASK
  platform/chrome: cros_ec_proto: ignore unnecessary wakeups on old ECs
  platform/chrome: cros_ec_sensorhub: Simplify legacy timestamp spreading
  platform/chrome: cros_ec_proto: Do not export cros_ec_cmd_xfer()
  platform/chrome: cros_ec_typec: Unregister partner on error
  platform/chrome: cros_ec_sensorhub: Fix EC timestamp overflow
  platform/chrome: cros_ec_typec: Add PM support
  platform/chrome: cros_ec_typec: Use workqueue for port update
  platform/chrome: cros_ec_typec: Add a dependency on USB_ROLE_SWITCH
  platform/chrome: cros_ec_ishtp: Fix a double-unlock issue
  platform/chrome: cros_ec_rpmsg: Document missing struct parameters
  platform/chrome: cros_ec_spi: Document missing function parameters
  platform/chrome: cros_ec_typec: Add TBT compat support
  platform/chrome: cros_ec: Add TBT pd_ctrl fields
  platform/chrome: cros_ec_typec: Make configure_mux static
  platform/chrome: cros_ec_typec: Support DP alt mode
  platform/chrome: cros_ec_typec: Add USB mux control
  platform/chrome: cros_ec_typec: Register PD CTRL cmd v2
  platform/chrome: cros_ec: Update mux state bits
  platform/chrome: cros_ec_typec: Register Type C switches
  ...
parents d668e848 fc8cacf3
...@@ -218,6 +218,7 @@ config CROS_EC_TYPEC ...@@ -218,6 +218,7 @@ config CROS_EC_TYPEC
tristate "ChromeOS EC Type-C Connector Control" tristate "ChromeOS EC Type-C Connector Control"
depends on MFD_CROS_EC_DEV && TYPEC depends on MFD_CROS_EC_DEV && TYPEC
depends on CROS_USBPD_NOTIFY depends on CROS_USBPD_NOTIFY
depends on USB_ROLE_SWITCH
default MFD_CROS_EC_DEV default MFD_CROS_EC_DEV
help help
If you say Y here, you get support for accessing Type C connector If you say Y here, you get support for accessing Type C connector
......
...@@ -242,6 +242,25 @@ static ssize_t cros_ec_pdinfo_read(struct file *file, ...@@ -242,6 +242,25 @@ static ssize_t cros_ec_pdinfo_read(struct file *file,
read_buf, p - read_buf); read_buf, p - read_buf);
} }
static bool cros_ec_uptime_is_supported(struct cros_ec_device *ec_dev)
{
struct {
struct cros_ec_command cmd;
struct ec_response_uptime_info resp;
} __packed msg = {};
int ret;
msg.cmd.command = EC_CMD_GET_UPTIME_INFO;
msg.cmd.insize = sizeof(msg.resp);
ret = cros_ec_cmd_xfer_status(ec_dev, &msg.cmd);
if (ret == -EPROTO && msg.cmd.result == EC_RES_INVALID_COMMAND)
return false;
/* Other errors maybe a transient error, do not rule about support. */
return true;
}
static ssize_t cros_ec_uptime_read(struct file *file, char __user *user_buf, static ssize_t cros_ec_uptime_read(struct file *file, char __user *user_buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
...@@ -444,6 +463,7 @@ static int cros_ec_debugfs_probe(struct platform_device *pd) ...@@ -444,6 +463,7 @@ static int cros_ec_debugfs_probe(struct platform_device *pd)
debugfs_create_file("pdinfo", 0444, debug_info->dir, debug_info, debugfs_create_file("pdinfo", 0444, debug_info->dir, debug_info,
&cros_ec_pdinfo_fops); &cros_ec_pdinfo_fops);
if (cros_ec_uptime_is_supported(ec->ec_dev))
debugfs_create_file("uptime", 0444, debug_info->dir, debug_info, debugfs_create_file("uptime", 0444, debug_info->dir, debug_info,
&cros_ec_uptime_fops); &cros_ec_uptime_fops);
......
...@@ -681,8 +681,10 @@ static int cros_ec_ishtp_probe(struct ishtp_cl_device *cl_device) ...@@ -681,8 +681,10 @@ static int cros_ec_ishtp_probe(struct ishtp_cl_device *cl_device)
/* Register croc_ec_dev mfd */ /* Register croc_ec_dev mfd */
rv = cros_ec_dev_init(client_data); rv = cros_ec_dev_init(client_data);
if (rv) if (rv) {
down_write(&init_lock);
goto end_cros_ec_dev_init_error; goto end_cros_ec_dev_init_error;
}
return 0; return 0;
......
...@@ -208,6 +208,12 @@ static int cros_ec_get_host_event_wake_mask(struct cros_ec_device *ec_dev, ...@@ -208,6 +208,12 @@ static int cros_ec_get_host_event_wake_mask(struct cros_ec_device *ec_dev,
msg->insize = sizeof(*r); msg->insize = sizeof(*r);
ret = send_command(ec_dev, msg); ret = send_command(ec_dev, msg);
if (ret >= 0) {
if (msg->result == EC_RES_INVALID_COMMAND)
return -EOPNOTSUPP;
if (msg->result != EC_RES_SUCCESS)
return -EPROTO;
}
if (ret > 0) { if (ret > 0) {
r = (struct ec_response_host_event_mask *)msg->data; r = (struct ec_response_host_event_mask *)msg->data;
*mask = r->mask; *mask = r->mask;
...@@ -469,14 +475,33 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev) ...@@ -469,14 +475,33 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev)
&ver_mask); &ver_mask);
ec_dev->host_sleep_v1 = (ret >= 0 && (ver_mask & EC_VER_MASK(1))); ec_dev->host_sleep_v1 = (ret >= 0 && (ver_mask & EC_VER_MASK(1)));
/* /* Get host event wake mask. */
* Get host event wake mask, assume all events are wake events
* if unavailable.
*/
ret = cros_ec_get_host_event_wake_mask(ec_dev, proto_msg, ret = cros_ec_get_host_event_wake_mask(ec_dev, proto_msg,
&ec_dev->host_event_wake_mask); &ec_dev->host_event_wake_mask);
if (ret < 0) if (ret < 0) {
ec_dev->host_event_wake_mask = U32_MAX; /*
* If the EC doesn't support EC_CMD_HOST_EVENT_GET_WAKE_MASK,
* use a reasonable default. Note that we ignore various
* battery, AC status, and power-state events, because (a)
* those can be quite common (e.g., when sitting at full
* charge, on AC) and (b) these are not actionable wake events;
* if anything, we'd like to continue suspending (to save
* power), not wake up.
*/
ec_dev->host_event_wake_mask = U32_MAX &
~(BIT(EC_HOST_EVENT_AC_DISCONNECTED) |
BIT(EC_HOST_EVENT_BATTERY_LOW) |
BIT(EC_HOST_EVENT_BATTERY_CRITICAL) |
BIT(EC_HOST_EVENT_PD_MCU) |
BIT(EC_HOST_EVENT_BATTERY_STATUS));
/*
* Old ECs may not support this command. Complain about all
* other errors.
*/
if (ret != -EOPNOTSUPP)
dev_err(ec_dev->dev,
"failed to retrieve wake mask: %d\n", ret);
}
ret = 0; ret = 0;
...@@ -496,7 +521,7 @@ EXPORT_SYMBOL(cros_ec_query_all); ...@@ -496,7 +521,7 @@ EXPORT_SYMBOL(cros_ec_query_all);
* *
* Return: 0 on success or negative error code. * Return: 0 on success or negative error code.
*/ */
int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev, static int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
struct cros_ec_command *msg) struct cros_ec_command *msg)
{ {
int ret; int ret;
...@@ -541,7 +566,6 @@ int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev, ...@@ -541,7 +566,6 @@ int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
return ret; return ret;
} }
EXPORT_SYMBOL(cros_ec_cmd_xfer);
/** /**
* cros_ec_cmd_xfer_status() - Send a command to the ChromeOS EC. * cros_ec_cmd_xfer_status() - Send a command to the ChromeOS EC.
......
...@@ -38,6 +38,9 @@ struct cros_ec_rpmsg_response { ...@@ -38,6 +38,9 @@ struct cros_ec_rpmsg_response {
* @rpdev: rpmsg device we are connected to * @rpdev: rpmsg device we are connected to
* @xfer_ack: completion for host command transfer. * @xfer_ack: completion for host command transfer.
* @host_event_work: Work struct for pending host event. * @host_event_work: Work struct for pending host event.
* @ept: The rpmsg endpoint of this channel.
* @has_pending_host_event: Boolean used to check if there is a pending event.
* @probe_done: Flag to indicate that probe is done.
*/ */
struct cros_ec_rpmsg { struct cros_ec_rpmsg {
struct rpmsg_device *rpdev; struct rpmsg_device *rpdev;
......
...@@ -419,9 +419,7 @@ cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub, ...@@ -419,9 +419,7 @@ cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub,
* Disable filtering since we might add more jitter * Disable filtering since we might add more jitter
* if b is in a random point in time. * if b is in a random point in time.
*/ */
new_timestamp = fifo_timestamp - new_timestamp = c - b * 1000 + a * 1000;
fifo_info->timestamp * 1000 +
in->timestamp * 1000;
/* /*
* The timestamp can be stale if we had to use the fifo * The timestamp can be stale if we had to use the fifo
* info timestamp. * info timestamp.
...@@ -675,29 +673,22 @@ cros_ec_sensor_ring_spread_add(struct cros_ec_sensorhub *sensorhub, ...@@ -675,29 +673,22 @@ cros_ec_sensor_ring_spread_add(struct cros_ec_sensorhub *sensorhub,
* cros_ec_sensor_ring_spread_add_legacy: Calculate proper timestamps then * cros_ec_sensor_ring_spread_add_legacy: Calculate proper timestamps then
* add to ringbuffer (legacy). * add to ringbuffer (legacy).
* *
* Note: This assumes we're running old firmware, where every sample's timestamp * Note: This assumes we're running old firmware, where timestamp
* is after the sample. Run if tight_timestamps == false. * is inserted after its sample(s)e. There can be several samples between
* * timestamps, so several samples can have the same timestamp.
* If there is a sample with a proper timestamp
* *
* timestamp | count * timestamp | count
* ----------------- * -----------------
* older_unprocess_out --> TS1 | 1 * 1st sample --> TS1 | 1
* TS1 | 2 * TS2 | 2
* out --> TS1 | 3 * TS2 | 3
* next_out --> TS2 | * TS3 | 4
* * last_out -->
* We spread time for the samples [older_unprocess_out .. out]
* between TS1 and TS2: [TS1+1/4, TS1+2/4, TS1+3/4, TS2].
* *
* If we reach the end of the samples, we compare with the
* current timestamp:
* *
* older_unprocess_out --> TS1 | 1 * We spread time for the samples using perod p = (current - TS1)/4.
* TS1 | 2 * between TS1 and TS2: [TS1+p/4, TS1+2p/4, TS1+3p/4, current_timestamp].
* out --> TS1 | 3
* *
* We know have [TS1+1/3, TS1+2/3, current timestamp]
*/ */
static void static void
cros_ec_sensor_ring_spread_add_legacy(struct cros_ec_sensorhub *sensorhub, cros_ec_sensor_ring_spread_add_legacy(struct cros_ec_sensorhub *sensorhub,
...@@ -710,58 +701,37 @@ cros_ec_sensor_ring_spread_add_legacy(struct cros_ec_sensorhub *sensorhub, ...@@ -710,58 +701,37 @@ cros_ec_sensor_ring_spread_add_legacy(struct cros_ec_sensorhub *sensorhub,
int i; int i;
for_each_set_bit(i, &sensor_mask, sensorhub->sensor_num) { for_each_set_bit(i, &sensor_mask, sensorhub->sensor_num) {
s64 older_timestamp;
s64 timestamp; s64 timestamp;
struct cros_ec_sensors_ring_sample *older_unprocess_out = int count = 0;
sensorhub->ring;
struct cros_ec_sensors_ring_sample *next_out;
int count = 1;
for (out = sensorhub->ring; out < last_out; out = next_out) {
s64 time_period; s64 time_period;
next_out = out + 1; for (out = sensorhub->ring; out < last_out; out++) {
if (out->sensor_id != i) if (out->sensor_id != i)
continue; continue;
/* Timestamp to start with */ /* Timestamp to start with */
older_timestamp = out->timestamp; timestamp = out->timestamp;
out++;
/* Find next sample. */ count = 1;
while (next_out < last_out && next_out->sensor_id != i) break;
next_out++;
if (next_out >= last_out) {
timestamp = current_timestamp;
} else {
timestamp = next_out->timestamp;
if (timestamp == older_timestamp) {
count++;
continue;
} }
for (; out < last_out; out++) {
/* Find last sample. */
if (out->sensor_id != i)
continue;
count++;
} }
if (count == 0)
continue;
/* /* Spread uniformly between the first and last samples. */
* The next sample has a new timestamp, spread the time_period = div_s64(current_timestamp - timestamp, count);
* unprocessed samples.
*/
if (next_out < last_out)
count++;
time_period = div_s64(timestamp - older_timestamp,
count);
for (; older_unprocess_out <= out; for (out = sensorhub->ring; out < last_out; out++) {
older_unprocess_out++) { if (out->sensor_id != i)
if (older_unprocess_out->sensor_id != i)
continue; continue;
older_timestamp += time_period; timestamp += time_period;
older_unprocess_out->timestamp = out->timestamp = timestamp;
older_timestamp;
}
count = 1;
/* The next_out sample has a valid timestamp, skip. */
next_out++;
older_unprocess_out = next_out;
} }
} }
......
...@@ -148,6 +148,10 @@ static int terminate_request(struct cros_ec_device *ec_dev) ...@@ -148,6 +148,10 @@ static int terminate_request(struct cros_ec_device *ec_dev)
* receive_n_bytes - receive n bytes from the EC. * receive_n_bytes - receive n bytes from the EC.
* *
* Assumes buf is a pointer into the ec_dev->din buffer * Assumes buf is a pointer into the ec_dev->din buffer
*
* @ec_dev: ChromeOS EC device.
* @buf: Pointer to the buffer receiving the data.
* @n: Number of bytes received.
*/ */
static int receive_n_bytes(struct cros_ec_device *ec_dev, u8 *buf, int n) static int receive_n_bytes(struct cros_ec_device *ec_dev, u8 *buf, int n)
{ {
......
This diff is collapsed.
...@@ -4917,15 +4917,26 @@ struct ec_response_usb_pd_control_v1 { ...@@ -4917,15 +4917,26 @@ struct ec_response_usb_pd_control_v1 {
#define USBC_PD_CC_UFP_ATTACHED 4 /* UFP attached to usbc */ #define USBC_PD_CC_UFP_ATTACHED 4 /* UFP attached to usbc */
#define USBC_PD_CC_DFP_ATTACHED 5 /* DPF attached to usbc */ #define USBC_PD_CC_DFP_ATTACHED 5 /* DPF attached to usbc */
/* Active/Passive Cable */
#define USB_PD_CTRL_ACTIVE_CABLE BIT(0)
/* Optical/Non-optical cable */
#define USB_PD_CTRL_OPTICAL_CABLE BIT(1)
/* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */
#define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2)
/* Active Link Uni-Direction */
#define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3)
struct ec_response_usb_pd_control_v2 { struct ec_response_usb_pd_control_v2 {
uint8_t enabled; uint8_t enabled;
uint8_t role; uint8_t role;
uint8_t polarity; uint8_t polarity;
char state[32]; char state[32];
uint8_t cc_state; /* USBC_PD_CC_*Encoded cc state */ uint8_t cc_state; /* enum pd_cc_states representing cc state */
uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */ uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
/* CL:1500994 Current cable type */ uint8_t reserved; /* Reserved for future use */
uint8_t reserved_cable_type; uint8_t control_flags; /* USB_PD_CTRL_*flags */
uint8_t cable_speed; /* TBT_SS_* cable speed */
uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */
} __ec_align1; } __ec_align1;
#define EC_CMD_USB_PD_PORTS 0x0102 #define EC_CMD_USB_PD_PORTS 0x0102
...@@ -5207,11 +5218,15 @@ struct ec_params_usb_pd_mux_info { ...@@ -5207,11 +5218,15 @@ struct ec_params_usb_pd_mux_info {
} __ec_align1; } __ec_align1;
/* Flags representing mux state */ /* Flags representing mux state */
#define USB_PD_MUX_NONE 0 /* Open switch */
#define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */ #define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */ #define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */ #define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
#define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */ #define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
#define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */ #define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
#define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */
#define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */
#define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */
struct ec_response_usb_pd_mux_info { struct ec_response_usb_pd_mux_info {
uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */ uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
......
...@@ -216,9 +216,6 @@ int cros_ec_prepare_tx(struct cros_ec_device *ec_dev, ...@@ -216,9 +216,6 @@ int cros_ec_prepare_tx(struct cros_ec_device *ec_dev,
int cros_ec_check_result(struct cros_ec_device *ec_dev, int cros_ec_check_result(struct cros_ec_device *ec_dev,
struct cros_ec_command *msg); struct cros_ec_command *msg);
int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
struct cros_ec_command *msg);
int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev, int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev,
struct cros_ec_command *msg); struct cros_ec_command *msg);
......
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