Commit 02d4f8a3 authored by Linus Torvalds's avatar Linus Torvalds

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

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

Pull chrome platform updates from Benson Leung:
 "cros_ec_typec:

   - Check for EC device - Fix a crash when using the cros_ec_typec
     driver on older hardware not capable of typec commands

   - Make try power role optional

   - Mux configuration reorganization series from Prashant

  cros_ec_debugfs:

   - Fix use after free. Thanks Tzung-bi

  sensorhub:

   - cros_ec_sensorhub fixup - Split trace include file

  misc:

   - Add new mailing list for chrome-platform development:

	chrome-platform@lists.linux.dev

     Now with patchwork!"

* tag 'tag-chrome-platform-for-v5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux:
  platform/chrome: cros_ec_debugfs: detach log reader wq from devm
  platform: chrome: Split trace include file
  platform/chrome: cros_ec_typec: Update mux flags during partner removal
  platform/chrome: cros_ec_typec: Configure muxes at start of port update
  platform/chrome: cros_ec_typec: Get mux state inside configure_mux
  platform/chrome: cros_ec_typec: Move mux flag checks
  platform/chrome: cros_ec_typec: Check for EC device
  platform/chrome: cros_ec_typec: Make try power role optional
  MAINTAINERS: platform-chrome: Add new chrome-platform@lists.linux.dev list
