1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2 // Copyright(c) 2015-17 Intel Corporation.
5 * MIPI Discovery And Configuration (DisCo) Specification for SoundWire
6 * specifies properties to be implemented for SoundWire Masters and Slaves.
7 * The DisCo spec doesn't mandate these properties. However, SDW bus cannot
8 * work without knowing these values.
10 * The helper functions read the Master and Slave properties. Implementers
11 * of Master or Slave drivers can use any of the below three mechanisms:
12 * a) Use these APIs here as .read_prop() callback for Master and Slave
13 * b) Implement own methods and set those as .read_prop(), but invoke
14 * APIs in this file for generic read and override the values with
15 * platform specific data
16 * c) Implement ones own methods which do not use anything provided
20 #include <linux/device.h>
21 #include <linux/property.h>
22 #include <linux/mod_devicetable.h>
23 #include <linux/soundwire/sdw.h>
27 * sdw_master_read_prop() - Read Master properties
28 * @bus: SDW bus instance
30 int sdw_master_read_prop(struct sdw_bus *bus)
32 struct sdw_master_prop *prop = &bus->prop;
33 struct fwnode_handle *link;
37 device_property_read_u32(bus->dev,
38 "mipi-sdw-sw-interface-revision",
41 /* Find master handle */
42 snprintf(name, sizeof(name),
43 "mipi-sdw-master-%d-subproperties", bus->link_id);
45 link = device_get_named_child_node(bus->dev, name);
47 dev_err(bus->dev, "Master node %s not found\n", name);
51 if (fwnode_property_read_bool(link,
52 "mipi-sdw-clock-stop-mode0-supported"))
53 prop->clk_stop_mode = SDW_CLK_STOP_MODE0;
55 if (fwnode_property_read_bool(link,
56 "mipi-sdw-clock-stop-mode1-supported"))
57 prop->clk_stop_mode |= SDW_CLK_STOP_MODE1;
59 fwnode_property_read_u32(link,
60 "mipi-sdw-max-clock-frequency",
63 nval = fwnode_property_read_u32_array(link,
64 "mipi-sdw-clock-frequencies-supported", NULL, 0);
66 prop->num_freq = nval;
67 prop->freq = devm_kcalloc(bus->dev, prop->num_freq,
68 sizeof(*prop->freq), GFP_KERNEL);
72 fwnode_property_read_u32_array(link,
73 "mipi-sdw-clock-frequencies-supported",
74 prop->freq, prop->num_freq);
78 * Check the frequencies supported. If FW doesn't provide max
79 * freq, then populate here by checking values.
81 if (!prop->max_freq && prop->freq) {
82 prop->max_freq = prop->freq[0];
83 for (i = 1; i < prop->num_freq; i++) {
84 if (prop->freq[i] > prop->max_freq)
85 prop->max_freq = prop->freq[i];
89 nval = fwnode_property_read_u32_array(link,
90 "mipi-sdw-supported-clock-gears", NULL, 0);
92 prop->num_clk_gears = nval;
93 prop->clk_gears = devm_kcalloc(bus->dev, prop->num_clk_gears,
94 sizeof(*prop->clk_gears),
99 fwnode_property_read_u32_array(link,
100 "mipi-sdw-supported-clock-gears",
102 prop->num_clk_gears);
105 fwnode_property_read_u32(link, "mipi-sdw-default-frame-rate",
106 &prop->default_frame_rate);
108 fwnode_property_read_u32(link, "mipi-sdw-default-frame-row-size",
111 fwnode_property_read_u32(link, "mipi-sdw-default-frame-col-size",
114 prop->dynamic_frame = fwnode_property_read_bool(link,
115 "mipi-sdw-dynamic-frame-shape");
117 fwnode_property_read_u32(link, "mipi-sdw-command-error-threshold",
118 &prop->err_threshold);
122 EXPORT_SYMBOL(sdw_master_read_prop);
124 static int sdw_slave_read_dp0(struct sdw_slave *slave,
125 struct fwnode_handle *port,
126 struct sdw_dp0_prop *dp0)
130 fwnode_property_read_u32(port, "mipi-sdw-port-max-wordlength",
133 fwnode_property_read_u32(port, "mipi-sdw-port-min-wordlength",
136 nval = fwnode_property_read_u32_array(port,
137 "mipi-sdw-port-wordlength-configs", NULL, 0);
140 dp0->num_words = nval;
141 dp0->words = devm_kcalloc(&slave->dev,
142 dp0->num_words, sizeof(*dp0->words),
147 fwnode_property_read_u32_array(port,
148 "mipi-sdw-port-wordlength-configs",
149 dp0->words, dp0->num_words);
152 dp0->flow_controlled = fwnode_property_read_bool(port,
153 "mipi-sdw-bra-flow-controlled");
155 dp0->simple_ch_prep_sm = fwnode_property_read_bool(port,
156 "mipi-sdw-simplified-channel-prepare-sm");
158 dp0->device_interrupts = fwnode_property_read_bool(port,
159 "mipi-sdw-imp-def-dp0-interrupts-supported");
164 static int sdw_slave_read_dpn(struct sdw_slave *slave,
165 struct sdw_dpn_prop *dpn, int count, int ports,
168 struct fwnode_handle *node;
175 /* valid ports are 1 to 14 so apply mask */
176 addr &= GENMASK(14, 1);
178 for_each_set_bit(bit, &addr, 32) {
179 snprintf(name, sizeof(name),
180 "mipi-sdw-dp-%d-%s-subproperties", bit, type);
184 node = device_get_named_child_node(&slave->dev, name);
186 dev_err(&slave->dev, "%s dpN not found\n", name);
190 fwnode_property_read_u32(node, "mipi-sdw-port-max-wordlength",
192 fwnode_property_read_u32(node, "mipi-sdw-port-min-wordlength",
195 nval = fwnode_property_read_u32_array(node,
196 "mipi-sdw-port-wordlength-configs", NULL, 0);
198 dpn[i].num_words = nval;
199 dpn[i].words = devm_kcalloc(&slave->dev,
201 sizeof(*dpn[i].words),
206 fwnode_property_read_u32_array(node,
207 "mipi-sdw-port-wordlength-configs",
208 dpn[i].words, dpn[i].num_words);
211 fwnode_property_read_u32(node, "mipi-sdw-data-port-type",
214 fwnode_property_read_u32(node,
215 "mipi-sdw-max-grouping-supported",
216 &dpn[i].max_grouping);
218 dpn[i].simple_ch_prep_sm = fwnode_property_read_bool(node,
219 "mipi-sdw-simplified-channelprepare-sm");
221 fwnode_property_read_u32(node,
222 "mipi-sdw-port-channelprepare-timeout",
223 &dpn[i].ch_prep_timeout);
225 fwnode_property_read_u32(node,
226 "mipi-sdw-imp-def-dpn-interrupts-supported",
227 &dpn[i].device_interrupts);
229 fwnode_property_read_u32(node, "mipi-sdw-min-channel-number",
232 fwnode_property_read_u32(node, "mipi-sdw-max-channel-number",
235 nval = fwnode_property_read_u32_array(node,
236 "mipi-sdw-channel-number-list", NULL, 0);
238 dpn[i].num_ch = nval;
239 dpn[i].ch = devm_kcalloc(&slave->dev, dpn[i].num_ch,
245 fwnode_property_read_u32_array(node,
246 "mipi-sdw-channel-number-list",
247 dpn[i].ch, dpn[i].num_ch);
250 nval = fwnode_property_read_u32_array(node,
251 "mipi-sdw-channel-combination-list", NULL, 0);
253 dpn[i].num_ch_combinations = nval;
254 dpn[i].ch_combinations = devm_kcalloc(&slave->dev,
255 dpn[i].num_ch_combinations,
256 sizeof(*dpn[i].ch_combinations),
258 if (!dpn[i].ch_combinations)
261 fwnode_property_read_u32_array(node,
262 "mipi-sdw-channel-combination-list",
263 dpn[i].ch_combinations,
264 dpn[i].num_ch_combinations);
267 fwnode_property_read_u32(node,
268 "mipi-sdw-modes-supported", &dpn[i].modes);
270 fwnode_property_read_u32(node, "mipi-sdw-max-async-buffer",
271 &dpn[i].max_async_buffer);
273 dpn[i].block_pack_mode = fwnode_property_read_bool(node,
274 "mipi-sdw-block-packing-mode");
276 fwnode_property_read_u32(node, "mipi-sdw-port-encoding-type",
277 &dpn[i].port_encoding);
279 /* TODO: Read audio mode */
288 * sdw_slave_read_prop() - Read Slave properties
291 int sdw_slave_read_prop(struct sdw_slave *slave)
293 struct sdw_slave_prop *prop = &slave->prop;
294 struct device *dev = &slave->dev;
295 struct fwnode_handle *port;
296 int num_of_ports, nval, i, dp0 = 0;
298 device_property_read_u32(dev, "mipi-sdw-sw-interface-revision",
299 &prop->mipi_revision);
301 prop->wake_capable = device_property_read_bool(dev,
302 "mipi-sdw-wake-up-unavailable");
303 prop->wake_capable = !prop->wake_capable;
305 prop->test_mode_capable = device_property_read_bool(dev,
306 "mipi-sdw-test-mode-supported");
308 prop->clk_stop_mode1 = false;
309 if (device_property_read_bool(dev,
310 "mipi-sdw-clock-stop-mode1-supported"))
311 prop->clk_stop_mode1 = true;
313 prop->simple_clk_stop_capable = device_property_read_bool(dev,
314 "mipi-sdw-simplified-clockstopprepare-sm-supported");
316 device_property_read_u32(dev, "mipi-sdw-clockstopprepare-timeout",
317 &prop->clk_stop_timeout);
319 device_property_read_u32(dev, "mipi-sdw-slave-channelprepare-timeout",
320 &prop->ch_prep_timeout);
322 device_property_read_u32(dev,
323 "mipi-sdw-clockstopprepare-hard-reset-behavior",
324 &prop->reset_behave);
326 prop->high_PHY_capable = device_property_read_bool(dev,
327 "mipi-sdw-highPHY-capable");
329 prop->paging_support = device_property_read_bool(dev,
330 "mipi-sdw-paging-support");
332 prop->bank_delay_support = device_property_read_bool(dev,
333 "mipi-sdw-bank-delay-support");
335 device_property_read_u32(dev,
336 "mipi-sdw-port15-read-behavior", &prop->p15_behave);
338 device_property_read_u32(dev, "mipi-sdw-master-count",
339 &prop->master_count);
341 device_property_read_u32(dev, "mipi-sdw-source-port-list",
342 &prop->source_ports);
344 device_property_read_u32(dev, "mipi-sdw-sink-port-list",
347 /* Read dp0 properties */
348 port = device_get_named_child_node(dev, "mipi-sdw-dp-0-subproperties");
350 dev_dbg(dev, "DP0 node not found!!\n");
352 prop->dp0_prop = devm_kzalloc(&slave->dev,
353 sizeof(*prop->dp0_prop),
358 sdw_slave_read_dp0(slave, port, prop->dp0_prop);
363 * Based on each DPn port, get source and sink dpn properties.
364 * Also, some ports can operate as both source or sink.
367 /* Allocate memory for set bits in port lists */
368 nval = hweight32(prop->source_ports);
369 prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval,
370 sizeof(*prop->src_dpn_prop),
372 if (!prop->src_dpn_prop)
375 /* Read dpn properties for source port(s) */
376 sdw_slave_read_dpn(slave, prop->src_dpn_prop, nval,
377 prop->source_ports, "source");
379 nval = hweight32(prop->sink_ports);
380 prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval,
381 sizeof(*prop->sink_dpn_prop),
383 if (!prop->sink_dpn_prop)
386 /* Read dpn properties for sink port(s) */
387 sdw_slave_read_dpn(slave, prop->sink_dpn_prop, nval,
388 prop->sink_ports, "sink");
390 /* some ports are bidirectional so check total ports by ORing */
391 nval = prop->source_ports | prop->sink_ports;
392 num_of_ports = hweight32(nval) + dp0; /* add DP0 */
394 /* Allocate port_ready based on num_of_ports */
395 slave->port_ready = devm_kcalloc(&slave->dev, num_of_ports,
396 sizeof(*slave->port_ready),
398 if (!slave->port_ready)
401 /* Initialize completion */
402 for (i = 0; i < num_of_ports; i++)
403 init_completion(&slave->port_ready[i]);
407 EXPORT_SYMBOL(sdw_slave_read_prop);