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