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