Commit 9875b201 authored by Linus Torvalds's avatar Linus Torvalds

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

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

Pull chrome platform updates from Benson Leung:
 "cros_ec_typec:
   - Add notifier for update, and register port partner

  Sensors/iio:
   - Fixes to cros_ec_sensorhub around allocation of resources, and
     send_sample

  Wilco EC:
   - Fix to output format of h1_gpio

  Misc:
   - Misc fixes to appease kernel-doc and other warnings
   - Set user space log size in chromeos_pstore"

* tag 'tag-chrome-platform-for-v5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux:
  platform/chrome: cros_usbpd_logger: Add __printf annotation to append_str()
  platform/chrome: cros_ec_i2c: Appease the kernel-doc deity
  platform/chrome: typec: Fix ret value check error
  platform/chrome: cros_ec_typec: Register port partner
  platform/chrome: cros_ec_typec: Add struct for port data
  platform/chrome: cros_ec_typec: Use notifier for updates
  platform/chrome: cros_ec_ishtp: free ishtp buffer before sending event
  platform/chrome: cros_ec_ishtp: skip old cros_ec responses
  platform/chrome: wilco_ec: Provide correct output format to 'h1_gpio' file
  platform/chrome: chromeos_pstore: set user space log size
parents 0486a39a bbb7ad49
...@@ -217,6 +217,7 @@ config CROS_EC_SYSFS ...@@ -217,6 +217,7 @@ config CROS_EC_SYSFS
config CROS_EC_TYPEC 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
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
......
...@@ -57,6 +57,7 @@ static struct ramoops_platform_data chromeos_ramoops_data = { ...@@ -57,6 +57,7 @@ static struct ramoops_platform_data chromeos_ramoops_data = {
.record_size = 0x40000, .record_size = 0x40000,
.console_size = 0x20000, .console_size = 0x20000,
.ftrace_size = 0x20000, .ftrace_size = 0x20000,
.pmsg_size = 0x20000,
.max_reason = KMSG_DUMP_OOPS, .max_reason = KMSG_DUMP_OOPS,
}; };
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "cros_ec.h" #include "cros_ec.h"
/** /*
* Request format for protocol v3 * Request format for protocol v3
* byte 0 0xda (EC_COMMAND_PROTOCOL_3) * byte 0 0xda (EC_COMMAND_PROTOCOL_3)
* byte 1-8 struct ec_host_request * byte 1-8 struct ec_host_request
......
...@@ -48,7 +48,8 @@ static const guid_t cros_ish_guid = ...@@ -48,7 +48,8 @@ static const guid_t cros_ish_guid =
struct header { struct header {
u8 channel; u8 channel;
u8 status; u8 status;
u8 reserved[2]; u8 token;
u8 reserved;
} __packed; } __packed;
struct cros_ish_out_msg { struct cros_ish_out_msg {
...@@ -90,6 +91,7 @@ static DECLARE_RWSEM(init_lock); ...@@ -90,6 +91,7 @@ static DECLARE_RWSEM(init_lock);
* data exceeds this value, we log an error. * data exceeds this value, we log an error.
* @size: Actual size of data received from firmware. * @size: Actual size of data received from firmware.
* @error: 0 for success, negative error code for a failure in process_recv(). * @error: 0 for success, negative error code for a failure in process_recv().
* @token: Expected token for response that we are waiting on.
* @received: Set to true on receiving a valid firmware response to host command * @received: Set to true on receiving a valid firmware response to host command
* @wait_queue: Wait queue for host to wait for firmware response. * @wait_queue: Wait queue for host to wait for firmware response.
*/ */
...@@ -98,6 +100,7 @@ struct response_info { ...@@ -98,6 +100,7 @@ struct response_info {
size_t max_size; size_t max_size;
size_t size; size_t size;
int error; int error;
u8 token;
bool received; bool received;
wait_queue_head_t wait_queue; wait_queue_head_t wait_queue;
}; };
...@@ -162,6 +165,7 @@ static int ish_send(struct ishtp_cl_data *client_data, ...@@ -162,6 +165,7 @@ static int ish_send(struct ishtp_cl_data *client_data,
u8 *out_msg, size_t out_size, u8 *out_msg, size_t out_size,
u8 *in_msg, size_t in_size) u8 *in_msg, size_t in_size)
{ {
static u8 next_token;
int rv; int rv;
struct header *out_hdr = (struct header *)out_msg; struct header *out_hdr = (struct header *)out_msg;
struct ishtp_cl *cros_ish_cl = client_data->cros_ish_cl; struct ishtp_cl *cros_ish_cl = client_data->cros_ish_cl;
...@@ -174,8 +178,11 @@ static int ish_send(struct ishtp_cl_data *client_data, ...@@ -174,8 +178,11 @@ static int ish_send(struct ishtp_cl_data *client_data,
client_data->response.data = in_msg; client_data->response.data = in_msg;
client_data->response.max_size = in_size; client_data->response.max_size = in_size;
client_data->response.error = 0; client_data->response.error = 0;
client_data->response.token = next_token++;
client_data->response.received = false; client_data->response.received = false;
out_hdr->token = client_data->response.token;
rv = ishtp_cl_send(cros_ish_cl, out_msg, out_size); rv = ishtp_cl_send(cros_ish_cl, out_msg, out_size);
if (rv) { if (rv) {
dev_err(cl_data_to_dev(client_data), dev_err(cl_data_to_dev(client_data),
...@@ -249,17 +256,23 @@ static void process_recv(struct ishtp_cl *cros_ish_cl, ...@@ -249,17 +256,23 @@ static void process_recv(struct ishtp_cl *cros_ish_cl,
switch (in_msg->hdr.channel) { switch (in_msg->hdr.channel) {
case CROS_EC_COMMAND: case CROS_EC_COMMAND:
/* Sanity check */ if (client_data->response.received) {
if (!client_data->response.data) {
dev_err(dev, dev_err(dev,
"Receiving buffer is null. Should be allocated by calling function\n"); "Previous firmware message not yet processed\n");
client_data->response.error = -EINVAL; goto end_error;
goto error_wake_up;
} }
if (client_data->response.received) { if (client_data->response.token != in_msg->hdr.token) {
dev_err_ratelimited(dev,
"Dropping old response token %d\n",
in_msg->hdr.token);
goto end_error;
}
/* Sanity check */
if (!client_data->response.data) {
dev_err(dev, dev_err(dev,
"Previous firmware message not yet processed\n"); "Receiving buffer is null. Should be allocated by calling function\n");
client_data->response.error = -EINVAL; client_data->response.error = -EINVAL;
goto error_wake_up; goto error_wake_up;
} }
...@@ -289,21 +302,28 @@ static void process_recv(struct ishtp_cl *cros_ish_cl, ...@@ -289,21 +302,28 @@ static void process_recv(struct ishtp_cl *cros_ish_cl,
memcpy(client_data->response.data, memcpy(client_data->response.data,
rb_in_proc->buffer.data, data_len); rb_in_proc->buffer.data, data_len);
error_wake_up:
/* Free the buffer since we copied data or didn't need it */
ishtp_cl_io_rb_recycle(rb_in_proc);
rb_in_proc = NULL;
/* Set flag before waking up the caller */ /* Set flag before waking up the caller */
client_data->response.received = true; client_data->response.received = true;
error_wake_up:
/* Wake the calling thread */ /* Wake the calling thread */
wake_up_interruptible(&client_data->response.wait_queue); wake_up_interruptible(&client_data->response.wait_queue);
break; break;
case CROS_MKBP_EVENT: case CROS_MKBP_EVENT:
/* Free the buffer. This is just an event without data */
ishtp_cl_io_rb_recycle(rb_in_proc);
rb_in_proc = NULL;
/* /*
* Set timestamp from beginning of function since we actually * Set timestamp from beginning of function since we actually
* got an incoming MKBP event * got an incoming MKBP event
*/ */
client_data->ec_dev->last_event_time = timestamp; client_data->ec_dev->last_event_time = timestamp;
/* The event system doesn't send any data in buffer */
schedule_work(&client_data->work_ec_evt); schedule_work(&client_data->work_ec_evt);
break; break;
...@@ -313,8 +333,9 @@ static void process_recv(struct ishtp_cl *cros_ish_cl, ...@@ -313,8 +333,9 @@ static void process_recv(struct ishtp_cl *cros_ish_cl,
} }
end_error: end_error:
/* Free the buffer */ /* Free the buffer if we already haven't */
ishtp_cl_io_rb_recycle(rb_in_proc); if (rb_in_proc)
ishtp_cl_io_rb_recycle(rb_in_proc);
up_read(&init_lock); up_read(&init_lock);
} }
......
...@@ -11,11 +11,22 @@ ...@@ -11,11 +11,22 @@
#include <linux/of.h> #include <linux/of.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_usbpd_notify.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/usb/typec.h> #include <linux/usb/typec.h>
#define DRV_NAME "cros-ec-typec" #define DRV_NAME "cros-ec-typec"
/* Per port data. */
struct cros_typec_port {
struct typec_port *port;
/* Initial capabilities for the port. */
struct typec_capability caps;
struct typec_partner *partner;
/* Port partner PD identity info. */
struct usb_pd_identity p_identity;
};
/* Platform-specific data for the Chrome OS EC Type C controller. */ /* Platform-specific data for the Chrome OS EC Type C controller. */
struct cros_typec_data { struct cros_typec_data {
struct device *dev; struct device *dev;
...@@ -23,9 +34,8 @@ struct cros_typec_data { ...@@ -23,9 +34,8 @@ struct cros_typec_data {
int num_ports; int num_ports;
unsigned int cmd_ver; unsigned int cmd_ver;
/* Array of ports, indexed by port number. */ /* Array of ports, indexed by port number. */
struct typec_port *ports[EC_USB_PD_MAX_PORTS]; struct cros_typec_port *ports[EC_USB_PD_MAX_PORTS];
/* Initial capabilities for each port. */ struct notifier_block nb;
struct typec_capability *caps[EC_USB_PD_MAX_PORTS];
}; };
static int cros_typec_parse_port_props(struct typec_capability *cap, static int cros_typec_parse_port_props(struct typec_capability *cap,
...@@ -74,14 +84,25 @@ static int cros_typec_parse_port_props(struct typec_capability *cap, ...@@ -74,14 +84,25 @@ static int cros_typec_parse_port_props(struct typec_capability *cap,
return 0; return 0;
} }
static void cros_unregister_ports(struct cros_typec_data *typec)
{
int i;
for (i = 0; i < typec->num_ports; i++) {
if (!typec->ports[i])
continue;
typec_unregister_port(typec->ports[i]->port);
}
}
static int cros_typec_init_ports(struct cros_typec_data *typec) static int cros_typec_init_ports(struct cros_typec_data *typec)
{ {
struct device *dev = typec->dev; struct device *dev = typec->dev;
struct typec_capability *cap; struct typec_capability *cap;
struct fwnode_handle *fwnode; struct fwnode_handle *fwnode;
struct cros_typec_port *cros_port;
const char *port_prop; const char *port_prop;
int ret; int ret;
int i;
int nports; int nports;
u32 port_num = 0; u32 port_num = 0;
...@@ -113,22 +134,23 @@ static int cros_typec_init_ports(struct cros_typec_data *typec) ...@@ -113,22 +134,23 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
dev_dbg(dev, "Registering port %d\n", port_num); dev_dbg(dev, "Registering port %d\n", port_num);
cap = devm_kzalloc(dev, sizeof(*cap), GFP_KERNEL); cros_port = devm_kzalloc(dev, sizeof(*cros_port), GFP_KERNEL);
if (!cap) { if (!cros_port) {
ret = -ENOMEM; ret = -ENOMEM;
goto unregister_ports; goto unregister_ports;
} }
typec->caps[port_num] = cap; typec->ports[port_num] = cros_port;
cap = &cros_port->caps;
ret = cros_typec_parse_port_props(cap, fwnode, dev); ret = cros_typec_parse_port_props(cap, fwnode, dev);
if (ret < 0) if (ret < 0)
goto unregister_ports; goto unregister_ports;
typec->ports[port_num] = typec_register_port(dev, cap); cros_port->port = typec_register_port(dev, cap);
if (IS_ERR(typec->ports[port_num])) { if (IS_ERR(cros_port->port)) {
dev_err(dev, "Failed to register port %d\n", port_num); dev_err(dev, "Failed to register port %d\n", port_num);
ret = PTR_ERR(typec->ports[port_num]); ret = PTR_ERR(cros_port->port);
goto unregister_ports; goto unregister_ports;
} }
} }
...@@ -136,8 +158,7 @@ static int cros_typec_init_ports(struct cros_typec_data *typec) ...@@ -136,8 +158,7 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
return 0; return 0;
unregister_ports: unregister_ports:
for (i = 0; i < typec->num_ports; i++) cros_unregister_ports(typec);
typec_unregister_port(typec->ports[i]);
return ret; return ret;
} }
...@@ -172,10 +193,34 @@ static int cros_typec_ec_command(struct cros_typec_data *typec, ...@@ -172,10 +193,34 @@ static int cros_typec_ec_command(struct cros_typec_data *typec,
return ret; return ret;
} }
static int cros_typec_add_partner(struct cros_typec_data *typec, int port_num,
bool pd_en)
{
struct cros_typec_port *port = typec->ports[port_num];
struct typec_partner_desc p_desc = {
.usb_pd = pd_en,
};
int ret = 0;
/*
* Fill an initial PD identity, which will then be updated with info
* from the EC.
*/
p_desc.identity = &port->p_identity;
port->partner = typec_register_partner(port->port, &p_desc);
if (IS_ERR(port->partner)) {
ret = PTR_ERR(port->partner);
port->partner = NULL;
}
return ret;
}
static void cros_typec_set_port_params_v0(struct cros_typec_data *typec, static void cros_typec_set_port_params_v0(struct cros_typec_data *typec,
int port_num, struct ec_response_usb_pd_control *resp) int port_num, struct ec_response_usb_pd_control *resp)
{ {
struct typec_port *port = typec->ports[port_num]; struct typec_port *port = typec->ports[port_num]->port;
enum typec_orientation polarity; enum typec_orientation polarity;
if (!resp->enabled) if (!resp->enabled)
...@@ -192,8 +237,10 @@ static void cros_typec_set_port_params_v0(struct cros_typec_data *typec, ...@@ -192,8 +237,10 @@ static void cros_typec_set_port_params_v0(struct cros_typec_data *typec,
static void cros_typec_set_port_params_v1(struct cros_typec_data *typec, static void cros_typec_set_port_params_v1(struct cros_typec_data *typec,
int port_num, struct ec_response_usb_pd_control_v1 *resp) int port_num, struct ec_response_usb_pd_control_v1 *resp)
{ {
struct typec_port *port = typec->ports[port_num]; struct typec_port *port = typec->ports[port_num]->port;
enum typec_orientation polarity; enum typec_orientation polarity;
bool pd_en;
int ret;
if (!(resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED)) if (!(resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED))
polarity = TYPEC_ORIENTATION_NONE; polarity = TYPEC_ORIENTATION_NONE;
...@@ -208,6 +255,25 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec, ...@@ -208,6 +255,25 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec,
TYPEC_SOURCE : TYPEC_SINK); TYPEC_SOURCE : TYPEC_SINK);
typec_set_vconn_role(port, resp->role & PD_CTRL_RESP_ROLE_VCONN ? typec_set_vconn_role(port, resp->role & PD_CTRL_RESP_ROLE_VCONN ?
TYPEC_SOURCE : TYPEC_SINK); TYPEC_SOURCE : TYPEC_SINK);
/* Register/remove partners when a connect/disconnect occurs. */
if (resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED) {
if (typec->ports[port_num]->partner)
return;
pd_en = resp->enabled & PD_CTRL_RESP_ENABLED_PD_CAPABLE;
ret = cros_typec_add_partner(typec, port_num, pd_en);
if (ret)
dev_warn(typec->dev,
"Failed to register partner on port: %d\n",
port_num);
} else {
if (!typec->ports[port_num]->partner)
return;
typec_unregister_partner(typec->ports[port_num]->partner);
typec->ports[port_num]->partner = NULL;
}
} }
static int cros_typec_port_update(struct cros_typec_data *typec, int port_num) static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)
...@@ -272,6 +338,22 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec) ...@@ -272,6 +338,22 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
return 0; return 0;
} }
static int cros_ec_typec_event(struct notifier_block *nb,
unsigned long host_event, void *_notify)
{
struct cros_typec_data *typec = container_of(nb, struct cros_typec_data,
nb);
int ret, i;
for (i = 0; i < typec->num_ports; i++) {
ret = cros_typec_port_update(typec, i);
if (ret < 0)
dev_warn(typec->dev, "Update failed for port: %d\n", i);
}
return NOTIFY_OK;
}
#ifdef CONFIG_ACPI #ifdef CONFIG_ACPI
static const struct acpi_device_id cros_typec_acpi_id[] = { static const struct acpi_device_id cros_typec_acpi_id[] = {
{ "GOOG0014", 0 }, { "GOOG0014", 0 },
...@@ -332,12 +414,15 @@ static int cros_typec_probe(struct platform_device *pdev) ...@@ -332,12 +414,15 @@ static int cros_typec_probe(struct platform_device *pdev)
goto unregister_ports; goto unregister_ports;
} }
typec->nb.notifier_call = cros_ec_typec_event;
ret = cros_usbpd_register_notify(&typec->nb);
if (ret < 0)
goto unregister_ports;
return 0; return 0;
unregister_ports: unregister_ports:
for (i = 0; i < typec->num_ports; i++) cros_unregister_ports(typec);
if (typec->ports[i])
typec_unregister_port(typec->ports[i]);
return ret; return ret;
} }
......
...@@ -46,6 +46,7 @@ static const char * const fault_names[] = { ...@@ -46,6 +46,7 @@ static const char * const fault_names[] = {
"---", "OCP", "fast OCP", "OVP", "Discharge" "---", "OCP", "fast OCP", "OVP", "Discharge"
}; };
__printf(3, 4)
static int append_str(char *buf, int pos, const char *fmt, ...) static int append_str(char *buf, int pos, const char *fmt, ...)
{ {
va_list args; va_list args;
......
...@@ -208,7 +208,12 @@ static int send_ec_cmd(struct wilco_ec_device *ec, u8 sub_cmd, u8 *out_val) ...@@ -208,7 +208,12 @@ static int send_ec_cmd(struct wilco_ec_device *ec, u8 sub_cmd, u8 *out_val)
*/ */
static int h1_gpio_get(void *arg, u64 *val) static int h1_gpio_get(void *arg, u64 *val)
{ {
return send_ec_cmd(arg, SUB_CMD_H1_GPIO, (u8 *)val); int ret;
ret = send_ec_cmd(arg, SUB_CMD_H1_GPIO, (u8 *)val);
if (ret == 0)
*val &= 0xFF;
return ret;
} }
DEFINE_DEBUGFS_ATTRIBUTE(fops_h1_gpio, h1_gpio_get, NULL, "0x%02llx\n"); DEFINE_DEBUGFS_ATTRIBUTE(fops_h1_gpio, h1_gpio_get, NULL, "0x%02llx\n");
......
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