FILE
debugfs.c
File preview with syntax highlighting.
linux-6.19.14/drivers/usb/typec/ucsi/debugfs.c
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * UCSI debugfs interface 4 * 5 * Copyright (C) 2023 Intel Corporation 6 * 7 * Authors: Rajaram Regupathy <rajaram.regupathy@intel.com> 8 * Gopal Saranya <saranya.gopal@intel.com> 9 */ 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> 15 16#include <asm/errno.h> 17 18#include "ucsi.h" 19 20static struct dentry *ucsi_debugfs_root; 21 22static int ucsi_cmd(void *data, u64 val) 23{ 24 struct ucsi *ucsi = data; 25 int ret; 26 27 memset(&ucsi->debugfs->response, 0, sizeof(ucsi->debugfs->response)); 28 ucsi->debugfs->status = 0; 29 30 switch (UCSI_COMMAND(val)) { 31 case UCSI_SET_CCOM: 32 case UCSI_SET_UOR: 33 case UCSI_SET_PDR: 34 case UCSI_CONNECTOR_RESET: 35 case UCSI_SET_SINK_PATH: 36 case UCSI_SET_NEW_CAM: 37 case UCSI_SET_USB: 38 case UCSI_SET_POWER_LEVEL: 39 case UCSI_READ_POWER_LEVEL: 40 ret = ucsi_send_command(ucsi, val, NULL, 0); 41 break; 42 case UCSI_GET_CAPABILITY: 43 case UCSI_GET_CONNECTOR_CAPABILITY: 44 case UCSI_GET_ALTERNATE_MODES: 45 case UCSI_GET_CAM_SUPPORTED: 46 case UCSI_GET_CURRENT_CAM: 47 case UCSI_GET_PDOS: 48 case UCSI_GET_CABLE_PROPERTY: 49 case UCSI_GET_CONNECTOR_STATUS: 50 case UCSI_GET_ERROR_STATUS: 51 case UCSI_GET_PD_MESSAGE: 52 case UCSI_GET_ATTENTION_VDO: 53 case UCSI_GET_CAM_CS: 54 case UCSI_GET_LPM_PPM_INFO: 55 ret = ucsi_send_command(ucsi, val, 56 &ucsi->debugfs->response, 57 sizeof(ucsi->debugfs->response)); 58 break; 59 default: 60 ret = -EOPNOTSUPP; 61 } 62 63 if (ret < 0) { 64 ucsi->debugfs->status = ret; 65 return ret; 66 } 67 68 return 0; 69} 70DEFINE_DEBUGFS_ATTRIBUTE(ucsi_cmd_fops, NULL, ucsi_cmd, "0x%llx\n"); 71 72static int ucsi_resp_show(struct seq_file *s, void *not_used) 73{ 74 struct ucsi *ucsi = s->private; 75 76 if (ucsi->debugfs->status) 77 return ucsi->debugfs->status; 78 79 seq_printf(s, "0x%016llx%016llx\n", ucsi->debugfs->response.high, 80 ucsi->debugfs->response.low); 81 return 0; 82} 83DEFINE_SHOW_ATTRIBUTE(ucsi_resp); 84 85static int ucsi_peak_curr_show(struct seq_file *m, void *v) 86{ 87 struct ucsi *ucsi = m->private; 88 89 seq_printf(m, "%u mA\n", ucsi->connector->peak_current); 90 return 0; 91} 92DEFINE_SHOW_ATTRIBUTE(ucsi_peak_curr); 93 94static int ucsi_avg_curr_show(struct seq_file *m, void *v) 95{ 96 struct ucsi *ucsi = m->private; 97 98 seq_printf(m, "%u mA\n", ucsi->connector->avg_current); 99 return 0; 100} 101DEFINE_SHOW_ATTRIBUTE(ucsi_avg_curr); 102 103static int ucsi_vbus_volt_show(struct seq_file *m, void *v) 104{ 105 struct ucsi *ucsi = m->private; 106 107 seq_printf(m, "%u mV\n", ucsi->connector->vbus_voltage); 108 return 0; 109} 110DEFINE_SHOW_ATTRIBUTE(ucsi_vbus_volt); 111 112void ucsi_debugfs_register(struct ucsi *ucsi) 113{ 114 ucsi->debugfs = kzalloc(sizeof(*ucsi->debugfs), GFP_KERNEL); 115 if (!ucsi->debugfs) 116 return; 117 118 ucsi->debugfs->dentry = debugfs_create_dir(dev_name(ucsi->dev), ucsi_debugfs_root); 119 debugfs_create_file("command", 0200, ucsi->debugfs->dentry, ucsi, &ucsi_cmd_fops); 120 debugfs_create_file("response", 0400, ucsi->debugfs->dentry, ucsi, &ucsi_resp_fops); 121 debugfs_create_file("peak_current", 0400, ucsi->debugfs->dentry, ucsi, &ucsi_peak_curr_fops); 122 debugfs_create_file("avg_current", 0400, ucsi->debugfs->dentry, ucsi, &ucsi_avg_curr_fops); 123 debugfs_create_file("vbus_voltage", 0400, ucsi->debugfs->dentry, ucsi, &ucsi_vbus_volt_fops); 124} 125 126void ucsi_debugfs_unregister(struct ucsi *ucsi) 127{ 128 if (IS_ERR_OR_NULL(ucsi) || !ucsi->debugfs) 129 return; 130 131 debugfs_remove_recursive(ucsi->debugfs->dentry); 132 kfree(ucsi->debugfs); 133} 134 135void ucsi_debugfs_init(void) 136{ 137 ucsi_debugfs_root = debugfs_create_dir("ucsi", usb_debug_root); 138} 139 140void ucsi_debugfs_exit(void) 141{ 142 debugfs_remove(ucsi_debugfs_root); 143}
~/
Read-only file preview.