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.
20 * status and device_number come directly from the MIPI SoundWire
27 * |---- dev-properties
30 * |---- test_mode_capable
31 * |---- clk_stop_mode1
32 * |---- simple_clk_stop_capable
33 * |---- clk_stop_timeout
34 * |---- ch_prep_timeout
36 * |---- high_PHY_capable
37 * |---- paging_support
38 * |---- bank_delay_support
47 * |---- BRA_flow_controlled
48 * |---- simple_ch_prep_sm
49 * |---- imp_def_interrupts
50 * |---- dpN_<sink/src>
56 * |---- simple_ch_prep_sm
57 * |---- ch_prep_timeout
58 * |---- imp_def_interrupts
62 * |---- ch_combinations
63 * |---- max_async_buffer
64 * |---- block_pack_mode
69 #define sdw_slave_attr(field, format_string) \
70 static ssize_t field##_show(struct device *dev, \
71 struct device_attribute *attr, \
74 struct sdw_slave *slave = dev_to_sdw_dev(dev); \
75 return sprintf(buf, format_string, slave->prop.field); \
77 static DEVICE_ATTR_RO(field)
79 sdw_slave_attr(mipi_revision
, "0x%x\n");
80 sdw_slave_attr(wake_capable
, "%d\n");
81 sdw_slave_attr(test_mode_capable
, "%d\n");
82 sdw_slave_attr(clk_stop_mode1
, "%d\n");
83 sdw_slave_attr(simple_clk_stop_capable
, "%d\n");
84 sdw_slave_attr(clk_stop_timeout
, "%d\n");
85 sdw_slave_attr(ch_prep_timeout
, "%d\n");
86 sdw_slave_attr(reset_behave
, "%d\n");
87 sdw_slave_attr(high_PHY_capable
, "%d\n");
88 sdw_slave_attr(paging_support
, "%d\n");
89 sdw_slave_attr(bank_delay_support
, "%d\n");
90 sdw_slave_attr(p15_behave
, "%d\n");
91 sdw_slave_attr(master_count
, "%d\n");
92 sdw_slave_attr(source_ports
, "0x%x\n");
93 sdw_slave_attr(sink_ports
, "0x%x\n");
95 static ssize_t
modalias_show(struct device
*dev
,
96 struct device_attribute
*attr
, char *buf
)
98 struct sdw_slave
*slave
= dev_to_sdw_dev(dev
);
100 return sdw_slave_modalias(slave
, buf
, 256);
102 static DEVICE_ATTR_RO(modalias
);
104 static struct attribute
*slave_attrs
[] = {
105 &dev_attr_modalias
.attr
,
109 static const struct attribute_group slave_attr_group
= {
110 .attrs
= slave_attrs
,
113 static struct attribute
*slave_dev_attrs
[] = {
114 &dev_attr_mipi_revision
.attr
,
115 &dev_attr_wake_capable
.attr
,
116 &dev_attr_test_mode_capable
.attr
,
117 &dev_attr_clk_stop_mode1
.attr
,
118 &dev_attr_simple_clk_stop_capable
.attr
,
119 &dev_attr_clk_stop_timeout
.attr
,
120 &dev_attr_ch_prep_timeout
.attr
,
121 &dev_attr_reset_behave
.attr
,
122 &dev_attr_high_PHY_capable
.attr
,
123 &dev_attr_paging_support
.attr
,
124 &dev_attr_bank_delay_support
.attr
,
125 &dev_attr_p15_behave
.attr
,
126 &dev_attr_master_count
.attr
,
127 &dev_attr_source_ports
.attr
,
128 &dev_attr_sink_ports
.attr
,
132 static const struct attribute_group sdw_slave_dev_attr_group
= {
133 .attrs
= slave_dev_attrs
,
134 .name
= "dev-properties",
141 #define sdw_dp0_attr(field, format_string) \
142 static ssize_t field##_show(struct device *dev, \
143 struct device_attribute *attr, \
146 struct sdw_slave *slave = dev_to_sdw_dev(dev); \
147 return sprintf(buf, format_string, slave->prop.dp0_prop->field);\
149 static DEVICE_ATTR_RO(field)
151 sdw_dp0_attr(max_word
, "%d\n");
152 sdw_dp0_attr(min_word
, "%d\n");
153 sdw_dp0_attr(BRA_flow_controlled
, "%d\n");
154 sdw_dp0_attr(simple_ch_prep_sm
, "%d\n");
155 sdw_dp0_attr(imp_def_interrupts
, "0x%x\n");
157 static ssize_t
words_show(struct device
*dev
,
158 struct device_attribute
*attr
, char *buf
)
160 struct sdw_slave
*slave
= dev_to_sdw_dev(dev
);
164 for (i
= 0; i
< slave
->prop
.dp0_prop
->num_words
; i
++)
165 size
+= sprintf(buf
+ size
, "%d ",
166 slave
->prop
.dp0_prop
->words
[i
]);
167 size
+= sprintf(buf
+ size
, "\n");
171 static DEVICE_ATTR_RO(words
);
173 static struct attribute
*dp0_attrs
[] = {
174 &dev_attr_max_word
.attr
,
175 &dev_attr_min_word
.attr
,
176 &dev_attr_words
.attr
,
177 &dev_attr_BRA_flow_controlled
.attr
,
178 &dev_attr_simple_ch_prep_sm
.attr
,
179 &dev_attr_imp_def_interrupts
.attr
,
183 static umode_t
dp0_attr_visible(struct kobject
*kobj
, struct attribute
*attr
,
186 struct sdw_slave
*slave
= dev_to_sdw_dev(kobj_to_dev(kobj
));
188 if (slave
->prop
.dp0_prop
)
193 static bool dp0_group_visible(struct kobject
*kobj
)
195 struct sdw_slave
*slave
= dev_to_sdw_dev(kobj_to_dev(kobj
));
197 if (slave
->prop
.dp0_prop
)
201 DEFINE_SYSFS_GROUP_VISIBLE(dp0
);
203 static const struct attribute_group dp0_group
= {
205 .is_visible
= SYSFS_GROUP_VISIBLE(dp0
),
209 const struct attribute_group
*sdw_attr_groups
[] = {
211 &sdw_slave_dev_attr_group
,
217 * the status is shown in capital letters for UNATTACHED and RESERVED
218 * on purpose, to highlight users to the fact that these status values
221 static const char *const slave_status
[] = {
222 [SDW_SLAVE_UNATTACHED
] = "UNATTACHED",
223 [SDW_SLAVE_ATTACHED
] = "Attached",
224 [SDW_SLAVE_ALERT
] = "Alert",
225 [SDW_SLAVE_RESERVED
] = "RESERVED",
228 static ssize_t
status_show(struct device
*dev
,
229 struct device_attribute
*attr
, char *buf
)
231 struct sdw_slave
*slave
= dev_to_sdw_dev(dev
);
233 return sprintf(buf
, "%s\n", slave_status
[slave
->status
]);
235 static DEVICE_ATTR_RO(status
);
237 static ssize_t
device_number_show(struct device
*dev
,
238 struct device_attribute
*attr
, char *buf
)
240 struct sdw_slave
*slave
= dev_to_sdw_dev(dev
);
242 if (slave
->status
== SDW_SLAVE_UNATTACHED
)
243 return sprintf(buf
, "%s", "N/A");
245 return sprintf(buf
, "%d", slave
->dev_num
);
247 static DEVICE_ATTR_RO(device_number
);
249 static struct attribute
*slave_status_attrs
[] = {
250 &dev_attr_status
.attr
,
251 &dev_attr_device_number
.attr
,
256 * we don't use ATTRIBUTES_GROUP here since the group is used in a
257 * separate file and can't be handled as a static.
259 static const struct attribute_group sdw_slave_status_attr_group
= {
260 .attrs
= slave_status_attrs
,
263 const struct attribute_group
*sdw_slave_status_attr_groups
[] = {
264 &sdw_slave_status_attr_group
,