1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright(c) 2015-2020 Intel Corporation.
4 #include <linux/device.h>
5 #include <linux/mod_devicetable.h>
6 #include <linux/slab.h>
7 #include <linux/sysfs.h>
8 #include <linux/soundwire/sdw.h>
9 #include <linux/soundwire/sdw_type.h>
11 #include "sysfs_local.h"
18 * The sysfs for Slave reflects the MIPI description as given
19 * in the MIPI DisCo spec
23 * |---- dev-properties
26 * |---- test_mode_capable
27 * |---- clk_stop_mode1
28 * |---- simple_clk_stop_capable
29 * |---- clk_stop_timeout
30 * |---- ch_prep_timeout
32 * |---- high_PHY_capable
33 * |---- paging_support
34 * |---- bank_delay_support
43 * |---- BRA_flow_controlled
44 * |---- simple_ch_prep_sm
45 * |---- imp_def_interrupts
46 * |---- dpN_<sink/src>
52 * |---- simple_ch_prep_sm
53 * |---- ch_prep_timeout
54 * |---- imp_def_interrupts
58 * |---- ch_combinations
59 * |---- max_async_buffer
60 * |---- block_pack_mode
65 #define sdw_slave_attr(field, format_string) \
66 static ssize_t field##_show(struct device *dev, \
67 struct device_attribute *attr, \
70 struct sdw_slave *slave = dev_to_sdw_dev(dev); \
71 return sprintf(buf, format_string, slave->prop.field); \
73 static DEVICE_ATTR_RO(field)
75 sdw_slave_attr(mipi_revision
, "0x%x\n");
76 sdw_slave_attr(wake_capable
, "%d\n");
77 sdw_slave_attr(test_mode_capable
, "%d\n");
78 sdw_slave_attr(clk_stop_mode1
, "%d\n");
79 sdw_slave_attr(simple_clk_stop_capable
, "%d\n");
80 sdw_slave_attr(clk_stop_timeout
, "%d\n");
81 sdw_slave_attr(ch_prep_timeout
, "%d\n");
82 sdw_slave_attr(reset_behave
, "%d\n");
83 sdw_slave_attr(high_PHY_capable
, "%d\n");
84 sdw_slave_attr(paging_support
, "%d\n");
85 sdw_slave_attr(bank_delay_support
, "%d\n");
86 sdw_slave_attr(p15_behave
, "%d\n");
87 sdw_slave_attr(master_count
, "%d\n");
88 sdw_slave_attr(source_ports
, "0x%x\n");
89 sdw_slave_attr(sink_ports
, "0x%x\n");
91 static ssize_t
modalias_show(struct device
*dev
,
92 struct device_attribute
*attr
, char *buf
)
94 struct sdw_slave
*slave
= dev_to_sdw_dev(dev
);
96 return sdw_slave_modalias(slave
, buf
, 256);
98 static DEVICE_ATTR_RO(modalias
);
100 static struct attribute
*slave_attrs
[] = {
101 &dev_attr_modalias
.attr
,
104 ATTRIBUTE_GROUPS(slave
);
106 static struct attribute
*slave_dev_attrs
[] = {
107 &dev_attr_mipi_revision
.attr
,
108 &dev_attr_wake_capable
.attr
,
109 &dev_attr_test_mode_capable
.attr
,
110 &dev_attr_clk_stop_mode1
.attr
,
111 &dev_attr_simple_clk_stop_capable
.attr
,
112 &dev_attr_clk_stop_timeout
.attr
,
113 &dev_attr_ch_prep_timeout
.attr
,
114 &dev_attr_reset_behave
.attr
,
115 &dev_attr_high_PHY_capable
.attr
,
116 &dev_attr_paging_support
.attr
,
117 &dev_attr_bank_delay_support
.attr
,
118 &dev_attr_p15_behave
.attr
,
119 &dev_attr_master_count
.attr
,
120 &dev_attr_source_ports
.attr
,
121 &dev_attr_sink_ports
.attr
,
126 * we don't use ATTRIBUTES_GROUP here since we want to add a subdirectory
127 * for device-level properties
129 static struct attribute_group sdw_slave_dev_attr_group
= {
130 .attrs
= slave_dev_attrs
,
131 .name
= "dev-properties",
138 #define sdw_dp0_attr(field, format_string) \
139 static ssize_t field##_show(struct device *dev, \
140 struct device_attribute *attr, \
143 struct sdw_slave *slave = dev_to_sdw_dev(dev); \
144 return sprintf(buf, format_string, slave->prop.dp0_prop->field);\
146 static DEVICE_ATTR_RO(field)
148 sdw_dp0_attr(max_word
, "%d\n");
149 sdw_dp0_attr(min_word
, "%d\n");
150 sdw_dp0_attr(BRA_flow_controlled
, "%d\n");
151 sdw_dp0_attr(simple_ch_prep_sm
, "%d\n");
152 sdw_dp0_attr(imp_def_interrupts
, "0x%x\n");
154 static ssize_t
words_show(struct device
*dev
,
155 struct device_attribute
*attr
, char *buf
)
157 struct sdw_slave
*slave
= dev_to_sdw_dev(dev
);
161 for (i
= 0; i
< slave
->prop
.dp0_prop
->num_words
; i
++)
162 size
+= sprintf(buf
+ size
, "%d ",
163 slave
->prop
.dp0_prop
->words
[i
]);
164 size
+= sprintf(buf
+ size
, "\n");
168 static DEVICE_ATTR_RO(words
);
170 static struct attribute
*dp0_attrs
[] = {
171 &dev_attr_max_word
.attr
,
172 &dev_attr_min_word
.attr
,
173 &dev_attr_words
.attr
,
174 &dev_attr_BRA_flow_controlled
.attr
,
175 &dev_attr_simple_ch_prep_sm
.attr
,
176 &dev_attr_imp_def_interrupts
.attr
,
181 * we don't use ATTRIBUTES_GROUP here since we want to add a subdirectory
182 * for dp0-level properties
184 static const struct attribute_group dp0_group
= {
189 int sdw_slave_sysfs_init(struct sdw_slave
*slave
)
193 ret
= devm_device_add_groups(&slave
->dev
, slave_groups
);
197 ret
= devm_device_add_group(&slave
->dev
, &sdw_slave_dev_attr_group
);
201 if (slave
->prop
.dp0_prop
) {
202 ret
= devm_device_add_group(&slave
->dev
, &dp0_group
);
207 if (slave
->prop
.source_ports
|| slave
->prop
.sink_ports
) {
208 ret
= sdw_slave_sysfs_dpn_init(slave
);