hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/drivers/soundwire/mipi_disco.c
....@@ -35,11 +35,12 @@
3535 int nval, i;
3636
3737 device_property_read_u32(bus->dev,
38
- "mipi-sdw-sw-interface-revision", &prop->revision);
38
+ "mipi-sdw-sw-interface-revision",
39
+ &prop->revision);
3940
4041 /* Find master handle */
4142 snprintf(name, sizeof(name),
42
- "mipi-sdw-master-%d-subproperties", bus->link_id);
43
+ "mipi-sdw-link-%d-subproperties", bus->link_id);
4344
4445 link = device_get_named_child_node(bus->dev, name);
4546 if (!link) {
....@@ -48,96 +49,96 @@
4849 }
4950
5051 if (fwnode_property_read_bool(link,
51
- "mipi-sdw-clock-stop-mode0-supported") == true)
52
- prop->clk_stop_mode = SDW_CLK_STOP_MODE0;
52
+ "mipi-sdw-clock-stop-mode0-supported"))
53
+ prop->clk_stop_modes |= BIT(SDW_CLK_STOP_MODE0);
5354
5455 if (fwnode_property_read_bool(link,
55
- "mipi-sdw-clock-stop-mode1-supported") == true)
56
- prop->clk_stop_mode |= SDW_CLK_STOP_MODE1;
56
+ "mipi-sdw-clock-stop-mode1-supported"))
57
+ prop->clk_stop_modes |= BIT(SDW_CLK_STOP_MODE1);
5758
5859 fwnode_property_read_u32(link,
59
- "mipi-sdw-max-clock-frequency", &prop->max_freq);
60
+ "mipi-sdw-max-clock-frequency",
61
+ &prop->max_clk_freq);
6062
61
- nval = fwnode_property_read_u32_array(link,
62
- "mipi-sdw-clock-frequencies-supported", NULL, 0);
63
+ nval = fwnode_property_count_u32(link, "mipi-sdw-clock-frequencies-supported");
6364 if (nval > 0) {
64
-
65
- prop->num_freq = nval;
66
- prop->freq = devm_kcalloc(bus->dev, prop->num_freq,
67
- sizeof(*prop->freq), GFP_KERNEL);
68
- if (!prop->freq)
65
+ prop->num_clk_freq = nval;
66
+ prop->clk_freq = devm_kcalloc(bus->dev, prop->num_clk_freq,
67
+ sizeof(*prop->clk_freq),
68
+ GFP_KERNEL);
69
+ if (!prop->clk_freq)
6970 return -ENOMEM;
7071
7172 fwnode_property_read_u32_array(link,
7273 "mipi-sdw-clock-frequencies-supported",
73
- prop->freq, prop->num_freq);
74
+ prop->clk_freq, prop->num_clk_freq);
7475 }
7576
7677 /*
7778 * Check the frequencies supported. If FW doesn't provide max
7879 * freq, then populate here by checking values.
7980 */
80
- if (!prop->max_freq && prop->freq) {
81
- prop->max_freq = prop->freq[0];
82
- for (i = 1; i < prop->num_freq; i++) {
83
- if (prop->freq[i] > prop->max_freq)
84
- prop->max_freq = prop->freq[i];
81
+ if (!prop->max_clk_freq && prop->clk_freq) {
82
+ prop->max_clk_freq = prop->clk_freq[0];
83
+ for (i = 1; i < prop->num_clk_freq; i++) {
84
+ if (prop->clk_freq[i] > prop->max_clk_freq)
85
+ prop->max_clk_freq = prop->clk_freq[i];
8586 }
8687 }
8788
88
- nval = fwnode_property_read_u32_array(link,
89
- "mipi-sdw-supported-clock-gears", NULL, 0);
89
+ nval = fwnode_property_count_u32(link, "mipi-sdw-supported-clock-gears");
9090 if (nval > 0) {
91
-
9291 prop->num_clk_gears = nval;
9392 prop->clk_gears = devm_kcalloc(bus->dev, prop->num_clk_gears,
94
- sizeof(*prop->clk_gears), GFP_KERNEL);
93
+ sizeof(*prop->clk_gears),
94
+ GFP_KERNEL);
9595 if (!prop->clk_gears)
9696 return -ENOMEM;
9797
9898 fwnode_property_read_u32_array(link,
99
- "mipi-sdw-supported-clock-gears",
100
- prop->clk_gears, prop->num_clk_gears);
99
+ "mipi-sdw-supported-clock-gears",
100
+ prop->clk_gears,
101
+ prop->num_clk_gears);
101102 }
102103
103104 fwnode_property_read_u32(link, "mipi-sdw-default-frame-rate",
104
- &prop->default_frame_rate);
105
+ &prop->default_frame_rate);
105106
106107 fwnode_property_read_u32(link, "mipi-sdw-default-frame-row-size",
107
- &prop->default_row);
108
+ &prop->default_row);
108109
109110 fwnode_property_read_u32(link, "mipi-sdw-default-frame-col-size",
110
- &prop->default_col);
111
+ &prop->default_col);
111112
112113 prop->dynamic_frame = fwnode_property_read_bool(link,
113114 "mipi-sdw-dynamic-frame-shape");
114115
115116 fwnode_property_read_u32(link, "mipi-sdw-command-error-threshold",
116
- &prop->err_threshold);
117
+ &prop->err_threshold);
117118
118119 return 0;
119120 }
120121 EXPORT_SYMBOL(sdw_master_read_prop);
121122
122123 static int sdw_slave_read_dp0(struct sdw_slave *slave,
123
- struct fwnode_handle *port, struct sdw_dp0_prop *dp0)
124
+ struct fwnode_handle *port,
125
+ struct sdw_dp0_prop *dp0)
124126 {
125127 int nval;
126128
127129 fwnode_property_read_u32(port, "mipi-sdw-port-max-wordlength",
128
- &dp0->max_word);
130
+ &dp0->max_word);
129131
130132 fwnode_property_read_u32(port, "mipi-sdw-port-min-wordlength",
131
- &dp0->min_word);
133
+ &dp0->min_word);
132134
133
- nval = fwnode_property_read_u32_array(port,
134
- "mipi-sdw-port-wordlength-configs", NULL, 0);
135
+ nval = fwnode_property_count_u32(port, "mipi-sdw-port-wordlength-configs");
135136 if (nval > 0) {
136137
137138 dp0->num_words = nval;
138139 dp0->words = devm_kcalloc(&slave->dev,
139
- dp0->num_words, sizeof(*dp0->words),
140
- GFP_KERNEL);
140
+ dp0->num_words, sizeof(*dp0->words),
141
+ GFP_KERNEL);
141142 if (!dp0->words)
142143 return -ENOMEM;
143144
....@@ -146,20 +147,21 @@
146147 dp0->words, dp0->num_words);
147148 }
148149
149
- dp0->flow_controlled = fwnode_property_read_bool(
150
- port, "mipi-sdw-bra-flow-controlled");
150
+ dp0->BRA_flow_controlled = fwnode_property_read_bool(port,
151
+ "mipi-sdw-bra-flow-controlled");
151152
152
- dp0->simple_ch_prep_sm = fwnode_property_read_bool(
153
- port, "mipi-sdw-simplified-channel-prepare-sm");
153
+ dp0->simple_ch_prep_sm = fwnode_property_read_bool(port,
154
+ "mipi-sdw-simplified-channel-prepare-sm");
154155
155
- dp0->device_interrupts = fwnode_property_read_bool(
156
- port, "mipi-sdw-imp-def-dp0-interrupts-supported");
156
+ dp0->imp_def_interrupts = fwnode_property_read_bool(port,
157
+ "mipi-sdw-imp-def-dp0-interrupts-supported");
157158
158159 return 0;
159160 }
160161
161162 static int sdw_slave_read_dpn(struct sdw_slave *slave,
162
- struct sdw_dpn_prop *dpn, int count, int ports, char *type)
163
+ struct sdw_dpn_prop *dpn, int count, int ports,
164
+ char *type)
163165 {
164166 struct fwnode_handle *node;
165167 u32 bit, i = 0;
....@@ -173,7 +175,7 @@
173175
174176 for_each_set_bit(bit, &addr, 32) {
175177 snprintf(name, sizeof(name),
176
- "mipi-sdw-dp-%d-%s-subproperties", bit, type);
178
+ "mipi-sdw-dp-%d-%s-subproperties", bit, type);
177179
178180 dpn[i].num = bit;
179181
....@@ -184,18 +186,17 @@
184186 }
185187
186188 fwnode_property_read_u32(node, "mipi-sdw-port-max-wordlength",
187
- &dpn[i].max_word);
189
+ &dpn[i].max_word);
188190 fwnode_property_read_u32(node, "mipi-sdw-port-min-wordlength",
189
- &dpn[i].min_word);
191
+ &dpn[i].min_word);
190192
191
- nval = fwnode_property_read_u32_array(node,
192
- "mipi-sdw-port-wordlength-configs", NULL, 0);
193
+ nval = fwnode_property_count_u32(node, "mipi-sdw-port-wordlength-configs");
193194 if (nval > 0) {
194
-
195195 dpn[i].num_words = nval;
196196 dpn[i].words = devm_kcalloc(&slave->dev,
197
- dpn[i].num_words,
198
- sizeof(*dpn[i].words), GFP_KERNEL);
197
+ dpn[i].num_words,
198
+ sizeof(*dpn[i].words),
199
+ GFP_KERNEL);
199200 if (!dpn[i].words)
200201 return -ENOMEM;
201202
....@@ -205,48 +206,46 @@
205206 }
206207
207208 fwnode_property_read_u32(node, "mipi-sdw-data-port-type",
208
- &dpn[i].type);
209
+ &dpn[i].type);
209210
210211 fwnode_property_read_u32(node,
211
- "mipi-sdw-max-grouping-supported",
212
- &dpn[i].max_grouping);
212
+ "mipi-sdw-max-grouping-supported",
213
+ &dpn[i].max_grouping);
213214
214215 dpn[i].simple_ch_prep_sm = fwnode_property_read_bool(node,
215216 "mipi-sdw-simplified-channelprepare-sm");
216217
217218 fwnode_property_read_u32(node,
218
- "mipi-sdw-port-channelprepare-timeout",
219
- &dpn[i].ch_prep_timeout);
219
+ "mipi-sdw-port-channelprepare-timeout",
220
+ &dpn[i].ch_prep_timeout);
220221
221222 fwnode_property_read_u32(node,
222223 "mipi-sdw-imp-def-dpn-interrupts-supported",
223
- &dpn[i].device_interrupts);
224
+ &dpn[i].imp_def_interrupts);
224225
225226 fwnode_property_read_u32(node, "mipi-sdw-min-channel-number",
226
- &dpn[i].min_ch);
227
+ &dpn[i].min_ch);
227228
228229 fwnode_property_read_u32(node, "mipi-sdw-max-channel-number",
229
- &dpn[i].max_ch);
230
+ &dpn[i].max_ch);
230231
231
- nval = fwnode_property_read_u32_array(node,
232
- "mipi-sdw-channel-number-list", NULL, 0);
232
+ nval = fwnode_property_count_u32(node, "mipi-sdw-channel-number-list");
233233 if (nval > 0) {
234
-
235
- dpn[i].num_ch = nval;
236
- dpn[i].ch = devm_kcalloc(&slave->dev, dpn[i].num_ch,
237
- sizeof(*dpn[i].ch), GFP_KERNEL);
238
- if (!dpn[i].ch)
234
+ dpn[i].num_channels = nval;
235
+ dpn[i].channels = devm_kcalloc(&slave->dev,
236
+ dpn[i].num_channels,
237
+ sizeof(*dpn[i].channels),
238
+ GFP_KERNEL);
239
+ if (!dpn[i].channels)
239240 return -ENOMEM;
240241
241242 fwnode_property_read_u32_array(node,
242243 "mipi-sdw-channel-number-list",
243
- dpn[i].ch, dpn[i].num_ch);
244
+ dpn[i].channels, dpn[i].num_channels);
244245 }
245246
246
- nval = fwnode_property_read_u32_array(node,
247
- "mipi-sdw-channel-combination-list", NULL, 0);
247
+ nval = fwnode_property_count_u32(node, "mipi-sdw-channel-combination-list");
248248 if (nval > 0) {
249
-
250249 dpn[i].num_ch_combinations = nval;
251250 dpn[i].ch_combinations = devm_kcalloc(&slave->dev,
252251 dpn[i].num_ch_combinations,
....@@ -265,13 +264,13 @@
265264 "mipi-sdw-modes-supported", &dpn[i].modes);
266265
267266 fwnode_property_read_u32(node, "mipi-sdw-max-async-buffer",
268
- &dpn[i].max_async_buffer);
267
+ &dpn[i].max_async_buffer);
269268
270269 dpn[i].block_pack_mode = fwnode_property_read_bool(node,
271270 "mipi-sdw-block-packing-mode");
272271
273272 fwnode_property_read_u32(node, "mipi-sdw-port-encoding-type",
274
- &dpn[i].port_encoding);
273
+ &dpn[i].port_encoding);
275274
276275 /* TODO: Read audio mode */
277276
....@@ -290,10 +289,10 @@
290289 struct sdw_slave_prop *prop = &slave->prop;
291290 struct device *dev = &slave->dev;
292291 struct fwnode_handle *port;
293
- int num_of_ports, nval, i, dp0 = 0;
292
+ int nval;
294293
295294 device_property_read_u32(dev, "mipi-sdw-sw-interface-revision",
296
- &prop->mipi_revision);
295
+ &prop->mipi_revision);
297296
298297 prop->wake_capable = device_property_read_bool(dev,
299298 "mipi-sdw-wake-up-unavailable");
....@@ -311,10 +310,10 @@
311310 "mipi-sdw-simplified-clockstopprepare-sm-supported");
312311
313312 device_property_read_u32(dev, "mipi-sdw-clockstopprepare-timeout",
314
- &prop->clk_stop_timeout);
313
+ &prop->clk_stop_timeout);
315314
316315 device_property_read_u32(dev, "mipi-sdw-slave-channelprepare-timeout",
317
- &prop->ch_prep_timeout);
316
+ &prop->ch_prep_timeout);
318317
319318 device_property_read_u32(dev,
320319 "mipi-sdw-clockstopprepare-hard-reset-behavior",
....@@ -333,27 +332,26 @@
333332 "mipi-sdw-port15-read-behavior", &prop->p15_behave);
334333
335334 device_property_read_u32(dev, "mipi-sdw-master-count",
336
- &prop->master_count);
335
+ &prop->master_count);
337336
338337 device_property_read_u32(dev, "mipi-sdw-source-port-list",
339
- &prop->source_ports);
338
+ &prop->source_ports);
340339
341340 device_property_read_u32(dev, "mipi-sdw-sink-port-list",
342
- &prop->sink_ports);
341
+ &prop->sink_ports);
343342
344343 /* Read dp0 properties */
345344 port = device_get_named_child_node(dev, "mipi-sdw-dp-0-subproperties");
346345 if (!port) {
347346 dev_dbg(dev, "DP0 node not found!!\n");
348347 } else {
349
-
350348 prop->dp0_prop = devm_kzalloc(&slave->dev,
351
- sizeof(*prop->dp0_prop), GFP_KERNEL);
349
+ sizeof(*prop->dp0_prop),
350
+ GFP_KERNEL);
352351 if (!prop->dp0_prop)
353352 return -ENOMEM;
354353
355354 sdw_slave_read_dp0(slave, port, prop->dp0_prop);
356
- dp0 = 1;
357355 }
358356
359357 /*
....@@ -364,37 +362,25 @@
364362 /* Allocate memory for set bits in port lists */
365363 nval = hweight32(prop->source_ports);
366364 prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval,
367
- sizeof(*prop->src_dpn_prop), GFP_KERNEL);
365
+ sizeof(*prop->src_dpn_prop),
366
+ GFP_KERNEL);
368367 if (!prop->src_dpn_prop)
369368 return -ENOMEM;
370369
371370 /* Read dpn properties for source port(s) */
372371 sdw_slave_read_dpn(slave, prop->src_dpn_prop, nval,
373
- prop->source_ports, "source");
372
+ prop->source_ports, "source");
374373
375374 nval = hweight32(prop->sink_ports);
376375 prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval,
377
- sizeof(*prop->sink_dpn_prop), GFP_KERNEL);
376
+ sizeof(*prop->sink_dpn_prop),
377
+ GFP_KERNEL);
378378 if (!prop->sink_dpn_prop)
379379 return -ENOMEM;
380380
381381 /* Read dpn properties for sink port(s) */
382382 sdw_slave_read_dpn(slave, prop->sink_dpn_prop, nval,
383
- prop->sink_ports, "sink");
384
-
385
- /* some ports are bidirectional so check total ports by ORing */
386
- nval = prop->source_ports | prop->sink_ports;
387
- num_of_ports = hweight32(nval) + dp0; /* add DP0 */
388
-
389
- /* Allocate port_ready based on num_of_ports */
390
- slave->port_ready = devm_kcalloc(&slave->dev, num_of_ports,
391
- sizeof(*slave->port_ready), GFP_KERNEL);
392
- if (!slave->port_ready)
393
- return -ENOMEM;
394
-
395
- /* Initialize completion */
396
- for (i = 0; i < num_of_ports; i++)
397
- init_completion(&slave->port_ready[i]);
383
+ prop->sink_ports, "sink");
398384
399385 return 0;
400386 }