Skip to content

Commit

Permalink
Merge tag 'tag-chrome-platform-for-v5.9' of git://git.kernel.org/pub/…
Browse files Browse the repository at this point in the history
…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
  ...
  • Loading branch information
torvalds committed Aug 12, 2020
2 parents d668e84 + fc8cacf commit fb893de
Show file tree
Hide file tree
Showing 10 changed files with 483 additions and 128 deletions.
1 change: 1 addition & 0 deletions drivers/platform/chrome/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ config CROS_EC_TYPEC
tristate "ChromeOS EC Type-C Connector Control"
depends on MFD_CROS_EC_DEV && TYPEC
depends on CROS_USBPD_NOTIFY
depends on USB_ROLE_SWITCH
default MFD_CROS_EC_DEV
help
If you say Y here, you get support for accessing Type C connector
Expand Down
24 changes: 22 additions & 2 deletions drivers/platform/chrome/cros_ec_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,25 @@ static ssize_t cros_ec_pdinfo_read(struct file *file,
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,
size_t count, loff_t *ppos)
{
Expand Down Expand Up @@ -444,8 +463,9 @@ static int cros_ec_debugfs_probe(struct platform_device *pd)
debugfs_create_file("pdinfo", 0444, debug_info->dir, debug_info,
&cros_ec_pdinfo_fops);

debugfs_create_file("uptime", 0444, debug_info->dir, debug_info,
&cros_ec_uptime_fops);
if (cros_ec_uptime_is_supported(ec->ec_dev))
debugfs_create_file("uptime", 0444, debug_info->dir, debug_info,
&cros_ec_uptime_fops);

debugfs_create_x32("last_resume_result", 0444, debug_info->dir,
&ec->ec_dev->last_resume_result);
Expand Down
4 changes: 3 additions & 1 deletion drivers/platform/chrome/cros_ec_ishtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,10 @@ static int cros_ec_ishtp_probe(struct ishtp_cl_device *cl_device)

/* Register croc_ec_dev mfd */
rv = cros_ec_dev_init(client_data);
if (rv)
if (rv) {
down_write(&init_lock);
goto end_cros_ec_dev_init_error;
}

return 0;

Expand Down
42 changes: 33 additions & 9 deletions drivers/platform/chrome/cros_ec_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ static int cros_ec_get_host_event_wake_mask(struct cros_ec_device *ec_dev,
msg->insize = sizeof(*r);

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) {
r = (struct ec_response_host_event_mask *)msg->data;
*mask = r->mask;
Expand Down Expand Up @@ -469,14 +475,33 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev)
&ver_mask);
ec_dev->host_sleep_v1 = (ret >= 0 && (ver_mask & EC_VER_MASK(1)));

/*
* Get host event wake mask, assume all events are wake events
* if unavailable.
*/
/* Get host event wake mask. */
ret = cros_ec_get_host_event_wake_mask(ec_dev, proto_msg,
&ec_dev->host_event_wake_mask);
if (ret < 0)
ec_dev->host_event_wake_mask = U32_MAX;
if (ret < 0) {
/*
* 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;

Expand All @@ -496,8 +521,8 @@ EXPORT_SYMBOL(cros_ec_query_all);
*
* Return: 0 on success or negative error code.
*/
int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
struct cros_ec_command *msg)
static int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
struct cros_ec_command *msg)
{
int ret;

Expand Down Expand Up @@ -541,7 +566,6 @@ int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,

return ret;
}
EXPORT_SYMBOL(cros_ec_cmd_xfer);

