Skip to content

Commit 9875b20

Browse files
committed
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
2 parents 0486a39 + bbb7ad4 commit 9875b20

File tree

7 files changed

+145
-31
lines changed

7 files changed

+145
-31
lines changed

drivers/platform/chrome/Kconfig

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

drivers/platform/chrome/chromeos_pstore.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static struct ramoops_platform_data chromeos_ramoops_data = {
5757
.record_size = 0x40000,
5858
.console_size = 0x20000,
5959
.ftrace_size = 0x20000,
60+
.pmsg_size = 0x20000,
6061
.max_reason = KMSG_DUMP_OOPS,
6162
};
6263

drivers/platform/chrome/cros_ec_i2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include "cros_ec.h"
1818

19-
/**
19+
/*
2020
* Request format for protocol v3
2121
* byte 0 0xda (EC_COMMAND_PROTOCOL_3)
2222
* byte 1-8 struct ec_host_request

drivers/platform/chrome/cros_ec_ishtp.c

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ static const guid_t cros_ish_guid =
4848
struct header {
4949
u8 channel;
5050
u8 status;
51-
u8 reserved[2];
51+
u8 token;
52+
u8 reserved;
5253
} __packed;
5354

5455
struct cros_ish_out_msg {
@@ -90,6 +91,7 @@ static DECLARE_RWSEM(init_lock);
9091
* data exceeds this value, we log an error.
9192
* @size: Actual size of data received from firmware.
9293
* @error: 0 for success, negative error code for a failure in process_recv().
94+
* @token: Expected token for response that we are waiting on.
9395
* @received: Set to true on receiving a valid firmware response to host command
9496
* @wait_queue: Wait queue for host to wait for firmware response.
9597
*/
@@ -98,6 +100,7 @@ struct response_info {
98100
size_t max_size;
99101
size_t size;
100102
int error;
103+
u8 token;
101104
bool received;
102105
wait_queue_head_t wait_queue;
103106
};
@@ -162,6 +165,7 @@ static int ish_send(struct ishtp_cl_data *client_data,
162165
u8 *out_msg, size_t out_size,
163166
u8 *in_msg, size_t in_size)
164167
{
168+
static u8 next_token;
165169
int rv;
166170
struct header *out_hdr = (struct header *)out_msg;
167171
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,
174178
client_data->response.data = in_msg;
175179
client_data->response.max_size = in_size;
176180
client_data->response.error = 0;
181+
client_data->response.token = next_token++;
177182
client_data->response.received = false;
178183

184+
out_hdr->token = client_data->response.token;
185+
179186
rv = ishtp_cl_send(cros_ish_cl, out_msg, out_size);
180187
if (rv) {
181188
dev_err(cl_data_to_dev(client_data),
@@ -249,17 +256,23 @@ static void process_recv(struct ishtp_cl *cros_ish_cl,
249256

250257
switch (in_msg->hdr.channel) {
251258
case CROS_EC_COMMAND:
252-
/* Sanity check */
253-
if (!client_data->response.data) {
259+
if (client_data->response.received) {
254260
dev_err(dev,
255-
"Receiving buffer is null. Should be allocated by calling function\n");
256-
client_data->response.error = -EINVAL;
257-
goto error_wake_up;
261+
"Previous firmware message not yet processed\n");
262+
goto end_error;
258263
}
259264

260-
if (client_data->response.received) {
265+
if (client_data->response.token != in_msg->hdr.token) {
266+
dev_err_ratelimited(dev,
267+
"Dropping old response token %d\n",
268+
in_msg->hdr.token);
269+
goto end_error;
270+
}
271+
272+
/* Sanity check */
273+
if (!client_data->response.data) {
261274
dev_err(dev,
262-
"Previous firmware message not yet processed\n");
275+
"Receiving buffer is null. Should be allocated by calling function\n");
263276
client_data->response.error = -EINVAL;
264277
goto error_wake_up;
265278
}
@@ -289,21 +302,28 @@ static void process_recv(struct ishtp_cl *cros_ish_cl,
289302
memcpy(client_data->response.data,
290303
rb_in_proc->buffer.data, data_len);
291304

305+
error_wake_up:
306+
/* Free the buffer since we copied data or didn't need it */
307+
ishtp_cl_io_rb_recycle(rb_in_proc);
308+
rb_in_proc = NULL;
309+
292310
/* Set flag before waking up the caller */
293311
client_data->response.received = true;
294-
error_wake_up:
312+
295313
/* Wake the calling thread */
296314
wake_up_interruptible(&client_data->response.wait_queue);
297315

298316
break;
299317

300318
case CROS_MKBP_EVENT:
319+
/* Free the buffer. This is just an event without data */
320+
ishtp_cl_io_rb_recycle(rb_in_proc);
321+
rb_in_proc = NULL;
301322
/*
302323
* Set timestamp from beginning of function since we actually
303324
* got an incoming MKBP event
304325
*/
305326
client_data->ec_dev->last_event_time = timestamp;
306-
/* The event system doesn't send any data in buffer */
307327
schedule_work(&client_data->work_ec_evt);
308328

309329
break;
@@ -313,8 +333,9 @@ static void process_recv(struct ishtp_cl *cros_ish_cl,
313333
}
314334

315335
end_error:
316-
/* Free the buffer */
317-
ishtp_cl_io_rb_recycle(rb_in_proc);
336+
/* Free the buffer if we already haven't */
337+
if (rb_in_proc)
338+
ishtp_cl_io_rb_recycle(rb_in_proc);
318339

319340
up_read(&init_lock);
320341
}

drivers/platform/chrome/cros_ec_typec.c

Lines changed: 102 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,31 @@
1111
#include <linux/of.h>
1212
#include <linux/platform_data/cros_ec_commands.h>
1313
#include <linux/platform_data/cros_ec_proto.h>
14+
#include <linux/platform_data/cros_usbpd_notify.h>
1415
#include <linux/platform_device.h>
1516
#include <linux/usb/typec.h>
1617

1718
#define DRV_NAME "cros-ec-typec"
1819

20+
/* Per port data. */
21+
struct cros_typec_port {
22+
struct typec_port *port;
23+
/* Initial capabilities for the port. */
24+
struct typec_capability caps;
25+
struct typec_partner *partner;
26+
/* Port partner PD identity info. */
27+
struct usb_pd_identity p_identity;
28+
};
29+
1930
/* Platform-specific data for the Chrome OS EC Type C controller. */
2031
struct cros_typec_data {
2132
struct device *dev;
2233
struct cros_ec_device *ec;
2334
int num_ports;
2435
unsigned int cmd_ver;
2536
/* Array of ports, indexed by port number. */
26-
struct typec_port *ports[EC_USB_PD_MAX_PORTS];
27-
/* Initial capabilities for each port. */
28-
struct typec_capability *caps[EC_USB_PD_MAX_PORTS];
37+
struct cros_typec_port *ports[EC_USB_PD_MAX_PORTS];
38+
struct notifier_block nb;
2939
};
3040

3141
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,
7484
return 0;
7585
}
7686

87+
static void cros_unregister_ports(struct cros_typec_data *typec)
88+
{
89+
int i;
90+
91+
for (i = 0; i < typec->num_ports; i++) {
92+
if (!typec->ports[i])
93+
continue;
94+
typec_unregister_port(typec->ports[i]->port);
95+
}
96+
}
97+
7798
static int cros_typec_init_ports(struct cros_typec_data *typec)
7899
{
79100
struct device *dev = typec->dev;
80101
struct typec_capability *cap;
81102
struct fwnode_handle *fwnode;
103+
struct cros_typec_port *cros_port;
82104
const char *port_prop;
83105
int ret;
84-
int i;
85106
int nports;
86107
u32 port_num = 0;
87108

@@ -113,31 +134,31 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
113134

114135
dev_dbg(dev, "Registering port %d\n", port_num);
115136

116-
cap = devm_kzalloc(dev, sizeof(*cap), GFP_KERNEL);
117-
if (!cap) {
137+
cros_port = devm_kzalloc(dev, sizeof(*cros_port), GFP_KERNEL);
138+
if (!cros_port) {
118139
ret = -ENOMEM;
119140
goto unregister_ports;
120141
}
121142

122-
typec->caps[port_num] = cap;
143+
typec->ports[port_num] = cros_port;
144+
cap = &cros_port->caps;
123145

124146
ret = cros_typec_parse_port_props(cap, fwnode, dev);
125147
if (ret < 0)
126148
goto unregister_ports;
127149

128-
typec->ports[port_num] = typec_register_port(dev, cap);
129-
if (IS_ERR(typec->ports[port_num])) {
150+
cros_port->port = typec_register_port(dev, cap);
151+
if (IS_ERR(cros_port->port)) {
130152
dev_err(dev, "Failed to register port %d\n", port_num);
131-
ret = PTR_ERR(typec->ports[port_num]);
153+
ret = PTR_ERR(cros_port->port);
132154
goto unregister_ports;
133155
}
134156
}
135157

136158
return 0;
137159

138160
unregister_ports:
139-
for (i = 0; i < typec->num_ports; i++)
140-
typec_unregister_port(typec->ports[i]);
161+
cros_unregister_ports(typec);
141162
return ret;
142163
}
143164

@@ -172,10 +193,34 @@ static int cros_typec_ec_command(struct cros_typec_data *typec,
172193
return ret;
173194
}
174195

196+
static int cros_typec_add_partner(struct cros_typec_data *typec, int port_num,
197+
bool pd_en)
198+
{
199+
struct cros_typec_port *port = typec->ports[port_num];
200+
struct typec_partner_desc p_desc = {
201+
.usb_pd = pd_en,
202+
};
203+
int ret = 0;
204+
205+
/*
206+
* Fill an initial PD identity, which will then be updated with info
207+
* from the EC.
208+
*/
209+
p_desc.identity = &port->p_identity;
210+
211+
port->partner = typec_register_partner(port->port, &p_desc);
212+
if (IS_ERR(port->partner)) {
213+
ret = PTR_ERR(port->partner);
214+
port->partner = NULL;
215+
}
216+
217+
return ret;
218+
}
219+
175220
static void cros_typec_set_port_params_v0(struct cros_typec_data *typec,
176221
int port_num, struct ec_response_usb_pd_control *resp)
177222
{
178-
struct typec_port *port = typec->ports[port_num];
223+
struct typec_port *port = typec->ports[port_num]->port;
179224
enum typec_orientation polarity;
180225

181226
if (!resp->enabled)
@@ -192,8 +237,10 @@ static void cros_typec_set_port_params_v0(struct cros_typec_data *typec,
192237
static void cros_typec_set_port_params_v1(struct cros_typec_data *typec,
193238
int port_num, struct ec_response_usb_pd_control_v1 *resp)
194239
{
195-
struct typec_port *port = typec->ports[port_num];
240+
struct typec_port *port = typec->ports[port_num]->port;
196241
enum typec_orientation polarity;
242+
bool pd_en;
243+
int ret;
197244

198245
if (!(resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED))
199246
polarity = TYPEC_ORIENTATION_NONE;
@@ -208,6 +255,25 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec,
208255
TYPEC_SOURCE : TYPEC_SINK);
209256
typec_set_vconn_role(port, resp->role & PD_CTRL_RESP_ROLE_VCONN ?
210257
TYPEC_SOURCE : TYPEC_SINK);
258+
259+
/* Register/remove partners when a connect/disconnect occurs. */
260+
if (resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED) {
261+
if (typec->ports[port_num]->partner)
262+
return;
263+
264+
pd_en = resp->enabled & PD_CTRL_RESP_ENABLED_PD_CAPABLE;
265+
ret = cros_typec_add_partner(typec, port_num, pd_en);
266+
if (ret)
267+
dev_warn(typec->dev,
268+
"Failed to register partner on port: %d\n",
269+
port_num);
270+
} else {
271+
if (!typec->ports[port_num]->partner)
272+
return;
273+
274+
typec_unregister_partner(typec->ports[port_num]->partner);
275+
typec->ports[port_num]->partner = NULL;
276+
}
211277
}
212278

213279
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)
272338
return 0;
273339
}
274340

341+
static int cros_ec_typec_event(struct notifier_block *nb,
342+
unsigned long host_event, void *_notify)
343+
{
344+
struct cros_typec_data *typec = container_of(nb, struct cros_typec_data,
345+
nb);
346+
int ret, i;
347+
348+
for (i = 0; i < typec->num_ports; i++) {
349+
ret = cros_typec_port_update(typec, i);
350+
if (ret < 0)
351+
dev_warn(typec->dev, "Update failed for port: %d\n", i);
352+
}
353+
354+
return NOTIFY_OK;
355+
}
356+
275357
#ifdef CONFIG_ACPI
276358
static const struct acpi_device_id cros_typec_acpi_id[] = {
277359
{ "GOOG0014", 0 },
@@ -332,12 +414,15 @@ static int cros_typec_probe(struct platform_device *pdev)
332414
goto unregister_ports;
333415
}
334416

417+
typec->nb.notifier_call = cros_ec_typec_event;
418+
ret = cros_usbpd_register_notify(&typec->nb);
419+
if (ret < 0)
420+
goto unregister_ports;
421+
335422
return 0;
336423

337424
unregister_ports:
338-
for (i = 0; i < typec->num_ports; i++)
339-
if (typec->ports[i])
340-
typec_unregister_port(typec->ports[i]);
425+
cros_unregister_ports(typec);
341426
return ret;
342427
}
343428

drivers/platform/chrome/cros_usbpd_logger.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static const char * const fault_names[] = {
4646
"---", "OCP", "fast OCP", "OVP", "Discharge"
4747
};
4848

49+
__printf(3, 4)
4950
static int append_str(char *buf, int pos, const char *fmt, ...)
5051
{
5152
va_list args;

drivers/platform/chrome/wilco_ec/debugfs.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,12 @@ static int send_ec_cmd(struct wilco_ec_device *ec, u8 sub_cmd, u8 *out_val)
208208
*/
209209
static int h1_gpio_get(void *arg, u64 *val)
210210
{
211-
return send_ec_cmd(arg, SUB_CMD_H1_GPIO, (u8 *)val);
211+
int ret;
212+
213+
ret = send_ec_cmd(arg, SUB_CMD_H1_GPIO, (u8 *)val);
214+
if (ret == 0)
215+
*val &= 0xFF;
216+
return ret;
212217
}
213218

214219
DEFINE_DEBUGFS_ATTRIBUTE(fops_h1_gpio, h1_gpio_get, NULL, "0x%02llx\n");

0 commit comments

Comments
 (0)