parents b4902070 0e8eb5e8
...@@ -4640,6 +4640,7 @@ F: drivers/input/touchscreen/chipone_icn8505.c ...@@ -4640,6 +4640,7 @@ F: drivers/input/touchscreen/chipone_icn8505.c
CHROME HARDWARE PLATFORM SUPPORT CHROME HARDWARE PLATFORM SUPPORT
M: Benson Leung <bleung@chromium.org> M: Benson Leung <bleung@chromium.org>
L: chrome-platform@lists.linux.dev
S: Maintained S: Maintained
T: git git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git T: git git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git
F: drivers/platform/chrome/ F: drivers/platform/chrome/
...@@ -4648,6 +4649,7 @@ CHROMEOS EC CODEC DRIVER ...@@ -4648,6 +4649,7 @@ CHROMEOS EC CODEC DRIVER
M: Cheng-Yi Chiang <cychiang@chromium.org> M: Cheng-Yi Chiang <cychiang@chromium.org>
M: Tzung-Bi Shih <tzungbi@google.com> M: Tzung-Bi Shih <tzungbi@google.com>
R: Guenter Roeck <groeck@chromium.org> R: Guenter Roeck <groeck@chromium.org>
L: chrome-platform@lists.linux.dev
S: Maintained S: Maintained
F: Documentation/devicetree/bindings/sound/google,cros-ec-codec.yaml F: Documentation/devicetree/bindings/sound/google,cros-ec-codec.yaml
F: sound/soc/codecs/cros_ec_codec.* F: sound/soc/codecs/cros_ec_codec.*
...@@ -4655,6 +4657,7 @@ F: sound/soc/codecs/cros_ec_codec.* ...@@ -4655,6 +4657,7 @@ F: sound/soc/codecs/cros_ec_codec.*
CHROMEOS EC SUBDRIVERS CHROMEOS EC SUBDRIVERS
M: Benson Leung <bleung@chromium.org> M: Benson Leung <bleung@chromium.org>
R: Guenter Roeck <groeck@chromium.org> R: Guenter Roeck <groeck@chromium.org>
L: chrome-platform@lists.linux.dev
S: Maintained S: Maintained
F: drivers/power/supply/cros_usbpd-charger.c F: drivers/power/supply/cros_usbpd-charger.c
N: cros_ec N: cros_ec
...@@ -4662,11 +4665,13 @@ N: cros-ec ...@@ -4662,11 +4665,13 @@ N: cros-ec
CHROMEOS EC USB TYPE-C DRIVER CHROMEOS EC USB TYPE-C DRIVER
M: Prashant Malani <pmalani@chromium.org> M: Prashant Malani <pmalani@chromium.org>
L: chrome-platform@lists.linux.dev
S: Maintained S: Maintained
F: drivers/platform/chrome/cros_ec_typec.c F: drivers/platform/chrome/cros_ec_typec.c
CHROMEOS EC USB PD NOTIFY DRIVER CHROMEOS EC USB PD NOTIFY DRIVER
M: Prashant Malani <pmalani@chromium.org> M: Prashant Malani <pmalani@chromium.org>
L: chrome-platform@lists.linux.dev
S: Maintained S: Maintained
F: drivers/platform/chrome/cros_usbpd_notify.c F: drivers/platform/chrome/cros_usbpd_notify.c
F: include/linux/platform_data/cros_usbpd_notify.h F: include/linux/platform_data/cros_usbpd_notify.h
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# tell define_trace.h where to find the cros ec trace header # tell define_trace.h where to find the cros ec trace header
CFLAGS_cros_ec_trace.o:= -I$(src) CFLAGS_cros_ec_trace.o:= -I$(src)
CFLAGS_cros_ec_sensorhub_ring.o:= -I$(src)
obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o
obj-$(CONFIG_CHROMEOS_PRIVACY_SCREEN) += chromeos_privacy_screen.o obj-$(CONFIG_CHROMEOS_PRIVACY_SCREEN) += chromeos_privacy_screen.o
...@@ -21,7 +22,7 @@ obj-$(CONFIG_CROS_EC_CHARDEV) += cros_ec_chardev.o ...@@ -21,7 +22,7 @@ obj-$(CONFIG_CROS_EC_CHARDEV) += cros_ec_chardev.o
obj-$(CONFIG_CROS_EC_LIGHTBAR) += cros_ec_lightbar.o obj-$(CONFIG_CROS_EC_LIGHTBAR) += cros_ec_lightbar.o
obj-$(CONFIG_CROS_EC_VBC) += cros_ec_vbc.o obj-$(CONFIG_CROS_EC_VBC) += cros_ec_vbc.o
obj-$(CONFIG_CROS_EC_DEBUGFS) += cros_ec_debugfs.o obj-$(CONFIG_CROS_EC_DEBUGFS) += cros_ec_debugfs.o
cros-ec-sensorhub-objs := cros_ec_sensorhub.o cros_ec_sensorhub_ring.o cros_ec_trace.o cros-ec-sensorhub-objs := cros_ec_sensorhub.o cros_ec_sensorhub_ring.o
obj-$(CONFIG_CROS_EC_SENSORHUB) += cros-ec-sensorhub.o obj-$(CONFIG_CROS_EC_SENSORHUB) += cros-ec-sensorhub.o
obj-$(CONFIG_CROS_EC_SYSFS) += cros_ec_sysfs.o obj-$(CONFIG_CROS_EC_SYSFS) += cros_ec_sysfs.o
obj-$(CONFIG_CROS_USBPD_LOGGER) += cros_usbpd_logger.o obj-$(CONFIG_CROS_USBPD_LOGGER) += cros_usbpd_logger.o
......
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
#define CIRC_ADD(idx, size, value) (((idx) + (value)) & ((size) - 1)) #define CIRC_ADD(idx, size, value) (((idx) + (value)) & ((size) - 1))
/* waitqueue for log readers */
static DECLARE_WAIT_QUEUE_HEAD(cros_ec_debugfs_log_wq);
/** /**
* struct cros_ec_debugfs - EC debugging information. * struct cros_ec_debugfs - EC debugging information.
* *
...@@ -33,7 +36,6 @@ ...@@ -33,7 +36,6 @@
* @log_buffer: circular buffer for console log information * @log_buffer: circular buffer for console log information
* @read_msg: preallocated EC command and buffer to read console log * @read_msg: preallocated EC command and buffer to read console log
* @log_mutex: mutex to protect circular buffer * @log_mutex: mutex to protect circular buffer
* @log_wq: waitqueue for log readers
* @log_poll_work: recurring task to poll EC for new console log data * @log_poll_work: recurring task to poll EC for new console log data
* @panicinfo_blob: panicinfo debugfs blob * @panicinfo_blob: panicinfo debugfs blob
*/ */
...@@ -44,7 +46,6 @@ struct cros_ec_debugfs { ...@@ -44,7 +46,6 @@ struct cros_ec_debugfs {
struct circ_buf log_buffer; struct circ_buf log_buffer;
struct cros_ec_command *read_msg; struct cros_ec_command *read_msg;
struct mutex log_mutex; struct mutex log_mutex;
wait_queue_head_t log_wq;
struct delayed_work log_poll_work; struct delayed_work log_poll_work;
/* EC panicinfo */ /* EC panicinfo */
struct debugfs_blob_wrapper panicinfo_blob; struct debugfs_blob_wrapper panicinfo_blob;
...@@ -107,7 +108,7 @@ static void cros_ec_console_log_work(struct work_struct *__work) ...@@ -107,7 +108,7 @@ static void cros_ec_console_log_work(struct work_struct *__work)
buf_space--; buf_space--;
} }
wake_up(&debug_info->log_wq); wake_up(&cros_ec_debugfs_log_wq);
} }
mutex_unlock(&debug_info->log_mutex); mutex_unlock(&debug_info->log_mutex);
...@@ -141,7 +142,7 @@ static ssize_t cros_ec_console_log_read(struct file *file, char __user *buf, ...@@ -141,7 +142,7 @@ static ssize_t cros_ec_console_log_read(struct file *file, char __user *buf,
mutex_unlock(&debug_info->log_mutex); mutex_unlock(&debug_info->log_mutex);
ret = wait_event_interruptible(debug_info->log_wq, ret = wait_event_interruptible(cros_ec_debugfs_log_wq,
CIRC_CNT(cb->head, cb->tail, LOG_SIZE)); CIRC_CNT(cb->head, cb->tail, LOG_SIZE));
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -173,7 +174,7 @@ static __poll_t cros_ec_console_log_poll(struct file *file, ...@@ -173,7 +174,7 @@ static __poll_t cros_ec_console_log_poll(struct file *file,
struct cros_ec_debugfs *debug_info = file->private_data; struct cros_ec_debugfs *debug_info = file->private_data;
__poll_t mask = 0; __poll_t mask = 0;
poll_wait(file, &debug_info->log_wq, wait); poll_wait(file, &cros_ec_debugfs_log_wq, wait);
mutex_lock(&debug_info->log_mutex); mutex_lock(&debug_info->log_mutex);
if (CIRC_CNT(debug_info->log_buffer.head, if (CIRC_CNT(debug_info->log_buffer.head,
...@@ -377,7 +378,6 @@ static int cros_ec_create_console_log(struct cros_ec_debugfs *debug_info) ...@@ -377,7 +378,6 @@ static int cros_ec_create_console_log(struct cros_ec_debugfs *debug_info)
debug_info->log_buffer.tail = 0; debug_info->log_buffer.tail = 0;
mutex_init(&debug_info->log_mutex); mutex_init(&debug_info->log_mutex);
init_waitqueue_head(&debug_info->log_wq);
debugfs_create_file("console_log", S_IFREG | 0444, debug_info->dir, debugfs_create_file("console_log", S_IFREG | 0444, debug_info->dir,
debug_info, &cros_ec_console_log_fops); debug_info, &cros_ec_console_log_fops);
......
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
#include <linux/sort.h> #include <linux/sort.h>
#include <linux/slab.h> #include <linux/slab.h>
#include "cros_ec_trace.h" #define CREATE_TRACE_POINTS
#include "cros_ec_sensorhub_trace.h"
/* Precision of fixed point for the m values from the filter */ /* Precision of fixed point for the m values from the filter */
#define M_PRECISION BIT(23) #define M_PRECISION BIT(23)
......
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Trace events for the ChromeOS Sensorhub kernel module
*
* Copyright 2021 Google LLC.
*/
#undef TRACE_SYSTEM
#define TRACE_SYSTEM cros_ec
#if !defined(_CROS_EC_SENSORHUB_TRACE_H_) || defined(TRACE_HEADER_MULTI_READ)
#define _CROS_EC_SENSORHUB_TRACE_H_
#include <linux/types.h>
#include <linux/platform_data/cros_ec_sensorhub.h>
#include <linux/tracepoint.h>
TRACE_EVENT(cros_ec_sensorhub_timestamp,
TP_PROTO(u32 ec_sample_timestamp, u32 ec_fifo_timestamp, s64 fifo_timestamp,
s64 current_timestamp, s64 current_time),
TP_ARGS(ec_sample_timestamp, ec_fifo_timestamp, fifo_timestamp, current_timestamp,
current_time),
TP_STRUCT__entry(
__field(u32, ec_sample_timestamp)
__field(u32, ec_fifo_timestamp)
__field(s64, fifo_timestamp)
__field(s64, current_timestamp)
__field(s64, current_time)
__field(s64, delta)
),
TP_fast_assign(
__entry->ec_sample_timestamp = ec_sample_timestamp;
__entry->ec_fifo_timestamp = ec_fifo_timestamp;
__entry->fifo_timestamp = fifo_timestamp;
__entry->current_timestamp = current_timestamp;
__entry->current_time = current_time;
__entry->delta = current_timestamp - current_time;
),
TP_printk("ec_ts: %9u, ec_fifo_ts: %9u, fifo_ts: %12lld, curr_ts: %12lld, curr_time: %12lld, delta %12lld",
__entry->ec_sample_timestamp,
__entry->ec_fifo_timestamp,
__entry->fifo_timestamp,
__entry->current_timestamp,
__entry->current_time,
__entry->delta
)
);
TRACE_EVENT(cros_ec_sensorhub_data,
TP_PROTO(u32 ec_sensor_num, u32 ec_fifo_timestamp, s64 fifo_timestamp,
s64 current_timestamp, s64 current_time),
TP_ARGS(ec_sensor_num, ec_fifo_timestamp, fifo_timestamp, current_timestamp, current_time),
TP_STRUCT__entry(
__field(u32, ec_sensor_num)
__field(u32, ec_fifo_timestamp)
__field(s64, fifo_timestamp)
__field(s64, current_timestamp)
__field(s64, current_time)
__field(s64, delta)
),
TP_fast_assign(
__entry->ec_sensor_num = ec_sensor_num;
__entry->ec_fifo_timestamp = ec_fifo_timestamp;
__entry->fifo_timestamp = fifo_timestamp;
__entry->current_timestamp = current_timestamp;
__entry->current_time = current_time;
__entry->delta = current_timestamp - current_time;
),
TP_printk("ec_num: %4u, ec_fifo_ts: %9u, fifo_ts: %12lld, curr_ts: %12lld, curr_time: %12lld, delta %12lld",
__entry->ec_sensor_num,
__entry->ec_fifo_timestamp,
__entry->fifo_timestamp,
__entry->current_timestamp,
__entry->current_time,
__entry->delta
)
);
TRACE_EVENT(cros_ec_sensorhub_filter,
TP_PROTO(struct cros_ec_sensors_ts_filter_state *state, s64 dx, s64 dy),
TP_ARGS(state, dx, dy),
TP_STRUCT__entry(
__field(s64, dx)
__field(s64, dy)
__field(s64, median_m)
__field(s64, median_error)
__field(s64, history_len)
__field(s64, x)
__field(s64, y)
),
TP_fast_assign(
__entry->dx = dx;
__entry->dy = dy;
__entry->median_m = state->median_m;
__entry->median_error = state->median_error;
__entry->history_len = state->history_len;
__entry->x = state->x_offset;
__entry->y = state->y_offset;
),
TP_printk("dx: %12lld. dy: %12lld median_m: %12lld median_error: %12lld len: %lld x: %12lld y: %12lld",
__entry->dx,
__entry->dy,
__entry->median_m,
__entry->median_error,
__entry->history_len,
__entry->x,
__entry->y
)
);
#endif /* _CROS_EC_SENSORHUB_TRACE_H_ */
/* this part must be outside header guard */
#undef TRACE_INCLUDE_PATH
#define TRACE_INCLUDE_PATH .
#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE cros_ec_sensorhub_trace
#include <trace/define_trace.h>
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include <linux/types.h> #include <linux/types.h>
#include <linux/platform_data/cros_ec_commands.h> #include <linux/platform_data/cros_ec_commands.h>
#include <linux/platform_data/cros_ec_proto.h> #include <linux/platform_data/cros_ec_proto.h>
#include <linux/platform_data/cros_ec_sensorhub.h>
#include <linux/tracepoint.h> #include <linux/tracepoint.h>
...@@ -71,100 +70,6 @@ TRACE_EVENT(cros_ec_request_done, ...@@ -71,100 +70,6 @@ TRACE_EVENT(cros_ec_request_done,
__entry->retval) __entry->retval)
); );
TRACE_EVENT(cros_ec_sensorhub_timestamp,
TP_PROTO(u32 ec_sample_timestamp, u32 ec_fifo_timestamp, s64 fifo_timestamp,
s64 current_timestamp, s64 current_time),
TP_ARGS(ec_sample_timestamp, ec_fifo_timestamp, fifo_timestamp, current_timestamp,
current_time),
TP_STRUCT__entry(
__field(u32, ec_sample_timestamp)
__field(u32, ec_fifo_timestamp)
__field(s64, fifo_timestamp)
__field(s64, current_timestamp)
__field(s64, current_time)
__field(s64, delta)
),
TP_fast_assign(
__entry->ec_sample_timestamp = ec_sample_timestamp;
__entry->ec_fifo_timestamp = ec_fifo_timestamp;
__entry->fifo_timestamp = fifo_timestamp;
__entry->current_timestamp = current_timestamp;
__entry->current_time = current_time;
__entry->delta = current_timestamp - current_time;
),
TP_printk("ec_ts: %9u, ec_fifo_ts: %9u, fifo_ts: %12lld, curr_ts: %12lld, curr_time: %12lld, delta %12lld",
__entry->ec_sample_timestamp,
__entry->ec_fifo_timestamp,
__entry->fifo_timestamp,
__entry->current_timestamp,
__entry->current_time,
__entry->delta
)
);
TRACE_EVENT(cros_ec_sensorhub_data,
TP_PROTO(u32 ec_sensor_num, u32 ec_fifo_timestamp, s64 fifo_timestamp,
s64 current_timestamp, s64 current_time),
TP_ARGS(ec_sensor_num, ec_fifo_timestamp, fifo_timestamp, current_timestamp, current_time),
TP_STRUCT__entry(
__field(u32, ec_sensor_num)
__field(u32, ec_fifo_timestamp)
__field(s64, fifo_timestamp)
__field(s64, current_timestamp)
__field(s64, current_time)
__field(s64, delta)
),
TP_fast_assign(
__entry->ec_sensor_num = ec_sensor_num;
__entry->ec_fifo_timestamp = ec_fifo_timestamp;
__entry->fifo_timestamp = fifo_timestamp;
__entry->current_timestamp = current_timestamp;
__entry->current_time = current_time;
__entry->delta = current_timestamp - current_time;
),
TP_printk("ec_num: %4u, ec_fifo_ts: %9u, fifo_ts: %12lld, curr_ts: %12lld, curr_time: %12lld, delta %12lld",
__entry->ec_sensor_num,
__entry->ec_fifo_timestamp,
__entry->fifo_timestamp,
__entry->current_timestamp,
__entry->current_time,
__entry->delta
)
);
TRACE_EVENT(cros_ec_sensorhub_filter,
TP_PROTO(struct cros_ec_sensors_ts_filter_state *state, s64 dx, s64 dy),
TP_ARGS(state, dx, dy),
TP_STRUCT__entry(
__field(s64, dx)
__field(s64, dy)
__field(s64, median_m)
__field(s64, median_error)
__field(s64, history_len)
__field(s64, x)
__field(s64, y)
),
TP_fast_assign(
__entry->dx = dx;
__entry->dy = dy;
__entry->median_m = state->median_m;
__entry->median_error = state->median_error;
__entry->history_len = state->history_len;
__entry->x = state->x_offset;
__entry->y = state->y_offset;
),
TP_printk("dx: %12lld. dy: %12lld median_m: %12lld median_error: %12lld len: %lld x: %12lld y: %12lld",
__entry->dx,
__entry->dy,
__entry->median_m,
__entry->median_error,
__entry->history_len,
__entry->x,
__entry->y
)
);
#endif /* _CROS_EC_TRACE_H_ */ #endif /* _CROS_EC_TRACE_H_ */
/* this part must be outside header guard */ /* this part must be outside header guard */
......
...@@ -115,17 +115,18 @@ static int cros_typec_parse_port_props(struct typec_capability *cap, ...@@ -115,17 +115,18 @@ static int cros_typec_parse_port_props(struct typec_capability *cap,
return ret; return ret;
cap->data = ret; cap->data = ret;
/* Try-power-role is optional. */
ret = fwnode_property_read_string(fwnode, "try-power-role", &buf); ret = fwnode_property_read_string(fwnode, "try-power-role", &buf);
if (ret) { if (ret) {
dev_err(dev, "try-power-role not found: %d\n", ret); dev_warn(dev, "try-power-role not found: %d\n", ret);
return ret; cap->prefer_role = TYPEC_NO_PREFERRED_ROLE;
} else {
ret = typec_find_power_role(buf);
if (ret < 0)
return ret;
cap->prefer_role = ret;
} }
ret = typec_find_power_role(buf);
if (ret < 0)
return ret;
cap->prefer_role = ret;
cap->fwnode = fwnode; cap->fwnode = fwnode;
return 0; return 0;
...@@ -227,6 +228,7 @@ static void cros_typec_remove_partner(struct cros_typec_data *typec, ...@@ -227,6 +228,7 @@ static void cros_typec_remove_partner(struct cros_typec_data *typec,
cros_typec_unregister_altmodes(typec, port_num, true); cros_typec_unregister_altmodes(typec, port_num, true);
cros_typec_usb_disconnect_state(port); cros_typec_usb_disconnect_state(port);
port->mux_flags = USB_PD_MUX_NONE;
typec_unregister_partner(port->partner); typec_unregister_partner(port->partner);
port->partner = NULL; port->partner = NULL;
...@@ -512,20 +514,38 @@ static int cros_typec_enable_usb4(struct cros_typec_data *typec, ...@@ -512,20 +514,38 @@ static int cros_typec_enable_usb4(struct cros_typec_data *typec,
} }
static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num, static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
uint8_t mux_flags,
struct ec_response_usb_pd_control_v2 *pd_ctrl) struct ec_response_usb_pd_control_v2 *pd_ctrl)
{ {
struct cros_typec_port *port = typec->ports[port_num]; struct cros_typec_port *port = typec->ports[port_num];
struct ec_response_usb_pd_mux_info resp;
struct ec_params_usb_pd_mux_info req = {
.port = port_num,
};
struct ec_params_usb_pd_mux_ack mux_ack; struct ec_params_usb_pd_mux_ack mux_ack;
enum typec_orientation orientation; enum typec_orientation orientation;
int ret; int ret;
if (mux_flags == USB_PD_MUX_NONE) { ret = cros_ec_command(typec->ec, 0, EC_CMD_USB_PD_MUX_INFO,
&req, sizeof(req), &resp, sizeof(resp));
if (ret < 0) {
dev_warn(typec->dev, "Failed to get mux info for port: %d, err = %d\n",
port_num, ret);
return ret;
}
/* No change needs to be made, let's exit early. */
if (port->mux_flags == resp.flags && port->role == pd_ctrl->role)
return 0;
port->mux_flags = resp.flags;
port->role = pd_ctrl->role;
if (port->mux_flags == USB_PD_MUX_NONE) {
ret = cros_typec_usb_disconnect_state(port); ret = cros_typec_usb_disconnect_state(port);
goto mux_ack; goto mux_ack;
} }
if (mux_flags & USB_PD_MUX_POLARITY_INVERTED) if (port->mux_flags & USB_PD_MUX_POLARITY_INVERTED)
orientation = TYPEC_ORIENTATION_REVERSE; orientation = TYPEC_ORIENTATION_REVERSE;
else else
orientation = TYPEC_ORIENTATION_NORMAL; orientation = TYPEC_ORIENTATION_NORMAL;
...@@ -540,22 +560,22 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num, ...@@ -540,22 +560,22 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
if (ret) if (ret)
return ret; return ret;
if (mux_flags & USB_PD_MUX_USB4_ENABLED) { if (port->mux_flags & USB_PD_MUX_USB4_ENABLED) {
ret = cros_typec_enable_usb4(typec, port_num, pd_ctrl); ret = cros_typec_enable_usb4(typec, port_num, pd_ctrl);
} else if (mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) { } else if (port->mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) {
ret = cros_typec_enable_tbt(typec, port_num, pd_ctrl); ret = cros_typec_enable_tbt(typec, port_num, pd_ctrl);
} else if (mux_flags & USB_PD_MUX_DP_ENABLED) { } else if (port->mux_flags & USB_PD_MUX_DP_ENABLED) {
ret = cros_typec_enable_dp(typec, port_num, pd_ctrl); ret = cros_typec_enable_dp(typec, port_num, pd_ctrl);
} else if (mux_flags & USB_PD_MUX_SAFE_MODE) { } else if (port->mux_flags & USB_PD_MUX_SAFE_MODE) {
ret = cros_typec_usb_safe_state(port); ret = cros_typec_usb_safe_state(port);
} else if (mux_flags & USB_PD_MUX_USB_ENABLED) { } else if (port->mux_flags & USB_PD_MUX_USB_ENABLED) {
port->state.alt = NULL; port->state.alt = NULL;
port->state.mode = TYPEC_STATE_USB; port->state.mode = TYPEC_STATE_USB;
ret = typec_mux_set(port->mux, &port->state); ret = typec_mux_set(port->mux, &port->state);
} else { } else {
dev_dbg(typec->dev, dev_dbg(typec->dev,
"Unrecognized mode requested, mux flags: %x\n", "Unrecognized mode requested, mux flags: %x\n",
mux_flags); port->mux_flags);
} }
mux_ack: mux_ack:
...@@ -630,17 +650,6 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec, ...@@ -630,17 +650,6 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec,
} }
} }
static int cros_typec_get_mux_info(struct cros_typec_data *typec, int port_num,
struct ec_response_usb_pd_mux_info *resp)
{
struct ec_params_usb_pd_mux_info req = {
.port = port_num,
};
return cros_ec_command(typec->ec, 0, EC_CMD_USB_PD_MUX_INFO, &req,
sizeof(req), resp, sizeof(*resp));
}
/* /*
* Helper function to register partner/plug altmodes. * Helper function to register partner/plug altmodes.
*/ */
...@@ -938,7 +947,6 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num) ...@@ -938,7 +947,6 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)
{ {
struct ec_params_usb_pd_control req; struct ec_params_usb_pd_control req;
struct ec_response_usb_pd_control_v2 resp; struct ec_response_usb_pd_control_v2 resp;
struct ec_response_usb_pd_mux_info mux_resp;
int ret; int ret;
if (port_num < 0 || port_num >= typec->num_ports) { if (port_num < 0 || port_num >= typec->num_ports) {
...@@ -958,6 +966,11 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num) ...@@ -958,6 +966,11 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)
if (ret < 0) if (ret < 0)
return ret; return ret;
/* Update the switches if they exist, according to requested state */
ret = cros_typec_configure_mux(typec, port_num, &resp);
if (ret)
dev_warn(typec->dev, "Configure muxes failed, err = %d\n", ret);
dev_dbg(typec->dev, "Enabled %d: 0x%hhx\n", port_num, resp.enabled); dev_dbg(typec->dev, "Enabled %d: 0x%hhx\n", port_num, resp.enabled);
dev_dbg(typec->dev, "Role %d: 0x%hhx\n", port_num, resp.role); dev_dbg(typec->dev, "Role %d: 0x%hhx\n", port_num, resp.role);
dev_dbg(typec->dev, "Polarity %d: 0x%hhx\n", port_num, resp.polarity); dev_dbg(typec->dev, "Polarity %d: 0x%hhx\n", port_num, resp.polarity);
...@@ -973,27 +986,7 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num) ...@@ -973,27 +986,7 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)
if (typec->typec_cmd_supported) if (typec->typec_cmd_supported)
cros_typec_handle_status(typec, port_num); cros_typec_handle_status(typec, port_num);
/* Update the switches if they exist, according to requested state */ return 0;
ret = cros_typec_get_mux_info(typec, port_num, &mux_resp);
if (ret < 0) {
dev_warn(typec->dev,
"Failed to get mux info for port: %d, err = %d\n",
port_num, ret);
return 0;
}
/* No change needs to be made, let's exit early. */
if (typec->ports[port_num]->mux_flags == mux_resp.flags &&
typec->ports[port_num]->role == resp.role)
return 0;
typec->ports[port_num]->mux_flags = mux_resp.flags;
typec->ports[port_num]->role = resp.role;
ret = cros_typec_configure_mux(typec, port_num, mux_resp.flags, &resp);
if (ret)
dev_warn(typec->dev, "Configure muxes failed, err = %d\n", ret);
return ret;
} }
static int cros_typec_get_cmd_version(struct cros_typec_data *typec) static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
...@@ -1075,7 +1068,13 @@ static int cros_typec_probe(struct platform_device *pdev) ...@@ -1075,7 +1068,13 @@ static int cros_typec_probe(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
typec->dev = dev; typec->dev = dev;
typec->ec = dev_get_drvdata(pdev->dev.parent); typec->ec = dev_get_drvdata(pdev->dev.parent);
if (!typec->ec) {
dev_err(dev, "couldn't find parent EC device\n");
return -ENODEV;
}
platform_set_drvdata(pdev, typec); platform_set_drvdata(pdev, typec);
ret = cros_typec_get_cmd_version(typec); ret = cros_typec_get_cmd_version(typec);
......
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