Skip to content

Commit fb893de

Browse files
committed
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 ...
2 parents d668e84 + fc8cacf commit fb893de

File tree

10 files changed

+483
-128
lines changed

10 files changed

+483
-128
lines changed

drivers/platform/chrome/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ config CROS_EC_TYPEC
218218
tristate "ChromeOS EC Type-C Connector Control"
219219
depends on MFD_CROS_EC_DEV && TYPEC
220220
depends on CROS_USBPD_NOTIFY
221+
depends on USB_ROLE_SWITCH
221222
default MFD_CROS_EC_DEV
222223
help
223224
If you say Y here, you get support for accessing Type C connector

drivers/platform/chrome/cros_ec_debugfs.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,25 @@ static ssize_t cros_ec_pdinfo_read(struct file *file,
242242
read_buf, p - read_buf);
243243
}
244244

245+
static bool cros_ec_uptime_is_supported(struct cros_ec_device *ec_dev)
246+
{
247+
struct {
248+
struct cros_ec_command cmd;
249+
struct ec_response_uptime_info resp;
250+
} __packed msg = {};
251+
int ret;
252+
253+
msg.cmd.command = EC_CMD_GET_UPTIME_INFO;
254+
msg.cmd.insize = sizeof(msg.resp);
255+
256+
ret = cros_ec_cmd_xfer_status(ec_dev, &msg.cmd);
257+
if (ret == -EPROTO && msg.cmd.result == EC_RES_INVALID_COMMAND)
258+
return false;
259+
260+
/* Other errors maybe a transient error, do not rule about support. */
261+
return true;
262+
}
263+
245264
static ssize_t cros_ec_uptime_read(struct file *file, char __user *user_buf,
246265
size_t count, loff_t *ppos)
247266
{
@@ -444,8 +463,9 @@ static int cros_ec_debugfs_probe(struct platform_device *pd)
444463
debugfs_create_file("pdinfo", 0444, debug_info->dir, debug_info,
445464
&cros_ec_pdinfo_fops);
446465

447-
debugfs_create_file("uptime", 0444, debug_info->dir, debug_info,
448-
&cros_ec_uptime_fops);
466+
if (cros_ec_uptime_is_supported(ec->ec_dev))
467+
debugfs_create_file("uptime", 0444, debug_info->dir, debug_info,
468+
&cros_ec_uptime_fops);
449469

450470
debugfs_create_x32("last_resume_result", 0444, debug_info->dir,
451471
&ec->ec_dev->last_resume_result);

drivers/platform/chrome/cros_ec_ishtp.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,10 @@ static int cros_ec_ishtp_probe(struct ishtp_cl_device *cl_device)
681681

682682
/* Register croc_ec_dev mfd */
683683
rv = cros_ec_dev_init(client_data);
684-
if (rv)
684+
if (rv) {
685+
down_write(&init_lock);
685686
goto end_cros_ec_dev_init_error;
687+
}
686688

687689
return 0;
688690

drivers/platform/chrome/cros_ec_proto.c

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ static int cros_ec_get_host_event_wake_mask(struct cros_ec_device *ec_dev,
208208
msg->insize = sizeof(*r);
209209

210210
ret = send_command(ec_dev, msg);
211+
if (ret >= 0) {
212+
if (msg->result == EC_RES_INVALID_COMMAND)
213+
return -EOPNOTSUPP;
214+
if (msg->result != EC_RES_SUCCESS)
215+
return -EPROTO;
216+
}
211217
if (ret > 0) {
212218
r = (struct ec_response_host_event_mask *)msg->data;
213219
*mask = r->mask;
@@ -469,14 +475,33 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev)
469475
&ver_mask);
470476
ec_dev->host_sleep_v1 = (ret >= 0 && (ver_mask & EC_VER_MASK(1)));
471477

472-
/*
473-
* Get host event wake mask, assume all events are wake events
474-
* if unavailable.
475-
*/
478+
/* Get host event wake mask. */
476479
ret = cros_ec_get_host_event_wake_mask(ec_dev, proto_msg,
477480
&ec_dev->host_event_wake_mask);
478-
if (ret < 0)
479-
ec_dev->host_event_wake_mask = U32_MAX;
481+
if (ret < 0) {
482+
/*
483+
* If the EC doesn't support EC_CMD_HOST_EVENT_GET_WAKE_MASK,
484+
* use a reasonable default. Note that we ignore various
485+
* battery, AC status, and power-state events, because (a)
486+
* those can be quite common (e.g., when sitting at full
487+
* charge, on AC) and (b) these are not actionable wake events;
488+
* if anything, we'd like to continue suspending (to save
489+
* power), not wake up.
490+
*/
491+
ec_dev->host_event_wake_mask = U32_MAX &
492+
~(BIT(EC_HOST_EVENT_AC_DISCONNECTED) |
493+
BIT(EC_HOST_EVENT_BATTERY_LOW) |
494+
BIT(EC_HOST_EVENT_BATTERY_CRITICAL) |
495+
BIT(EC_HOST_EVENT_PD_MCU) |
496+
BIT(EC_HOST_EVENT_BATTERY_STATUS));
497+
/*
498+
* Old ECs may not support this command. Complain about all
499+
* other errors.
500+
*/
501+
if (ret != -EOPNOTSUPP)
502+
dev_err(ec_dev->dev,
503+
"failed to retrieve wake mask: %d\n", ret);
504+
}
480505

481506
ret = 0;
482507

@@ -496,8 +521,8 @@ EXPORT_SYMBOL(cros_ec_query_all);
496521
*
497522
* Return: 0 on success or negative error code.
498523
*/
499-
int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
500-
struct cros_ec_command *msg)
524+
static int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
525+
struct cros_ec_command *msg)
501526
{
502527
int ret;
503528

@@ -541,7 +566,6 @@ int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
541566

542567
return ret;
543568
}
544-
EXPORT_SYMBOL(cros_ec_cmd_xfer);
545569

