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>
26 static bool mipi_fwnode_property_read_bool(const struct fwnode_handle
*fwnode
,
32 if (!fwnode_property_present(fwnode
, propname
))
34 ret
= fwnode_property_read_u8_array(fwnode
, propname
, &val
, 1);
40 static bool mipi_device_property_read_bool(const struct device
*dev
,
43 return mipi_fwnode_property_read_bool(dev_fwnode(dev
), propname
);
47 * sdw_master_read_prop() - Read Master properties
48 * @bus: SDW bus instance
50 int sdw_master_read_prop(struct sdw_bus
*bus
)
52 struct sdw_master_prop
*prop
= &bus
->prop
;
53 struct fwnode_handle
*link
;
54 const char *scales_prop
;
60 device_property_read_u32(bus
->dev
,
61 "mipi-sdw-sw-interface-revision",
64 /* Find master handle */
65 snprintf(name
, sizeof(name
),
66 "mipi-sdw-link-%d-subproperties", bus
->link_id
);
68 link
= device_get_named_child_node(bus
->dev
, name
);
70 dev_err(bus
->dev
, "Master node %s not found\n", name
);
74 if (mipi_fwnode_property_read_bool(link
,
75 "mipi-sdw-clock-stop-mode0-supported"))
76 prop
->clk_stop_modes
|= BIT(SDW_CLK_STOP_MODE0
);
78 if (mipi_fwnode_property_read_bool(link
,
79 "mipi-sdw-clock-stop-mode1-supported"))
80 prop
->clk_stop_modes
|= BIT(SDW_CLK_STOP_MODE1
);
82 fwnode_property_read_u32(link
,
83 "mipi-sdw-max-clock-frequency",
86 nval
= fwnode_property_count_u32(link
, "mipi-sdw-clock-frequencies-supported");
88 prop
->num_clk_freq
= nval
;
89 prop
->clk_freq
= devm_kcalloc(bus
->dev
, prop
->num_clk_freq
,
90 sizeof(*prop
->clk_freq
),
92 if (!prop
->clk_freq
) {
93 fwnode_handle_put(link
);
97 ret
= fwnode_property_read_u32_array(link
,
98 "mipi-sdw-clock-frequencies-supported",
99 prop
->clk_freq
, prop
->num_clk_freq
);
105 * Check the frequencies supported. If FW doesn't provide max
106 * freq, then populate here by checking values.
108 if (!prop
->max_clk_freq
&& prop
->clk_freq
) {
109 prop
->max_clk_freq
= prop
->clk_freq
[0];
110 for (i
= 1; i
< prop
->num_clk_freq
; i
++) {
111 if (prop
->clk_freq
[i
] > prop
->max_clk_freq
)
112 prop
->max_clk_freq
= prop
->clk_freq
[i
];
116 scales_prop
= "mipi-sdw-supported-clock-scales";
117 nval
= fwnode_property_count_u32(link
, scales_prop
);
119 scales_prop
= "mipi-sdw-supported-clock-gears";
120 nval
= fwnode_property_count_u32(link
, scales_prop
);
123 prop
->num_clk_gears
= nval
;
124 prop
->clk_gears
= devm_kcalloc(bus
->dev
, prop
->num_clk_gears
,
125 sizeof(*prop
->clk_gears
),
127 if (!prop
->clk_gears
) {
128 fwnode_handle_put(link
);
132 ret
= fwnode_property_read_u32_array(link
,
135 prop
->num_clk_gears
);
140 fwnode_property_read_u32(link
, "mipi-sdw-default-frame-rate",
141 &prop
->default_frame_rate
);
143 fwnode_property_read_u32(link
, "mipi-sdw-default-frame-row-size",
146 fwnode_property_read_u32(link
, "mipi-sdw-default-frame-col-size",
149 prop
->dynamic_frame
= mipi_fwnode_property_read_bool(link
,
150 "mipi-sdw-dynamic-frame-shape");
152 fwnode_property_read_u32(link
, "mipi-sdw-command-error-threshold",
153 &prop
->err_threshold
);
155 fwnode_handle_put(link
);
159 EXPORT_SYMBOL(sdw_master_read_prop
);
161 static int sdw_slave_read_dp0(struct sdw_slave
*slave
,
162 struct fwnode_handle
*port
,
163 struct sdw_dp0_prop
*dp0
)
168 fwnode_property_read_u32(port
, "mipi-sdw-port-max-wordlength",
171 fwnode_property_read_u32(port
, "mipi-sdw-port-min-wordlength",
174 nval
= fwnode_property_count_u32(port
, "mipi-sdw-port-wordlength-configs");
177 dp0
->num_words
= nval
;
178 dp0
->words
= devm_kcalloc(&slave
->dev
,
179 dp0
->num_words
, sizeof(*dp0
->words
),
184 ret
= fwnode_property_read_u32_array(port
,
185 "mipi-sdw-port-wordlength-configs",
186 dp0
->words
, dp0
->num_words
);
191 dp0
->BRA_flow_controlled
= mipi_fwnode_property_read_bool(port
,
192 "mipi-sdw-bra-flow-controlled");
194 dp0
->simple_ch_prep_sm
= mipi_fwnode_property_read_bool(port
,
195 "mipi-sdw-simplified-channel-prepare-sm");
197 dp0
->imp_def_interrupts
= mipi_fwnode_property_read_bool(port
,
198 "mipi-sdw-imp-def-dp0-interrupts-supported");
200 nval
= fwnode_property_count_u32(port
, "mipi-sdw-lane-list");
202 dp0
->num_lanes
= nval
;
203 dp0
->lane_list
= devm_kcalloc(&slave
->dev
,
204 dp0
->num_lanes
, sizeof(*dp0
->lane_list
),
209 ret
= fwnode_property_read_u32_array(port
,
210 "mipi-sdw-lane-list",
211 dp0
->lane_list
, dp0
->num_lanes
);
219 static int sdw_slave_read_dpn(struct sdw_slave
*slave
,
220 struct sdw_dpn_prop
*dpn
, int count
, int ports
,
223 struct fwnode_handle
*node
;
231 /* valid ports are 1 to 14 so apply mask */
232 addr
&= GENMASK(14, 1);
234 for_each_set_bit(bit
, &addr
, 32) {
235 snprintf(name
, sizeof(name
),
236 "mipi-sdw-dp-%d-%s-subproperties", bit
, type
);
240 node
= device_get_named_child_node(&slave
->dev
, name
);
242 dev_err(&slave
->dev
, "%s dpN not found\n", name
);
246 fwnode_property_read_u32(node
, "mipi-sdw-port-max-wordlength",
248 fwnode_property_read_u32(node
, "mipi-sdw-port-min-wordlength",
251 nval
= fwnode_property_count_u32(node
, "mipi-sdw-port-wordlength-configs");
253 dpn
[i
].num_words
= nval
;
254 dpn
[i
].words
= devm_kcalloc(&slave
->dev
,
256 sizeof(*dpn
[i
].words
),
259 fwnode_handle_put(node
);
263 ret
= fwnode_property_read_u32_array(node
,
264 "mipi-sdw-port-wordlength-configs",
265 dpn
[i
].words
, dpn
[i
].num_words
);
270 fwnode_property_read_u32(node
, "mipi-sdw-data-port-type",
273 fwnode_property_read_u32(node
,
274 "mipi-sdw-max-grouping-supported",
275 &dpn
[i
].max_grouping
);
277 dpn
[i
].simple_ch_prep_sm
= mipi_fwnode_property_read_bool(node
,
278 "mipi-sdw-simplified-channelprepare-sm");
280 fwnode_property_read_u32(node
,
281 "mipi-sdw-port-channelprepare-timeout",
282 &dpn
[i
].ch_prep_timeout
);
284 fwnode_property_read_u32(node
,
285 "mipi-sdw-imp-def-dpn-interrupts-supported",
286 &dpn
[i
].imp_def_interrupts
);
288 fwnode_property_read_u32(node
, "mipi-sdw-min-channel-number",
291 fwnode_property_read_u32(node
, "mipi-sdw-max-channel-number",
294 nval
= fwnode_property_count_u32(node
, "mipi-sdw-channel-number-list");
296 dpn
[i
].num_channels
= nval
;
297 dpn
[i
].channels
= devm_kcalloc(&slave
->dev
,
299 sizeof(*dpn
[i
].channels
),
301 if (!dpn
[i
].channels
) {
302 fwnode_handle_put(node
);
306 ret
= fwnode_property_read_u32_array(node
,
307 "mipi-sdw-channel-number-list",
308 dpn
[i
].channels
, dpn
[i
].num_channels
);
313 nval
= fwnode_property_count_u32(node
, "mipi-sdw-channel-combination-list");
315 dpn
[i
].num_ch_combinations
= nval
;
316 dpn
[i
].ch_combinations
= devm_kcalloc(&slave
->dev
,
317 dpn
[i
].num_ch_combinations
,
318 sizeof(*dpn
[i
].ch_combinations
),
320 if (!dpn
[i
].ch_combinations
) {
321 fwnode_handle_put(node
);
325 ret
= fwnode_property_read_u32_array(node
,
326 "mipi-sdw-channel-combination-list",
327 dpn
[i
].ch_combinations
,
328 dpn
[i
].num_ch_combinations
);
333 fwnode_property_read_u32(node
,
334 "mipi-sdw-modes-supported", &dpn
[i
].modes
);
336 fwnode_property_read_u32(node
, "mipi-sdw-max-async-buffer",
337 &dpn
[i
].max_async_buffer
);
339 dpn
[i
].block_pack_mode
= mipi_fwnode_property_read_bool(node
,
340 "mipi-sdw-block-packing-mode");
342 fwnode_property_read_u32(node
, "mipi-sdw-port-encoding-type",
343 &dpn
[i
].port_encoding
);
345 nval
= fwnode_property_count_u32(node
, "mipi-sdw-lane-list");
347 dpn
[i
].num_lanes
= nval
;
348 dpn
[i
].lane_list
= devm_kcalloc(&slave
->dev
,
349 dpn
[i
].num_lanes
, sizeof(*dpn
[i
].lane_list
),
351 if (!dpn
[i
].lane_list
)
354 ret
= fwnode_property_read_u32_array(node
,
355 "mipi-sdw-lane-list",
356 dpn
[i
].lane_list
, dpn
[i
].num_lanes
);
361 fwnode_handle_put(node
);
370 * sdw_slave_read_prop() - Read Slave properties
373 int sdw_slave_read_prop(struct sdw_slave
*slave
)
375 struct sdw_slave_prop
*prop
= &slave
->prop
;
376 struct device
*dev
= &slave
->dev
;
377 struct fwnode_handle
*port
;
381 device_property_read_u32(dev
, "mipi-sdw-sw-interface-revision",
382 &prop
->mipi_revision
);
384 prop
->wake_capable
= mipi_device_property_read_bool(dev
,
385 "mipi-sdw-wake-up-unavailable");
386 prop
->wake_capable
= !prop
->wake_capable
;
388 prop
->test_mode_capable
= mipi_device_property_read_bool(dev
,
389 "mipi-sdw-test-mode-supported");
391 prop
->clk_stop_mode1
= false;
392 if (mipi_device_property_read_bool(dev
,
393 "mipi-sdw-clock-stop-mode1-supported"))
394 prop
->clk_stop_mode1
= true;
396 prop
->simple_clk_stop_capable
= mipi_device_property_read_bool(dev
,
397 "mipi-sdw-simplified-clockstopprepare-sm-supported");
399 device_property_read_u32(dev
, "mipi-sdw-clockstopprepare-timeout",
400 &prop
->clk_stop_timeout
);
402 ret
= device_property_read_u32(dev
, "mipi-sdw-peripheral-channelprepare-timeout",
403 &prop
->ch_prep_timeout
);
405 device_property_read_u32(dev
, "mipi-sdw-slave-channelprepare-timeout",
406 &prop
->ch_prep_timeout
);
408 device_property_read_u32(dev
,
409 "mipi-sdw-clockstopprepare-hard-reset-behavior",
410 &prop
->reset_behave
);
412 prop
->high_PHY_capable
= mipi_device_property_read_bool(dev
,
413 "mipi-sdw-highPHY-capable");
415 prop
->paging_support
= mipi_device_property_read_bool(dev
,
416 "mipi-sdw-paging-support");
418 prop
->bank_delay_support
= mipi_device_property_read_bool(dev
,
419 "mipi-sdw-bank-delay-support");
421 device_property_read_u32(dev
,
422 "mipi-sdw-port15-read-behavior", &prop
->p15_behave
);
424 device_property_read_u32(dev
, "mipi-sdw-master-count",
425 &prop
->master_count
);
427 device_property_read_u32(dev
, "mipi-sdw-source-port-list",
428 &prop
->source_ports
);
430 device_property_read_u32(dev
, "mipi-sdw-sink-port-list",
433 device_property_read_u32(dev
, "mipi-sdw-sdca-interrupt-register-list",
434 &prop
->sdca_interrupt_register_list
);
436 prop
->commit_register_supported
= mipi_device_property_read_bool(dev
,
437 "mipi-sdw-commit-register-supported");
440 * Read dp0 properties - we don't rely on the 'mipi-sdw-dp-0-supported'
441 * property since the 'mipi-sdw-dp0-subproperties' property is logically
444 port
= device_get_named_child_node(dev
, "mipi-sdw-dp-0-subproperties");
446 dev_dbg(dev
, "DP0 node not found!!\n");
448 prop
->dp0_prop
= devm_kzalloc(&slave
->dev
,
449 sizeof(*prop
->dp0_prop
),
451 if (!prop
->dp0_prop
) {
452 fwnode_handle_put(port
);
456 sdw_slave_read_dp0(slave
, port
, prop
->dp0_prop
);
458 fwnode_handle_put(port
);
462 * Based on each DPn port, get source and sink dpn properties.
463 * Also, some ports can operate as both source or sink.
466 /* Allocate memory for set bits in port lists */
467 nval
= hweight32(prop
->source_ports
);
468 prop
->src_dpn_prop
= devm_kcalloc(&slave
->dev
, nval
,
469 sizeof(*prop
->src_dpn_prop
),
471 if (!prop
->src_dpn_prop
)
474 /* Read dpn properties for source port(s) */
475 sdw_slave_read_dpn(slave
, prop
->src_dpn_prop
, nval
,
476 prop
->source_ports
, "source");
478 nval
= hweight32(prop
->sink_ports
);
479 prop
->sink_dpn_prop
= devm_kcalloc(&slave
->dev
, nval
,
480 sizeof(*prop
->sink_dpn_prop
),
482 if (!prop
->sink_dpn_prop
)
485 /* Read dpn properties for sink port(s) */
486 sdw_slave_read_dpn(slave
, prop
->sink_dpn_prop
, nval
,
487 prop
->sink_ports
, "sink");
491 EXPORT_SYMBOL(sdw_slave_read_prop
);