Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) |
| 2 | // Copyright(c) 2015-17 Intel Corporation. |
| 3 | |
| 4 | /* |
| 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. |
| 9 | * |
| 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 |
| 17 | * here |
| 18 | */ |
| 19 | |
| 20 | #include <linux/device.h> |
| 21 | #include <linux/property.h> |
| 22 | #include <linux/mod_devicetable.h> |
| 23 | #include <linux/soundwire/sdw.h> |
| 24 | #include "bus.h" |
| 25 | |
| 26 | /** |
| 27 | * sdw_master_read_prop() - Read Master properties |
| 28 | * @bus: SDW bus instance |
| 29 | */ |
| 30 | int sdw_master_read_prop(struct sdw_bus *bus) |
| 31 | { |
| 32 | struct sdw_master_prop *prop = &bus->prop; |
| 33 | struct fwnode_handle *link; |
| 34 | char name[32]; |
| 35 | int nval, i; |
| 36 | |
| 37 | device_property_read_u32(bus->dev, |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 38 | "mipi-sdw-sw-interface-revision", |
| 39 | &prop->revision); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 40 | |
| 41 | /* Find master handle */ |
| 42 | snprintf(name, sizeof(name), |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 43 | "mipi-sdw-master-%d-subproperties", bus->link_id); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 44 | |
| 45 | link = device_get_named_child_node(bus->dev, name); |
| 46 | if (!link) { |
| 47 | dev_err(bus->dev, "Master node %s not found\n", name); |
| 48 | return -EIO; |
| 49 | } |
| 50 | |
| 51 | if (fwnode_property_read_bool(link, |
| 52 | "mipi-sdw-clock-stop-mode0-supported") == true) |
| 53 | prop->clk_stop_mode = SDW_CLK_STOP_MODE0; |
| 54 | |
| 55 | if (fwnode_property_read_bool(link, |
| 56 | "mipi-sdw-clock-stop-mode1-supported") == true) |
| 57 | prop->clk_stop_mode |= SDW_CLK_STOP_MODE1; |
| 58 | |
| 59 | fwnode_property_read_u32(link, |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 60 | "mipi-sdw-max-clock-frequency", |
| 61 | &prop->max_freq); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 62 | |
| 63 | nval = fwnode_property_read_u32_array(link, |
| 64 | "mipi-sdw-clock-frequencies-supported", NULL, 0); |
| 65 | if (nval > 0) { |
| 66 | |
| 67 | prop->num_freq = nval; |
| 68 | prop->freq = devm_kcalloc(bus->dev, prop->num_freq, |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 69 | sizeof(*prop->freq), GFP_KERNEL); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 70 | if (!prop->freq) |
| 71 | return -ENOMEM; |
| 72 | |
| 73 | fwnode_property_read_u32_array(link, |
| 74 | "mipi-sdw-clock-frequencies-supported", |
| 75 | prop->freq, prop->num_freq); |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * Check the frequencies supported. If FW doesn't provide max |
| 80 | * freq, then populate here by checking values. |
| 81 | */ |
| 82 | if (!prop->max_freq && prop->freq) { |
| 83 | prop->max_freq = prop->freq[0]; |
| 84 | for (i = 1; i < prop->num_freq; i++) { |
| 85 | if (prop->freq[i] > prop->max_freq) |
| 86 | prop->max_freq = prop->freq[i]; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | nval = fwnode_property_read_u32_array(link, |
| 91 | "mipi-sdw-supported-clock-gears", NULL, 0); |
| 92 | if (nval > 0) { |
| 93 | |
| 94 | prop->num_clk_gears = nval; |
| 95 | prop->clk_gears = devm_kcalloc(bus->dev, prop->num_clk_gears, |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 96 | sizeof(*prop->clk_gears), |
| 97 | GFP_KERNEL); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 98 | if (!prop->clk_gears) |
| 99 | return -ENOMEM; |
| 100 | |
| 101 | fwnode_property_read_u32_array(link, |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 102 | "mipi-sdw-supported-clock-gears", |
| 103 | prop->clk_gears, |
| 104 | prop->num_clk_gears); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | fwnode_property_read_u32(link, "mipi-sdw-default-frame-rate", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 108 | &prop->default_frame_rate); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 109 | |
| 110 | fwnode_property_read_u32(link, "mipi-sdw-default-frame-row-size", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 111 | &prop->default_row); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 112 | |
| 113 | fwnode_property_read_u32(link, "mipi-sdw-default-frame-col-size", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 114 | &prop->default_col); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 115 | |
| 116 | prop->dynamic_frame = fwnode_property_read_bool(link, |
| 117 | "mipi-sdw-dynamic-frame-shape"); |
| 118 | |
| 119 | fwnode_property_read_u32(link, "mipi-sdw-command-error-threshold", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 120 | &prop->err_threshold); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | EXPORT_SYMBOL(sdw_master_read_prop); |
| 125 | |
| 126 | static int sdw_slave_read_dp0(struct sdw_slave *slave, |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 127 | struct fwnode_handle *port, |
| 128 | struct sdw_dp0_prop *dp0) |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 129 | { |
| 130 | int nval; |
| 131 | |
| 132 | fwnode_property_read_u32(port, "mipi-sdw-port-max-wordlength", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 133 | &dp0->max_word); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 134 | |
| 135 | fwnode_property_read_u32(port, "mipi-sdw-port-min-wordlength", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 136 | &dp0->min_word); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 137 | |
| 138 | nval = fwnode_property_read_u32_array(port, |
| 139 | "mipi-sdw-port-wordlength-configs", NULL, 0); |
| 140 | if (nval > 0) { |
| 141 | |
| 142 | dp0->num_words = nval; |
| 143 | dp0->words = devm_kcalloc(&slave->dev, |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 144 | dp0->num_words, sizeof(*dp0->words), |
| 145 | GFP_KERNEL); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 146 | if (!dp0->words) |
| 147 | return -ENOMEM; |
| 148 | |
| 149 | fwnode_property_read_u32_array(port, |
| 150 | "mipi-sdw-port-wordlength-configs", |
| 151 | dp0->words, dp0->num_words); |
| 152 | } |
| 153 | |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 154 | dp0->flow_controlled = fwnode_property_read_bool(port, |
| 155 | "mipi-sdw-bra-flow-controlled"); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 156 | |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 157 | dp0->simple_ch_prep_sm = fwnode_property_read_bool(port, |
| 158 | "mipi-sdw-simplified-channel-prepare-sm"); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 159 | |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 160 | dp0->device_interrupts = fwnode_property_read_bool(port, |
| 161 | "mipi-sdw-imp-def-dp0-interrupts-supported"); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | static int sdw_slave_read_dpn(struct sdw_slave *slave, |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 167 | struct sdw_dpn_prop *dpn, int count, int ports, |
| 168 | char *type) |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 169 | { |
| 170 | struct fwnode_handle *node; |
| 171 | u32 bit, i = 0; |
| 172 | int nval; |
| 173 | unsigned long addr; |
| 174 | char name[40]; |
| 175 | |
| 176 | addr = ports; |
| 177 | /* valid ports are 1 to 14 so apply mask */ |
| 178 | addr &= GENMASK(14, 1); |
| 179 | |
| 180 | for_each_set_bit(bit, &addr, 32) { |
| 181 | snprintf(name, sizeof(name), |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 182 | "mipi-sdw-dp-%d-%s-subproperties", bit, type); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 183 | |
| 184 | dpn[i].num = bit; |
| 185 | |
| 186 | node = device_get_named_child_node(&slave->dev, name); |
| 187 | if (!node) { |
| 188 | dev_err(&slave->dev, "%s dpN not found\n", name); |
| 189 | return -EIO; |
| 190 | } |
| 191 | |
| 192 | fwnode_property_read_u32(node, "mipi-sdw-port-max-wordlength", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 193 | &dpn[i].max_word); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 194 | fwnode_property_read_u32(node, "mipi-sdw-port-min-wordlength", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 195 | &dpn[i].min_word); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 196 | |
| 197 | nval = fwnode_property_read_u32_array(node, |
| 198 | "mipi-sdw-port-wordlength-configs", NULL, 0); |
| 199 | if (nval > 0) { |
| 200 | |
| 201 | dpn[i].num_words = nval; |
| 202 | dpn[i].words = devm_kcalloc(&slave->dev, |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 203 | dpn[i].num_words, |
| 204 | sizeof(*dpn[i].words), |
| 205 | GFP_KERNEL); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 206 | if (!dpn[i].words) |
| 207 | return -ENOMEM; |
| 208 | |
| 209 | fwnode_property_read_u32_array(node, |
| 210 | "mipi-sdw-port-wordlength-configs", |
| 211 | dpn[i].words, dpn[i].num_words); |
| 212 | } |
| 213 | |
| 214 | fwnode_property_read_u32(node, "mipi-sdw-data-port-type", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 215 | &dpn[i].type); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 216 | |
| 217 | fwnode_property_read_u32(node, |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 218 | "mipi-sdw-max-grouping-supported", |
| 219 | &dpn[i].max_grouping); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 220 | |
| 221 | dpn[i].simple_ch_prep_sm = fwnode_property_read_bool(node, |
| 222 | "mipi-sdw-simplified-channelprepare-sm"); |
| 223 | |
| 224 | fwnode_property_read_u32(node, |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 225 | "mipi-sdw-port-channelprepare-timeout", |
| 226 | &dpn[i].ch_prep_timeout); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 227 | |
| 228 | fwnode_property_read_u32(node, |
| 229 | "mipi-sdw-imp-def-dpn-interrupts-supported", |
| 230 | &dpn[i].device_interrupts); |
| 231 | |
| 232 | fwnode_property_read_u32(node, "mipi-sdw-min-channel-number", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 233 | &dpn[i].min_ch); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 234 | |
| 235 | fwnode_property_read_u32(node, "mipi-sdw-max-channel-number", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 236 | &dpn[i].max_ch); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 237 | |
| 238 | nval = fwnode_property_read_u32_array(node, |
| 239 | "mipi-sdw-channel-number-list", NULL, 0); |
| 240 | if (nval > 0) { |
| 241 | |
| 242 | dpn[i].num_ch = nval; |
| 243 | dpn[i].ch = devm_kcalloc(&slave->dev, dpn[i].num_ch, |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 244 | sizeof(*dpn[i].ch), |
| 245 | GFP_KERNEL); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 246 | if (!dpn[i].ch) |
| 247 | return -ENOMEM; |
| 248 | |
| 249 | fwnode_property_read_u32_array(node, |
| 250 | "mipi-sdw-channel-number-list", |
| 251 | dpn[i].ch, dpn[i].num_ch); |
| 252 | } |
| 253 | |
| 254 | nval = fwnode_property_read_u32_array(node, |
| 255 | "mipi-sdw-channel-combination-list", NULL, 0); |
| 256 | if (nval > 0) { |
| 257 | |
| 258 | dpn[i].num_ch_combinations = nval; |
| 259 | dpn[i].ch_combinations = devm_kcalloc(&slave->dev, |
| 260 | dpn[i].num_ch_combinations, |
| 261 | sizeof(*dpn[i].ch_combinations), |
| 262 | GFP_KERNEL); |
| 263 | if (!dpn[i].ch_combinations) |
| 264 | return -ENOMEM; |
| 265 | |
| 266 | fwnode_property_read_u32_array(node, |
| 267 | "mipi-sdw-channel-combination-list", |
| 268 | dpn[i].ch_combinations, |
| 269 | dpn[i].num_ch_combinations); |
| 270 | } |
| 271 | |
| 272 | fwnode_property_read_u32(node, |
| 273 | "mipi-sdw-modes-supported", &dpn[i].modes); |
| 274 | |
| 275 | fwnode_property_read_u32(node, "mipi-sdw-max-async-buffer", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 276 | &dpn[i].max_async_buffer); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 277 | |
| 278 | dpn[i].block_pack_mode = fwnode_property_read_bool(node, |
| 279 | "mipi-sdw-block-packing-mode"); |
| 280 | |
| 281 | fwnode_property_read_u32(node, "mipi-sdw-port-encoding-type", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 282 | &dpn[i].port_encoding); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 283 | |
| 284 | /* TODO: Read audio mode */ |
| 285 | |
| 286 | i++; |
| 287 | } |
| 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * sdw_slave_read_prop() - Read Slave properties |
| 294 | * @slave: SDW Slave |
| 295 | */ |
| 296 | int sdw_slave_read_prop(struct sdw_slave *slave) |
| 297 | { |
| 298 | struct sdw_slave_prop *prop = &slave->prop; |
| 299 | struct device *dev = &slave->dev; |
| 300 | struct fwnode_handle *port; |
| 301 | int num_of_ports, nval, i, dp0 = 0; |
| 302 | |
| 303 | device_property_read_u32(dev, "mipi-sdw-sw-interface-revision", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 304 | &prop->mipi_revision); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 305 | |
| 306 | prop->wake_capable = device_property_read_bool(dev, |
| 307 | "mipi-sdw-wake-up-unavailable"); |
| 308 | prop->wake_capable = !prop->wake_capable; |
| 309 | |
| 310 | prop->test_mode_capable = device_property_read_bool(dev, |
| 311 | "mipi-sdw-test-mode-supported"); |
| 312 | |
| 313 | prop->clk_stop_mode1 = false; |
| 314 | if (device_property_read_bool(dev, |
| 315 | "mipi-sdw-clock-stop-mode1-supported")) |
| 316 | prop->clk_stop_mode1 = true; |
| 317 | |
| 318 | prop->simple_clk_stop_capable = device_property_read_bool(dev, |
| 319 | "mipi-sdw-simplified-clockstopprepare-sm-supported"); |
| 320 | |
| 321 | device_property_read_u32(dev, "mipi-sdw-clockstopprepare-timeout", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 322 | &prop->clk_stop_timeout); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 323 | |
| 324 | device_property_read_u32(dev, "mipi-sdw-slave-channelprepare-timeout", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 325 | &prop->ch_prep_timeout); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 326 | |
| 327 | device_property_read_u32(dev, |
| 328 | "mipi-sdw-clockstopprepare-hard-reset-behavior", |
| 329 | &prop->reset_behave); |
| 330 | |
| 331 | prop->high_PHY_capable = device_property_read_bool(dev, |
| 332 | "mipi-sdw-highPHY-capable"); |
| 333 | |
| 334 | prop->paging_support = device_property_read_bool(dev, |
| 335 | "mipi-sdw-paging-support"); |
| 336 | |
| 337 | prop->bank_delay_support = device_property_read_bool(dev, |
| 338 | "mipi-sdw-bank-delay-support"); |
| 339 | |
| 340 | device_property_read_u32(dev, |
| 341 | "mipi-sdw-port15-read-behavior", &prop->p15_behave); |
| 342 | |
| 343 | device_property_read_u32(dev, "mipi-sdw-master-count", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 344 | &prop->master_count); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 345 | |
| 346 | device_property_read_u32(dev, "mipi-sdw-source-port-list", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 347 | &prop->source_ports); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 348 | |
| 349 | device_property_read_u32(dev, "mipi-sdw-sink-port-list", |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 350 | &prop->sink_ports); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 351 | |
| 352 | /* Read dp0 properties */ |
| 353 | port = device_get_named_child_node(dev, "mipi-sdw-dp-0-subproperties"); |
| 354 | if (!port) { |
| 355 | dev_dbg(dev, "DP0 node not found!!\n"); |
| 356 | } else { |
| 357 | |
| 358 | prop->dp0_prop = devm_kzalloc(&slave->dev, |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 359 | sizeof(*prop->dp0_prop), |
| 360 | GFP_KERNEL); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 361 | if (!prop->dp0_prop) |
| 362 | return -ENOMEM; |
| 363 | |
| 364 | sdw_slave_read_dp0(slave, port, prop->dp0_prop); |
| 365 | dp0 = 1; |
| 366 | } |
| 367 | |
| 368 | /* |
| 369 | * Based on each DPn port, get source and sink dpn properties. |
| 370 | * Also, some ports can operate as both source or sink. |
| 371 | */ |
| 372 | |
| 373 | /* Allocate memory for set bits in port lists */ |
| 374 | nval = hweight32(prop->source_ports); |
| 375 | prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 376 | sizeof(*prop->src_dpn_prop), |
| 377 | GFP_KERNEL); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 378 | if (!prop->src_dpn_prop) |
| 379 | return -ENOMEM; |
| 380 | |
| 381 | /* Read dpn properties for source port(s) */ |
| 382 | sdw_slave_read_dpn(slave, prop->src_dpn_prop, nval, |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 383 | prop->source_ports, "source"); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 384 | |
| 385 | nval = hweight32(prop->sink_ports); |
| 386 | prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 387 | sizeof(*prop->sink_dpn_prop), |
| 388 | GFP_KERNEL); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 389 | if (!prop->sink_dpn_prop) |
| 390 | return -ENOMEM; |
| 391 | |
| 392 | /* Read dpn properties for sink port(s) */ |
| 393 | sdw_slave_read_dpn(slave, prop->sink_dpn_prop, nval, |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 394 | prop->sink_ports, "sink"); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 395 | |
| 396 | /* some ports are bidirectional so check total ports by ORing */ |
| 397 | nval = prop->source_ports | prop->sink_ports; |
| 398 | num_of_ports = hweight32(nval) + dp0; /* add DP0 */ |
| 399 | |
| 400 | /* Allocate port_ready based on num_of_ports */ |
| 401 | slave->port_ready = devm_kcalloc(&slave->dev, num_of_ports, |
Pierre-Louis Bossart | 31dba31 | 2019-05-01 10:57:33 -0500 | [diff] [blame^] | 402 | sizeof(*slave->port_ready), |
| 403 | GFP_KERNEL); |
Vinod Koul | 56d4fe3 | 2017-12-14 11:19:35 +0530 | [diff] [blame] | 404 | if (!slave->port_ready) |
| 405 | return -ENOMEM; |
| 406 | |
| 407 | /* Initialize completion */ |
| 408 | for (i = 0; i < num_of_ports; i++) |
| 409 | init_completion(&slave->port_ready[i]); |
| 410 | |
| 411 | return 0; |
| 412 | } |
| 413 | EXPORT_SYMBOL(sdw_slave_read_prop); |