/**
* cros_ec_cmd_xfer_status() - Send a command to the ChromeOS EC.
Expand Down
3 changes: 3 additions & 0 deletions drivers/platform/chrome/cros_ec_rpmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ struct cros_ec_rpmsg_response {
* @rpdev: rpmsg device we are connected to
* @xfer_ack: completion for host command transfer.
* @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 rpmsg_device *rpdev;
Expand Down
98 changes: 34 additions & 64 deletions drivers/platform/chrome/cros_ec_sensorhub_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,7 @@ cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub,
* Disable filtering since we might add more jitter
* if b is in a random point in time.
*/
new_timestamp = fifo_timestamp -
fifo_info->timestamp * 1000 +
in->timestamp * 1000;
new_timestamp = c - b * 1000 + a * 1000;
/*
* The timestamp can be stale if we had to use the fifo
* info timestamp.
Expand Down Expand Up @@ -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
* add to ringbuffer (legacy).
*
* Note: This assumes we're running old firmware, where every sample's timestamp
* is after the sample. Run if tight_timestamps == false.
*
* If there is a sample with a proper timestamp
* Note: This assumes we're running old firmware, where timestamp
* is inserted after its sample(s)e. There can be several samples between
* timestamps, so several samples can have the same timestamp.
*
* timestamp | count
* -----------------
* older_unprocess_out --> TS1 | 1
* TS1 | 2
* out --> TS1 | 3
* next_out --> TS2 |
*
* We spread time for the samples [older_unprocess_out .. out]
* between TS1 and TS2: [TS1+1/4, TS1+2/4, TS1+3/4, TS2].
* 1st sample --> TS1 | 1
* TS2 | 2
* TS2 | 3
* TS3 | 4
* last_out -->
*
* If we reach the end of the samples, we compare with the
* current timestamp:
*
* older_unprocess_out --> TS1 | 1
* TS1 | 2
* out --> TS1 | 3
* We spread time for the samples using perod p = (current - TS1)/4.
* between TS1 and TS2: [TS1+p/4, TS1+2p/4, TS1+3p/4, current_timestamp].
*
* We know have [TS1+1/3, TS1+2/3, current timestamp]
*/
static void
cros_ec_sensor_ring_spread_add_legacy(struct cros_ec_sensorhub *sensorhub,
Expand All @@ -710,58 +701,37 @@ cros_ec_sensor_ring_spread_add_legacy(struct cros_ec_sensorhub *sensorhub,
int i;

for_each_set_bit(i, &sensor_mask, sensorhub->sensor_num) {
s64 older_timestamp;
s64 timestamp;
struct cros_ec_sensors_ring_sample *older_unprocess_out =
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;
int count = 0;
s64 time_period;

next_out = out + 1;
for (out = sensorhub->ring; out < last_out; out++) {
if (out->sensor_id != i)
continue;

/* Timestamp to start with */
older_timestamp = out->timestamp;

/* Find next sample. */
while (next_out < last_out && next_out->sensor_id != i)
next_out++;
timestamp = out->timestamp;
out++;
count = 1;
break;
}
for (; out < last_out; out++) {
/* Find last sample. */
if (out->sensor_id != i)
continue;
count++;
}
if (count == 0)
continue;

if (next_out >= last_out) {
timestamp = current_timestamp;
} else {
timestamp = next_out->timestamp;
if (timestamp == older_timestamp) {
count++;
continue;
}
}
/* Spread uniformly between the first and last samples. */
time_period = div_s64(current_timestamp - timestamp, count);

/*
* The next sample has a new timestamp, spread the
* unprocessed samples.
*/
if (next_out < last_out)
count++;
time_period = div_s64(timestamp - older_timestamp,
count);

for (; older_unprocess_out <= out;
older_unprocess_out++) {
if (older_unprocess_out->sensor_id != i)
continue;
older_timestamp += time_period;
older_unprocess_out->timestamp =
older_timestamp;
}
count = 1;
/* The next_out sample has a valid timestamp, skip. */
next_out++;
older_unprocess_out = next_out;
for (out = sensorhub->ring; out < last_out; out++) {
if (out->sensor_id != i)
continue;
timestamp += time_period;
out->timestamp = timestamp;
}
}

Expand Down
4 changes: 4 additions & 0 deletions drivers/platform/chrome/cros_ec_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ static int terminate_request(struct cros_ec_device *ec_dev)
* receive_n_bytes - receive n bytes from the EC.
*
* 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)
{
Expand Down
Loading

0 comments on commit fb893de

Please sign in to comment.