1 // SPDX-License-Identifier: GPL-2.0
3 * UCSI debugfs interface
5 * Copyright (C) 2023 Intel Corporation
7 * Authors: Rajaram Regupathy <rajaram.regupathy@intel.com>
8 * Gopal Saranya <saranya.gopal@intel.com>
10 #include <linux/debugfs.h>
11 #include <linux/slab.h>
12 #include <linux/string.h>
13 #include <linux/types.h>
14 #include <linux/usb.h>
16 #include <asm/errno.h>
20 static struct dentry *ucsi_debugfs_root;
22 static int ucsi_cmd(void *data, u64 val)
24 struct ucsi *ucsi = data;
27 memset(&ucsi->debugfs->response, 0, sizeof(ucsi->debugfs->response));
28 ucsi->debugfs->status = 0;
30 switch (UCSI_COMMAND(val)) {
34 case UCSI_CONNECTOR_RESET:
35 ret = ucsi_send_command(ucsi, val, NULL, 0);
37 case UCSI_GET_CAPABILITY:
38 case UCSI_GET_CONNECTOR_CAPABILITY:
39 case UCSI_GET_ALTERNATE_MODES:
40 case UCSI_GET_CURRENT_CAM:
42 case UCSI_GET_CABLE_PROPERTY:
43 case UCSI_GET_CONNECTOR_STATUS:
44 ret = ucsi_send_command(ucsi, val,
45 &ucsi->debugfs->response,
46 sizeof(ucsi->debugfs->response));
53 ucsi->debugfs->status = ret;
59 DEFINE_DEBUGFS_ATTRIBUTE(ucsi_cmd_fops, NULL, ucsi_cmd, "0x%llx\n");
61 static int ucsi_resp_show(struct seq_file *s, void *not_used)
63 struct ucsi *ucsi = s->private;
65 if (ucsi->debugfs->status)
66 return ucsi->debugfs->status;
68 seq_printf(s, "0x%016llx%016llx\n", ucsi->debugfs->response.high,
69 ucsi->debugfs->response.low);
72 DEFINE_SHOW_ATTRIBUTE(ucsi_resp);
74 void ucsi_debugfs_register(struct ucsi *ucsi)
76 ucsi->debugfs = kzalloc(sizeof(*ucsi->debugfs), GFP_KERNEL);
80 ucsi->debugfs->dentry = debugfs_create_dir(dev_name(ucsi->dev), ucsi_debugfs_root);
81 debugfs_create_file("command", 0200, ucsi->debugfs->dentry, ucsi, &ucsi_cmd_fops);
82 debugfs_create_file("response", 0400, ucsi->debugfs->dentry, ucsi, &ucsi_resp_fops);
85 void ucsi_debugfs_unregister(struct ucsi *ucsi)
87 if (IS_ERR_OR_NULL(ucsi) || !ucsi->debugfs)
90 debugfs_remove_recursive(ucsi->debugfs->dentry);
94 void ucsi_debugfs_init(void)
96 ucsi_debugfs_root = debugfs_create_dir("ucsi", usb_debug_root);
99 void ucsi_debugfs_exit(void)
101 debugfs_remove(ucsi_debugfs_root);