diff options
author | Shawn Nematbakhsh <shawnn@chromium.org> | 2018-03-23 13:42:46 -0400 |
---|---|---|
committer | Benson Leung <bleung@chromium.org> | 2018-04-11 01:24:51 -0400 |
commit | b082b2e1454c3e0217d7cf70f2211966c3d54301 (patch) | |
tree | b6cf2291b8e252388144df16bbd6c65363f7f8cb /drivers/platform | |
parent | f63192800ebd01099d3487f7fef1dd0ee0b18b45 (diff) |
platform/chrome: cros_ec_debugfs: Add PD port info to debugfs
Add info useful for debugging USB-PD port state.
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Benson Leung <bleung@chromium.org>
Diffstat (limited to 'drivers/platform')
-rw-r--r-- | drivers/platform/chrome/cros_ec_debugfs.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/drivers/platform/chrome/cros_ec_debugfs.c b/drivers/platform/chrome/cros_ec_debugfs.c index 539403022568..cc265ed8deb7 100644 --- a/drivers/platform/chrome/cros_ec_debugfs.c +++ b/drivers/platform/chrome/cros_ec_debugfs.c | |||
@@ -211,6 +211,58 @@ static int cros_ec_console_log_release(struct inode *inode, struct file *file) | |||
211 | return 0; | 211 | return 0; |
212 | } | 212 | } |
213 | 213 | ||
214 | static ssize_t cros_ec_pdinfo_read(struct file *file, | ||
215 | char __user *user_buf, | ||
216 | size_t count, | ||
217 | loff_t *ppos) | ||
218 | { | ||
219 | char read_buf[EC_USB_PD_MAX_PORTS * 40], *p = read_buf; | ||
220 | struct cros_ec_debugfs *debug_info = file->private_data; | ||
221 | struct cros_ec_device *ec_dev = debug_info->ec->ec_dev; | ||
222 | struct { | ||
223 | struct cros_ec_command msg; | ||
224 | union { | ||
225 | struct ec_response_usb_pd_control_v1 resp; | ||
226 | struct ec_params_usb_pd_control params; | ||
227 | }; | ||
228 | } __packed ec_buf; | ||
229 | struct cros_ec_command *msg; | ||
230 | struct ec_response_usb_pd_control_v1 *resp; | ||
231 | struct ec_params_usb_pd_control *params; | ||
232 | int i; | ||
233 | |||
234 | msg = &ec_buf.msg; | ||
235 | params = (struct ec_params_usb_pd_control *)msg->data; | ||
236 | resp = (struct ec_response_usb_pd_control_v1 *)msg->data; | ||
237 | |||
238 | msg->command = EC_CMD_USB_PD_CONTROL; | ||
239 | msg->version = 1; | ||
240 | msg->insize = sizeof(*resp); | ||
241 | msg->outsize = sizeof(*params); | ||
242 | |||
243 | /* | ||
244 | * Read status from all PD ports until failure, typically caused | ||
245 | * by attempting to read status on a port that doesn't exist. | ||
246 | */ | ||
247 | for (i = 0; i < EC_USB_PD_MAX_PORTS; ++i) { | ||
248 | params->port = i; | ||
249 | params->role = 0; | ||
250 | params->mux = 0; | ||
251 | params->swap = 0; | ||
252 | |||
253 | if (cros_ec_cmd_xfer_status(ec_dev, msg) < 0) | ||
254 | break; | ||
255 | |||
256 | p += scnprintf(p, sizeof(read_buf) + read_buf - p, | ||
257 | "p%d: %s en:%.2x role:%.2x pol:%.2x\n", i, | ||
258 | resp->state, resp->enabled, resp->role, | ||
259 | resp->polarity); | ||
260 | } | ||
261 | |||
262 | return simple_read_from_buffer(user_buf, count, ppos, | ||
263 | read_buf, p - read_buf); | ||
264 | } | ||
265 | |||
214 | const struct file_operations cros_ec_console_log_fops = { | 266 | const struct file_operations cros_ec_console_log_fops = { |
215 | .owner = THIS_MODULE, | 267 | .owner = THIS_MODULE, |
216 | .open = cros_ec_console_log_open, | 268 | .open = cros_ec_console_log_open, |
@@ -220,6 +272,13 @@ const struct file_operations cros_ec_console_log_fops = { | |||
220 | .release = cros_ec_console_log_release, | 272 | .release = cros_ec_console_log_release, |
221 | }; | 273 | }; |
222 | 274 | ||
275 | const struct file_operations cros_ec_pdinfo_fops = { | ||
276 | .owner = THIS_MODULE, | ||
277 | .open = simple_open, | ||
278 | .read = cros_ec_pdinfo_read, | ||
279 | .llseek = default_llseek, | ||
280 | }; | ||
281 | |||
223 | static int ec_read_version_supported(struct cros_ec_dev *ec) | 282 | static int ec_read_version_supported(struct cros_ec_dev *ec) |
224 | { | 283 | { |
225 | struct ec_params_get_cmd_versions_v1 *params; | 284 | struct ec_params_get_cmd_versions_v1 *params; |
@@ -355,6 +414,15 @@ free: | |||
355 | return ret; | 414 | return ret; |
356 | } | 415 | } |
357 | 416 | ||
417 | static int cros_ec_create_pdinfo(struct cros_ec_debugfs *debug_info) | ||
418 | { | ||
419 | if (!debugfs_create_file("pdinfo", 0444, debug_info->dir, debug_info, | ||
420 | &cros_ec_pdinfo_fops)) | ||
421 | return -ENOMEM; | ||
422 | |||
423 | return 0; | ||
424 | } | ||
425 | |||
358 | int cros_ec_debugfs_init(struct cros_ec_dev *ec) | 426 | int cros_ec_debugfs_init(struct cros_ec_dev *ec) |
359 | { | 427 | { |
360 | struct cros_ec_platform *ec_platform = dev_get_platdata(ec->dev); | 428 | struct cros_ec_platform *ec_platform = dev_get_platdata(ec->dev); |
@@ -379,6 +447,10 @@ int cros_ec_debugfs_init(struct cros_ec_dev *ec) | |||
379 | if (ret) | 447 | if (ret) |
380 | goto remove_debugfs; | 448 | goto remove_debugfs; |
381 | 449 | ||
450 | ret = cros_ec_create_pdinfo(debug_info); | ||
451 | if (ret) | ||
452 | goto remove_debugfs; | ||
453 | |||
382 | ec->debug_info = debug_info; | 454 | ec->debug_info = debug_info; |
383 | 455 | ||
384 | return 0; | 456 | return 0; |