|
3 | 3 | * Copyright 2024 NXP |
4 | 4 | */ |
5 | 5 |
|
| 6 | +#include <linux/debugfs.h> |
| 7 | +#include <linux/device/devres.h> |
6 | 8 | #include <linux/firmware/imx/sm.h> |
7 | 9 | #include <linux/module.h> |
8 | 10 | #include <linux/of.h> |
9 | 11 | #include <linux/platform_device.h> |
10 | 12 | #include <linux/scmi_protocol.h> |
11 | 13 | #include <linux/scmi_imx_protocol.h> |
| 14 | +#include <linux/seq_file.h> |
| 15 | +#include <linux/sizes.h> |
12 | 16 |
|
13 | 17 | static const struct scmi_imx_misc_proto_ops *imx_misc_ctrl_ops; |
14 | 18 | static struct scmi_protocol_handle *ph; |
@@ -44,10 +48,38 @@ static int scmi_imx_misc_ctrl_notifier(struct notifier_block *nb, |
44 | 48 | return 0; |
45 | 49 | } |
46 | 50 |
|
| 51 | +static int syslog_show(struct seq_file *file, void *priv) |
| 52 | +{ |
| 53 | + /* 4KB is large enough for syslog */ |
| 54 | + void *syslog __free(kfree) = kmalloc(SZ_4K, GFP_KERNEL); |
| 55 | + /* syslog API use num words, not num bytes */ |
| 56 | + u16 size = SZ_4K / 4; |
| 57 | + int ret; |
| 58 | + |
| 59 | + if (!ph) |
| 60 | + return -ENODEV; |
| 61 | + |
| 62 | + ret = imx_misc_ctrl_ops->misc_syslog(ph, &size, syslog); |
| 63 | + if (ret) |
| 64 | + return ret; |
| 65 | + |
| 66 | + seq_hex_dump(file, " ", DUMP_PREFIX_NONE, 16, sizeof(u32), syslog, size * 4, false); |
| 67 | + seq_putc(file, '\n'); |
| 68 | + |
| 69 | + return 0; |
| 70 | +} |
| 71 | +DEFINE_SHOW_ATTRIBUTE(syslog); |
| 72 | + |
| 73 | +static void scmi_imx_misc_put(void *p) |
| 74 | +{ |
| 75 | + debugfs_remove((struct dentry *)p); |
| 76 | +} |
| 77 | + |
47 | 78 | static int scmi_imx_misc_ctrl_probe(struct scmi_device *sdev) |
48 | 79 | { |
49 | 80 | const struct scmi_handle *handle = sdev->handle; |
50 | 81 | struct device_node *np = sdev->dev.of_node; |
| 82 | + struct dentry *scmi_imx_dentry; |
51 | 83 | u32 src_id, flags; |
52 | 84 | int ret, i, num; |
53 | 85 |
|
@@ -98,7 +130,10 @@ static int scmi_imx_misc_ctrl_probe(struct scmi_device *sdev) |
98 | 130 | } |
99 | 131 | } |
100 | 132 |
|
101 | | - return 0; |
| 133 | + scmi_imx_dentry = debugfs_create_dir("scmi_imx", NULL); |
| 134 | + debugfs_create_file("syslog", 0444, scmi_imx_dentry, &sdev->dev, &syslog_fops); |
| 135 | + |
| 136 | + return devm_add_action_or_reset(&sdev->dev, scmi_imx_misc_put, scmi_imx_dentry); |
102 | 137 | } |
103 | 138 |
|
104 | 139 | static const struct scmi_device_id scmi_id_table[] = { |
|
0 commit comments