546570
/**
547571
* cros_ec_cmd_xfer_status() - Send a command to the ChromeOS EC.

drivers/platform/chrome/cros_ec_rpmsg.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ struct cros_ec_rpmsg_response {
3838
* @rpdev: rpmsg device we are connected to
3939
* @xfer_ack: completion for host command transfer.
4040
* @host_event_work: Work struct for pending host event.
41+
* @ept: The rpmsg endpoint of this channel.
42+
* @has_pending_host_event: Boolean used to check if there is a pending event.
43+
* @probe_done: Flag to indicate that probe is done.
4144
*/
4245
struct cros_ec_rpmsg {
4346
struct rpmsg_device *rpdev;

drivers/platform/chrome/cros_ec_sensorhub_ring.c

Lines changed: 34 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,7 @@ cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub,
419419
* Disable filtering since we might add more jitter
420420
* if b is in a random point in time.
421421
*/
422-
new_timestamp = fifo_timestamp -
423-
fifo_info->timestamp * 1000 +
424-
in->timestamp * 1000;
422+
new_timestamp = c - b * 1000 + a * 1000;
425423
/*
426424
* The timestamp can be stale if we had to use the fifo
427425
* info timestamp.
@@ -675,29 +673,22 @@ cros_ec_sensor_ring_spread_add(struct cros_ec_sensorhub *sensorhub,
675673
* cros_ec_sensor_ring_spread_add_legacy: Calculate proper timestamps then
676674
* add to ringbuffer (legacy).
677675
*
678-
* Note: This assumes we're running old firmware, where every sample's timestamp
679-
* is after the sample. Run if tight_timestamps == false.
680-
*
681-
* If there is a sample with a proper timestamp
676+
* Note: This assumes we're running old firmware, where timestamp
677+
* is inserted after its sample(s)e. There can be several samples between
678+
* timestamps, so several samples can have the same timestamp.
682679
*
683680
* timestamp | count
684681
* -----------------
685-
* older_unprocess_out --> TS1 | 1
686-
* TS1 | 2
687-
* out --> TS1 | 3
688-
* next_out --> TS2 |
689-
*
690-
* We spread time for the samples [older_unprocess_out .. out]
691-
* between TS1 and TS2: [TS1+1/4, TS1+2/4, TS1+3/4, TS2].
682+
* 1st sample --> TS1 | 1
683+
* TS2 | 2
684+
* TS2 | 3
685+
* TS3 | 4
686+
* last_out -->
692687
*
693-
* If we reach the end of the samples, we compare with the
694-
* current timestamp:
695688
*
696-
* older_unprocess_out --> TS1 | 1
697-
* TS1 | 2
698-
* out --> TS1 | 3
689+
* We spread time for the samples using perod p = (current - TS1)/4.
690+
* between TS1 and TS2: [TS1+p/4, TS1+2p/4, TS1+3p/4, current_timestamp].
699691
*
700-
* We know have [TS1+1/3, TS1+2/3, current timestamp]
701692
*/
702693
static void
703694
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,
710701
int i;
711702

712703
for_each_set_bit(i, &sensor_mask, sensorhub->sensor_num) {
713-
s64 older_timestamp;
714704
s64 timestamp;
715-
struct cros_ec_sensors_ring_sample *older_unprocess_out =
716-
sensorhub->ring;
717-
struct cros_ec_sensors_ring_sample *next_out;
718-
int count = 1;
719-
720-
for (out = sensorhub->ring; out < last_out; out = next_out) {
721-
s64 time_period;
705+
int count = 0;
706+
s64 time_period;
722707

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

727712
/* Timestamp to start with */
728-
older_timestamp = out->timestamp;
729-
730-
/* Find next sample. */
731-
while (next_out < last_out && next_out->sensor_id != i)
732-
next_out++;
713+
timestamp = out->timestamp;
714+
out++;
715+
count = 1;
716+
break;
717+
}
718+
for (; out < last_out; out++) {
719+
/* Find last sample. */
720+
if (out->sensor_id != i)
721+
continue;
722+
count++;
723+
}
724+
if (count == 0)
725+
continue;
733726

734-
if (next_out >= last_out) {
735-
timestamp = current_timestamp;
736-
} else {
737-
timestamp = next_out->timestamp;
738-
if (timestamp == older_timestamp) {
739-
count++;
740-
continue;
741-
}
742-
}
727+
/* Spread uniformly between the first and last samples. */
728+
time_period = div_s64(current_timestamp - timestamp, count);
743729

744-
/*
745-
* The next sample has a new timestamp, spread the
746-
* unprocessed samples.
747-
*/
748-
if (next_out < last_out)
749-
count++;
750-
time_period = div_s64(timestamp - older_timestamp,
751-
count);
752-
753-
for (; older_unprocess_out <= out;
754-
older_unprocess_out++) {
755-
if (older_unprocess_out->sensor_id != i)
756-
continue;
757-
older_timestamp += time_period;
758-
older_unprocess_out->timestamp =
759-
older_timestamp;
760-
}
761-
count = 1;
762-
/* The next_out sample has a valid timestamp, skip. */
763-
next_out++;
764-
older_unprocess_out = next_out;
730+
for (out = sensorhub->ring; out < last_out; out++) {
731+
if (out->sensor_id != i)
732+
continue;
733+
timestamp += time_period;
734+
out->timestamp = timestamp;
765735
}
766736
}
767737

drivers/platform/chrome/cros_ec_spi.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ static int terminate_request(struct cros_ec_device *ec_dev)
148148
* receive_n_bytes - receive n bytes from the EC.
149149
*
150150
* Assumes buf is a pointer into the ec_dev->din buffer
151+
*
152+
* @ec_dev: ChromeOS EC device.
153+
* @buf: Pointer to the buffer receiving the data.
154+
* @n: Number of bytes received.
151155
*/
152156
static int receive_n_bytes(struct cros_ec_device *ec_dev, u8 *buf, int n)
153157
{

0 commit comments

Comments
 (0)