Add base debugfs mechanism for SoundWire bus by creating soundwire root and master-N and slave-x hierarchy. Also add SDW Slave SCP, DP0 and DP-N register debug file. Registers not implemented will print as "XX" Credits: this patch is based on an earlier internal contribution by Vinod Koul, Sanyog Kale, Shreyas Nc and Hardik Shah.
Unified · Split
| @@ -7,6 +7,10 @@ · 6 unmodified lines | ||
| 7 | 7 | soundwire-bus-objs := bus_type.o bus.o slave.o mipi_disco.o stream.o |
| 8 | 8 | obj-$(CONFIG_SOUNDWIRE_BUS) += soundwire-bus.o |
| 9 | 9 | |
| 10 | +ifdef CONFIG_DEBUG_FS | |
| 11 | +soundwire-bus-objs += debugfs.o | |
| 12 | +endif | |
| 13 | + | |
| 10 | 14 | #Cadence Objs |
| 11 | 15 | soundwire-cadence-objs := cadence_master.o |
| 12 | 16 | obj-$(CONFIG_SOUNDWIRE_CADENCE) += soundwire-cadence.o |
| @@ -49,6 +49,8 @@ int sdw_add_bus_master(struct sdw_bus *bus) · 48 unmodified lines | ||
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | + sdw_bus_debugfs_init(bus); | |
| 53 | + | |
| 52 | 54 | /* |
| 53 | 55 | * Device numbers in SoundWire are 0 through 15. Enumeration device |
| 54 | 56 | * number (0), Broadcast device number (15), Group numbers (12 and |
| @@ -109,6 +111,8 @@ static int sdw_delete_slave(struct device *dev, void *data) · 54 unmodified lines | ||
| 109 | 111 | struct sdw_slave *slave = dev_to_sdw_dev(dev); |
| 110 | 112 | struct sdw_bus *bus = slave->bus; |
| 111 | 113 | |
| 114 | + sdw_slave_debugfs_exit(slave); | |
| 115 | + | |
| 112 | 116 | mutex_lock(&bus->bus_lock); |
| 113 | 117 | |
| 114 | 118 | if (slave->dev_num) /* clear dev_num if assigned */ |
| @@ -130,6 +134,8 @@ static int sdw_delete_slave(struct device *dev, void *data) · 15 unmodified lines | ||
| 130 | 134 | void sdw_delete_bus_master(struct sdw_bus *bus) |
| 131 | 135 | { |
| 132 | 136 | device_for_each_child(bus->dev, NULL, sdw_delete_slave); |
| 137 | + | |
| 138 | + sdw_bus_debugfs_exit(bus); | |
| 133 | 139 | } |
| 134 | 140 | EXPORT_SYMBOL(sdw_delete_bus_master); |
| 135 | 141 | |
| @@ -18,6 +18,22 @@ static inline int sdw_acpi_find_slaves(struct sdw_bus *bus) · 17 unmodified lines | ||
| 18 | 18 | void sdw_extract_slave_id(struct sdw_bus *bus, |
| 19 | 19 | u64 addr, struct sdw_slave_id *id); |
| 20 | 20 | |
| 21 | +#ifdef CONFIG_DEBUG_FS | |
| 22 | +void sdw_bus_debugfs_init(struct sdw_bus *bus); | |
| 23 | +void sdw_bus_debugfs_exit(struct sdw_bus *bus); | |
| 24 | +void sdw_slave_debugfs_init(struct sdw_slave *slave); | |
| 25 | +void sdw_slave_debugfs_exit(struct sdw_slave *slave); | |
| 26 | +void sdw_debugfs_init(void); | |
| 27 | +void sdw_debugfs_exit(void); | |
| 28 | +#else | |
| 29 | +static inline void sdw_bus_debugfs_init(struct sdw_bus *bus) {} | |
| 30 | +static inline void sdw_bus_debugfs_exit(struct sdw_bus *bus) {} | |
| 31 | +static inline void sdw_slave_debugfs_init(struct sdw_slave *slave) {} | |
| 32 | +static inline void sdw_slave_debugfs_exit(struct sdw_slave *slave) {} | |
| 33 | +static inline void sdw_debugfs_init(void) {} | |
| 34 | +static inline void sdw_debugfs_exit(void) {} | |
| 35 | +#endif | |
| 36 | + | |
| 21 | 37 | enum { |
| 22 | 38 | SDW_MSG_FLAG_READ = 0, |
| 23 | 39 | SDW_MSG_FLAG_WRITE, |
| @@ -6,6 +6,7 @@ · 5 unmodified lines | ||
| 6 | 6 | #include <linux/pm_domain.h> |
| 7 | 7 | #include <linux/soundwire/sdw.h> |
| 8 | 8 | #include <linux/soundwire/sdw_type.h> |
| 9 | +#include "bus.h" | |
| 9 | 10 | |
| 10 | 11 | /** |
| 11 | 12 | * sdw_get_device_id - find the matching SoundWire device id |
| @@ -177,11 +178,13 @@ EXPORT_SYMBOL_GPL(sdw_unregister_driver); · 165 unmodified lines | ||
| 177 | 178 | |
| 178 | 179 | static int __init sdw_bus_init(void) |
| 179 | 180 | { |
| 181 | + sdw_debugfs_init(); | |
| 180 | 182 | return bus_register(&sdw_bus_type); |
| 181 | 183 | } |
| 182 | 184 | |
| 183 | 185 | static void __exit sdw_bus_exit(void) |
| 184 | 186 | { |
| 187 | + sdw_debugfs_exit(); | |
| 185 | 188 | bus_unregister(&sdw_bus_type); |
| 186 | 189 | } |
| 187 | 190 | |
| @@ -0,0 +1,151 @@ | ||
| 1 | +// SPDX-License-Identifier: GPL-2.0 | |
| 2 | +// Copyright(c) 2017-2019 Intel Corporation. | |
| 3 | + | |
| 4 | +#include <linux/device.h> | |
| 5 | +#include <linux/debugfs.h> | |
| 6 | +#include <linux/mod_devicetable.h> | |
| 7 | +#include <linux/slab.h> | |
| 8 | +#include <linux/soundwire/sdw.h> | |
| 9 | +#include <linux/soundwire/sdw_registers.h> | |
| 10 | +#include "bus.h" | |
| 11 | + | |
| 12 | +static struct dentry *sdw_debugfs_root; | |
| 13 | + | |
| 14 | +void sdw_bus_debugfs_init(struct sdw_bus *bus) | |
| 15 | +{ | |
| 16 | + char name[16]; | |
| 17 | + | |
| 18 | + if (!sdw_debugfs_root) | |
| 19 | + return; | |
| 20 | + | |
| 21 | + /* create the debugfs master-N */ | |
| 22 | + snprintf(name, sizeof(name), "master-%d", bus->link_id); | |
| 23 | + bus->debugfs = debugfs_create_dir(name, sdw_debugfs_root); | |
| 24 | +} | |
| 25 | + | |
| 26 | +void sdw_bus_debugfs_exit(struct sdw_bus *bus) | |
| 27 | +{ | |
| 28 | + debugfs_remove_recursive(bus->debugfs); | |
| 29 | +} | |
| 30 | + | |
| 31 | +#define RD_BUF (3 * PAGE_SIZE) | |
| 32 | + | |
| 33 | +static ssize_t sdw_sprintf(struct sdw_slave *slave, | |
| 34 | + char *buf, size_t pos, unsigned int reg) | |
| 35 | +{ | |
| 36 | + int value; | |
| 37 | + | |
| 38 | + value = sdw_read(slave, reg); | |
| 39 | + | |
| 40 | + if (value < 0) | |
| 41 | + return scnprintf(buf + pos, RD_BUF - pos, "%3x\tXX\n", reg); | |
| 42 | + else | |
| 43 | + return scnprintf(buf + pos, RD_BUF - pos, | |
| 44 | + "%3x\t%2x\n", reg, value); | |
| 45 | +} | |
| 46 | + | |
| 47 | +static int sdw_slave_reg_show(struct seq_file *s_file, void *data) | |
| 48 | +{ | |
| 49 | + struct sdw_slave *slave = s_file->private; | |
| 50 | + char *buf; | |
| 51 | + ssize_t ret; | |
| 52 | + int i, j; | |
| 53 | + | |
| 54 | + buf = kzalloc(RD_BUF, GFP_KERNEL); | |
| 55 | + if (!buf) | |
| 56 | + return -ENOMEM; | |
| 57 | + | |
| 58 | + ret = scnprintf(buf, RD_BUF, "Register Value\n"); | |
| 59 | + | |
| 60 | + /* DP0 non-banked registers */ | |
| 61 | + ret += scnprintf(buf + ret, RD_BUF - ret, "\nDP0\n"); | |
| 62 | + for (i = SDW_DP0_INT; i <= SDW_DP0_PREPARECTRL; i++) | |
| 63 | + ret += sdw_sprintf(slave, buf, ret, i); | |
| 64 | + | |
| 65 | + /* DP0 Bank 0 registers */ | |
| 66 | + ret += scnprintf(buf + ret, RD_BUF - ret, "Bank0\n"); | |
| 67 | + ret += sdw_sprintf(slave, buf, ret, SDW_DP0_CHANNELEN); | |
| 68 | + for (i = SDW_DP0_SAMPLECTRL1; i <= SDW_DP0_LANECTRL; i++) | |
| 69 | + ret += sdw_sprintf(slave, buf, ret, i); | |
| 70 | + | |
| 71 | + /* DP0 Bank 1 registers */ | |
| 72 | + ret += scnprintf(buf + ret, RD_BUF - ret, "Bank1\n"); | |
| 73 | + ret += sdw_sprintf(slave, buf, ret, | |
| 74 | + SDW_DP0_CHANNELEN + SDW_BANK1_OFFSET); | |
| 75 | + for (i = SDW_DP0_SAMPLECTRL1 + SDW_BANK1_OFFSET; | |
| 76 | + i <= SDW_DP0_LANECTRL + SDW_BANK1_OFFSET; i++) | |
| 77 | + ret += sdw_sprintf(slave, buf, ret, i); | |
| 78 | + | |
| 79 | + /* SCP registers */ | |
| 80 | + ret += scnprintf(buf + ret, RD_BUF - ret, "\nSCP\n"); | |
| 81 | + for (i = SDW_SCP_INT1; i <= SDW_SCP_BANKDELAY; i++) | |
| 82 | + ret += sdw_sprintf(slave, buf, ret, i); | |
| 83 | + for (i = SDW_SCP_DEVID_0; i <= SDW_SCP_DEVID_5; i++) | |
| 84 | + ret += sdw_sprintf(slave, buf, ret, i); | |
| 85 | + | |
| 86 | + /* | |
| 87 | + * SCP Bank 0/1 registers are read-only and cannot be | |
| 88 | + * retrieved from the Slave. The Master typically keeps track | |
| 89 | + * of the current frame size so the information can be found | |
| 90 | + * in other places | |
| 91 | + */ | |
| 92 | + | |
| 93 | + /* DP1..14 registers */ | |
| 94 | + for (i = 1; SDW_VALID_PORT_RANGE(i); i++) { | |
| 95 | + | |
| 96 | + /* DPi registers */ | |
| 97 | + ret += scnprintf(buf + ret, RD_BUF - ret, "\nDP%d\n", i); | |
| 98 | + for (j = SDW_DPN_INT(i); j <= SDW_DPN_PREPARECTRL(i); j++) | |
| 99 | + ret += sdw_sprintf(slave, buf, ret, j); | |
| 100 | + | |
| 101 | + /* DPi Bank0 registers */ | |
| 102 | + ret += scnprintf(buf + ret, RD_BUF - ret, "Bank0\n"); | |
| 103 | + for (j = SDW_DPN_CHANNELEN_B0(i); | |
| 104 | + j <= SDW_DPN_LANECTRL_B0(i); j++) | |
| 105 | + ret += sdw_sprintf(slave, buf, ret, j); | |
| 106 | + | |
| 107 | + /* DPi Bank1 registers */ | |
| 108 | + ret += scnprintf(buf + ret, RD_BUF - ret, "Bank1\n"); | |
| 109 | + for (j = SDW_DPN_CHANNELEN_B1(i); | |
| 110 | + j <= SDW_DPN_LANECTRL_B1(i); j++) | |
| 111 | + ret += sdw_sprintf(slave, buf, ret, j); | |
| 112 | + } | |
| 113 | + | |
| 114 | + seq_printf(s_file, "%s", buf); | |
| 115 | + kfree(buf); | |
| 116 | + | |
| 117 | + return 0; | |
| 118 | +} | |
| 119 | +DEFINE_SHOW_ATTRIBUTE(sdw_slave_reg); | |
| 120 | + | |
| 121 | +void sdw_slave_debugfs_init(struct sdw_slave *slave) | |
| 122 | +{ | |
| 123 | + struct dentry *master; | |
| 124 | + struct dentry *d; | |
| 125 | + char name[32]; | |
| 126 | + | |
| 127 | + master = slave->bus->debugfs; | |
| 128 | + | |
| 129 | + /* create the debugfs slave-name */ | |
| 130 | + snprintf(name, sizeof(name), "%s", dev_name(&slave->dev)); | |
| 131 | + d = debugfs_create_dir(name, master); | |
| 132 | + | |
| 133 | + debugfs_create_file("registers", 0400, d, slave, &sdw_slave_reg_fops); | |
| 134 | + | |
| 135 | + slave->debugfs = d; | |
| 136 | +} | |
| 137 | + | |
| 138 | +void sdw_slave_debugfs_exit(struct sdw_slave *slave) | |
| 139 | +{ | |
| 140 | + debugfs_remove_recursive(slave->debugfs); | |
| 141 | +} | |
| 142 | + | |
| 143 | +void sdw_debugfs_init(void) | |
| 144 | +{ | |
| 145 | + sdw_debugfs_root = debugfs_create_dir("soundwire", NULL); | |
| 146 | +} | |
| 147 | + | |
| 148 | +void sdw_debugfs_exit(void) | |
| 149 | +{ | |
| 150 | + debugfs_remove_recursive(sdw_debugfs_root); | |
| 151 | +} | |
| @@ -56,6 +56,7 @@ static int sdw_slave_add(struct sdw_bus *bus, · 55 unmodified lines | ||
| 56 | 56 | mutex_unlock(&bus->bus_lock); |
| 57 | 57 | put_device(&slave->dev); |
| 58 | 58 | } |
| 59 | + sdw_slave_debugfs_init(slave); | |
| 59 | 60 | |
| 60 | 61 | return ret; |
| 61 | 62 | } |
| @@ -542,6 +542,7 @@ struct sdw_slave_ops { · 541 unmodified lines | ||
| 542 | 542 | * @bus: Bus handle |
| 543 | 543 | * @ops: Slave callback ops |
| 544 | 544 | * @prop: Slave properties |
| 545 | + * @debugfs: Slave debugfs | |
| 545 | 546 | * @node: node for bus list |
| 546 | 547 | * @port_ready: Port ready completion flag for each Slave port |
| 547 | 548 | * @dev_num: Device Number assigned by Bus |
| @@ -553,6 +554,9 @@ struct sdw_slave { · 5 unmodified lines | ||
| 553 | 554 | struct sdw_bus *bus; |
| 554 | 555 | const struct sdw_slave_ops *ops; |
| 555 | 556 | struct sdw_slave_prop prop; |
| 557 | +#ifdef CONFIG_DEBUG_FS | |
| 558 | + struct dentry *debugfs; | |
| 559 | +#endif | |
| 556 | 560 | struct list_head node; |
| 557 | 561 | struct completion *port_ready; |
| 558 | 562 | u16 dev_num; |
| @@ -729,6 +733,7 @@ struct sdw_master_ops { · 170 unmodified lines | ||
| 729 | 733 | * @m_rt_list: List of Master instance of all stream(s) running on Bus. This |
| 730 | 734 | * is used to compute and program bus bandwidth, clock, frame shape, |
| 731 | 735 | * transport and port parameters |
| 736 | + * @debugfs: Bus debugfs | |
| 732 | 737 | * @defer_msg: Defer message |
| 733 | 738 | * @clk_stop_timeout: Clock stop timeout computed |
| 734 | 739 | * @bank_switch_timeout: Bank switch timeout computed |
| @@ -748,6 +753,9 @@ struct sdw_bus { · 13 unmodified lines | ||
| 748 | 753 | struct sdw_bus_params params; |
| 749 | 754 | struct sdw_master_prop prop; |
| 750 | 755 | struct list_head m_rt_list; |
| 756 | +#ifdef CONFIG_DEBUG_FS | |
| 757 | + struct dentry *debugfs; | |
| 758 | +#endif | |
| 751 | 759 | struct sdw_defer defer_msg; |
| 752 | 760 | unsigned int clk_stop_timeout; |
| 753 | 761 | u32 bank_switch_timeout; |