History

soundwire: add debugfs support

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.

Pierre-Louis Bossart committed 7 years ago

Commit bf034731 parent e87cf357 files · +189 −0Browse files

Unified · Split

7 files
  1. drivers/soundwire/Makefile +4 −0
  2. drivers/soundwire/bus.c +6 −0
  3. drivers/soundwire/bus.h +16 −0
  4. drivers/soundwire/bus_type.c +3 −0
  5. drivers/soundwire/debugfs.c +151 −0
  6. drivers/soundwire/slave.c +1 −0
  7. include/linux/soundwire/sdw.h +8 −0
drivers/soundwire/Makefile+4−0
@@ -7,6 +7,10 @@ · 6 unmodified lines
7soundwire-bus-objs := bus_type.o bus.o slave.o mipi_disco.o stream.o7soundwire-bus-objs := bus_type.o bus.o slave.o mipi_disco.o stream.o
8obj-$(CONFIG_SOUNDWIRE_BUS) += soundwire-bus.o8obj-$(CONFIG_SOUNDWIRE_BUS) += soundwire-bus.o
9 9
10ifdef CONFIG_DEBUG_FS
11soundwire-bus-objs += debugfs.o
12endif
13
10#Cadence Objs14#Cadence Objs
11soundwire-cadence-objs := cadence_master.o15soundwire-cadence-objs := cadence_master.o
12obj-$(CONFIG_SOUNDWIRE_CADENCE) += soundwire-cadence.o16obj-$(CONFIG_SOUNDWIRE_CADENCE) += soundwire-cadence.o
drivers/soundwire/bus.c+6−0
@@ -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 * Device numbers in SoundWire are 0 through 15. Enumeration device55 * Device numbers in SoundWire are 0 through 15. Enumeration device
54 * number (0), Broadcast device number (15), Group numbers (12 and56 * 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 struct sdw_slave *slave = dev_to_sdw_dev(dev);111 struct sdw_slave *slave = dev_to_sdw_dev(dev);
110 struct sdw_bus *bus = slave->bus;112 struct sdw_bus *bus = slave->bus;
111 113
114 sdw_slave_debugfs_exit(slave);
115
112 mutex_lock(&bus->bus_lock);116 mutex_lock(&bus->bus_lock);
113 117
114 if (slave->dev_num) /* clear dev_num if assigned */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
130void sdw_delete_bus_master(struct sdw_bus *bus)134void sdw_delete_bus_master(struct sdw_bus *bus)
131{135{
132 device_for_each_child(bus->dev, NULL, sdw_delete_slave);136 device_for_each_child(bus->dev, NULL, sdw_delete_slave);
137
138 sdw_bus_debugfs_exit(bus);
133}139}
134EXPORT_SYMBOL(sdw_delete_bus_master);140EXPORT_SYMBOL(sdw_delete_bus_master);
135 141
drivers/soundwire/bus.h+16−0
@@ -18,6 +18,22 @@ static inline int sdw_acpi_find_slaves(struct sdw_bus *bus) · 17 unmodified lines
18void sdw_extract_slave_id(struct sdw_bus *bus,18void sdw_extract_slave_id(struct sdw_bus *bus,
19 u64 addr, struct sdw_slave_id *id);19 u64 addr, struct sdw_slave_id *id);
20 20
21#ifdef CONFIG_DEBUG_FS
22void sdw_bus_debugfs_init(struct sdw_bus *bus);
23void sdw_bus_debugfs_exit(struct sdw_bus *bus);
24void sdw_slave_debugfs_init(struct sdw_slave *slave);
25void sdw_slave_debugfs_exit(struct sdw_slave *slave);
26void sdw_debugfs_init(void);
27void sdw_debugfs_exit(void);
28#else
29static inline void sdw_bus_debugfs_init(struct sdw_bus *bus) {}
30static inline void sdw_bus_debugfs_exit(struct sdw_bus *bus) {}
31static inline void sdw_slave_debugfs_init(struct sdw_slave *slave) {}
32static inline void sdw_slave_debugfs_exit(struct sdw_slave *slave) {}
33static inline void sdw_debugfs_init(void) {}
34static inline void sdw_debugfs_exit(void) {}
35#endif
36
21enum {37enum {
22 SDW_MSG_FLAG_READ = 0,38 SDW_MSG_FLAG_READ = 0,
23 SDW_MSG_FLAG_WRITE,39 SDW_MSG_FLAG_WRITE,
drivers/soundwire/bus_type.c+3−0
@@ -6,6 +6,7 @@ · 5 unmodified lines
6#include <linux/pm_domain.h>6#include <linux/pm_domain.h>
7#include <linux/soundwire/sdw.h>7#include <linux/soundwire/sdw.h>
8#include <linux/soundwire/sdw_type.h>8#include <linux/soundwire/sdw_type.h>
9#include "bus.h"
9 10
10/**11/**
11 * sdw_get_device_id - find the matching SoundWire device id12 * 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
178static int __init sdw_bus_init(void)179static int __init sdw_bus_init(void)
179{180{
181 sdw_debugfs_init();
180 return bus_register(&sdw_bus_type);182 return bus_register(&sdw_bus_type);
181}183}
182 184
183static void __exit sdw_bus_exit(void)185static void __exit sdw_bus_exit(void)
184{186{
187 sdw_debugfs_exit();
185 bus_unregister(&sdw_bus_type);188 bus_unregister(&sdw_bus_type);
186}189}
187 190
drivers/soundwire/debugfs.c+151−0
@@ -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
12static struct dentry *sdw_debugfs_root;
13
14void 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
26void 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
33static 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
47static 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}
119DEFINE_SHOW_ATTRIBUTE(sdw_slave_reg);
120
121void 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
138void sdw_slave_debugfs_exit(struct sdw_slave *slave)
139{
140 debugfs_remove_recursive(slave->debugfs);
141}
142
143void sdw_debugfs_init(void)
144{
145 sdw_debugfs_root = debugfs_create_dir("soundwire", NULL);
146}
147
148void sdw_debugfs_exit(void)
149{
150 debugfs_remove_recursive(sdw_debugfs_root);
151}
drivers/soundwire/slave.c+1−0
@@ -56,6 +56,7 @@ static int sdw_slave_add(struct sdw_bus *bus, · 55 unmodified lines
56 mutex_unlock(&bus->bus_lock);56 mutex_unlock(&bus->bus_lock);
57 put_device(&slave->dev);57 put_device(&slave->dev);
58 }58 }
59 sdw_slave_debugfs_init(slave);
59 60
60 return ret;61 return ret;
61}62}
include/linux/soundwire/sdw.h+8−0
@@ -542,6 +542,7 @@ struct sdw_slave_ops { · 541 unmodified lines
542 * @bus: Bus handle542 * @bus: Bus handle
543 * @ops: Slave callback ops543 * @ops: Slave callback ops
544 * @prop: Slave properties544 * @prop: Slave properties
545 * @debugfs: Slave debugfs
545 * @node: node for bus list546 * @node: node for bus list
546 * @port_ready: Port ready completion flag for each Slave port547 * @port_ready: Port ready completion flag for each Slave port
547 * @dev_num: Device Number assigned by Bus548 * @dev_num: Device Number assigned by Bus
@@ -553,6 +554,9 @@ struct sdw_slave { · 5 unmodified lines
553 struct sdw_bus *bus;554 struct sdw_bus *bus;
554 const struct sdw_slave_ops *ops;555 const struct sdw_slave_ops *ops;
555 struct sdw_slave_prop prop;556 struct sdw_slave_prop prop;
557#ifdef CONFIG_DEBUG_FS
558 struct dentry *debugfs;
559#endif
556 struct list_head node;560 struct list_head node;
557 struct completion *port_ready;561 struct completion *port_ready;
558 u16 dev_num;562 u16 dev_num;
@@ -729,6 +733,7 @@ struct sdw_master_ops { · 170 unmodified lines
729 * @m_rt_list: List of Master instance of all stream(s) running on Bus. This733 * @m_rt_list: List of Master instance of all stream(s) running on Bus. This
730 * is used to compute and program bus bandwidth, clock, frame shape,734 * is used to compute and program bus bandwidth, clock, frame shape,
731 * transport and port parameters735 * transport and port parameters
736 * @debugfs: Bus debugfs
732 * @defer_msg: Defer message737 * @defer_msg: Defer message
733 * @clk_stop_timeout: Clock stop timeout computed738 * @clk_stop_timeout: Clock stop timeout computed
734 * @bank_switch_timeout: Bank switch timeout computed739 * @bank_switch_timeout: Bank switch timeout computed
@@ -748,6 +753,9 @@ struct sdw_bus { · 13 unmodified lines
748 struct sdw_bus_params params;753 struct sdw_bus_params params;
749 struct sdw_master_prop prop;754 struct sdw_master_prop prop;
750 struct list_head m_rt_list;755 struct list_head m_rt_list;
756#ifdef CONFIG_DEBUG_FS
757 struct dentry *debugfs;
758#endif
751 struct sdw_defer defer_msg;759 struct sdw_defer defer_msg;
752 unsigned int clk_stop_timeout;760 unsigned int clk_stop_timeout;
753 u32 bank_switch_timeout;761 u32 bank_switch_timeout;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t