Merge tag 'soundwire-6.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/soundwire

Pull soundwire updates from Vinod Koul:

- SoundWire multi lane support to use multiple lanes if supported

- Stream handling of DEPREPARED state

- AMD wake register programming for power off mode

* tag 'soundwire-6.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/soundwire:
soundwire: amd: clear wake enable register for power off mode
soundwire: generic_bandwidth_allocation: count the bandwidth of active streams only
SoundWire: pass stream to compute_params()
soundwire: generic_bandwidth_allocation: add lane in sdw_group_params
soundwire: generic_bandwidth_allocation: select data lane
soundwire: generic_bandwidth_allocation: check required freq accurately
soundwire: generic_bandwidth_allocation: correct clk_freq check in sdw_select_row_col
Soundwire: generic_bandwidth_allocation: set frame shape on fly
Soundwire: stream: program BUSCLOCK_SCALE
Soundwire: add sdw_slave_get_scale_index helper
soundwire: generic_bandwidth_allocation: skip DEPREPARED streams
soundwire: stream: set DEPREPARED state earlier
soundwire: add lane_used_bandwidth in struct sdw_bus
soundwire: mipi_disco: read lane mapping properties from ACPI
soundwire: add lane field in sdw_port_runtime
soundwire: bus: Move irq mapping cleanup into devres

+513 -163
+3 -2
drivers/soundwire/amd_manager.c
··· 384 384 return slave_stat; 385 385 } 386 386 387 - static int amd_sdw_compute_params(struct sdw_bus *bus) 387 + static int amd_sdw_compute_params(struct sdw_bus *bus, struct sdw_stream_runtime *stream) 388 388 { 389 389 struct sdw_transport_data t_data = {0}; 390 390 struct sdw_master_runtime *m_rt; ··· 410 410 sdw_fill_xport_params(&p_rt->transport_params, p_rt->num, 411 411 false, SDW_BLK_GRP_CNT_1, sample_int, 412 412 port_bo, port_bo >> 8, hstart, hstop, 413 - SDW_BLK_PKG_PER_PORT, 0x0); 413 + SDW_BLK_PKG_PER_PORT, p_rt->lane); 414 414 415 415 sdw_fill_port_params(&p_rt->port_params, 416 416 p_rt->num, bps, ··· 1190 1190 if (amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) { 1191 1191 return amd_sdw_clock_stop_exit(amd_manager); 1192 1192 } else if (amd_manager->power_mode_mask & AMD_SDW_POWER_OFF_MODE) { 1193 + writel(0x00, amd_manager->acp_mmio + ACP_SW_WAKE_EN(amd_manager->instance)); 1193 1194 val = readl(amd_manager->mmio + ACP_SW_CLK_RESUME_CTRL); 1194 1195 if (val) { 1195 1196 val |= AMD_SDW_CLK_RESUME_REQ;
+44 -21
drivers/soundwire/bus.c
··· 813 813 } 814 814 EXPORT_SYMBOL(sdw_extract_slave_id); 815 815 816 + bool is_clock_scaling_supported_by_slave(struct sdw_slave *slave) 817 + { 818 + /* 819 + * Dynamic scaling is a defined by SDCA. However, some devices expose the class ID but 820 + * can't support dynamic scaling. We might need a quirk to handle such devices. 821 + */ 822 + return slave->id.class_id; 823 + } 824 + EXPORT_SYMBOL(is_clock_scaling_supported_by_slave); 825 + 816 826 static int sdw_program_device_num(struct sdw_bus *bus, bool *programmed) 817 827 { 818 828 u8 buf[SDW_NUM_DEV_ID_REGISTERS] = {0}; ··· 1286 1276 return ret; 1287 1277 } 1288 1278 1289 - static int sdw_slave_set_frequency(struct sdw_slave *slave) 1279 + int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base) 1290 1280 { 1291 1281 u32 mclk_freq = slave->bus->prop.mclk_freq; 1292 1282 u32 curr_freq = slave->bus->params.curr_dr_freq >> 1; 1293 1283 unsigned int scale; 1294 1284 u8 scale_index; 1295 - u8 base; 1296 - int ret; 1297 - 1298 - /* 1299 - * frequency base and scale registers are required for SDCA 1300 - * devices. They may also be used for 1.2+/non-SDCA devices. 1301 - * Driver can set the property, we will need a DisCo property 1302 - * to discover this case from platform firmware. 1303 - */ 1304 - if (!slave->id.class_id && !slave->prop.clock_reg_supported) 1305 - return 0; 1306 1285 1307 1286 if (!mclk_freq) { 1308 1287 dev_err(&slave->dev, ··· 1310 1311 */ 1311 1312 if (!(19200000 % mclk_freq)) { 1312 1313 mclk_freq = 19200000; 1313 - base = SDW_SCP_BASE_CLOCK_19200000_HZ; 1314 + *base = SDW_SCP_BASE_CLOCK_19200000_HZ; 1314 1315 } else if (!(22579200 % mclk_freq)) { 1315 1316 mclk_freq = 22579200; 1316 - base = SDW_SCP_BASE_CLOCK_22579200_HZ; 1317 + *base = SDW_SCP_BASE_CLOCK_22579200_HZ; 1317 1318 } else if (!(24576000 % mclk_freq)) { 1318 1319 mclk_freq = 24576000; 1319 - base = SDW_SCP_BASE_CLOCK_24576000_HZ; 1320 + *base = SDW_SCP_BASE_CLOCK_24576000_HZ; 1320 1321 } else if (!(32000000 % mclk_freq)) { 1321 1322 mclk_freq = 32000000; 1322 - base = SDW_SCP_BASE_CLOCK_32000000_HZ; 1323 + *base = SDW_SCP_BASE_CLOCK_32000000_HZ; 1323 1324 } else if (!(96000000 % mclk_freq)) { 1324 1325 mclk_freq = 24000000; 1325 - base = SDW_SCP_BASE_CLOCK_24000000_HZ; 1326 + *base = SDW_SCP_BASE_CLOCK_24000000_HZ; 1326 1327 } else { 1327 1328 dev_err(&slave->dev, 1328 1329 "Unsupported clock base, mclk %d\n", ··· 1353 1354 } 1354 1355 scale_index++; 1355 1356 1357 + dev_dbg(&slave->dev, 1358 + "Configured bus base %d, scale %d, mclk %d, curr_freq %d\n", 1359 + *base, scale_index, mclk_freq, curr_freq); 1360 + 1361 + return scale_index; 1362 + } 1363 + EXPORT_SYMBOL(sdw_slave_get_scale_index); 1364 + 1365 + static int sdw_slave_set_frequency(struct sdw_slave *slave) 1366 + { 1367 + int scale_index; 1368 + u8 base; 1369 + int ret; 1370 + 1371 + /* 1372 + * frequency base and scale registers are required for SDCA 1373 + * devices. They may also be used for 1.2+/non-SDCA devices. 1374 + * Driver can set the property directly, for now there's no 1375 + * DisCo property to discover support for the scaling registers 1376 + * from platform firmware. 1377 + */ 1378 + if (!slave->id.class_id && !slave->prop.clock_reg_supported) 1379 + return 0; 1380 + 1381 + scale_index = sdw_slave_get_scale_index(slave, &base); 1382 + if (scale_index < 0) 1383 + return scale_index; 1384 + 1356 1385 ret = sdw_write_no_pm(slave, SDW_SCP_BUS_CLOCK_BASE, base); 1357 1386 if (ret < 0) { 1358 1387 dev_err(&slave->dev, ··· 1399 1372 if (ret < 0) 1400 1373 dev_err(&slave->dev, 1401 1374 "SDW_SCP_BUSCLOCK_SCALE_B1 write failed:%d\n", ret); 1402 - 1403 - dev_dbg(&slave->dev, 1404 - "Configured bus base %d, scale %d, mclk %d, curr_freq %d\n", 1405 - base, scale_index, mclk_freq, curr_freq); 1406 1375 1407 1376 return ret; 1408 1377 }
+3
drivers/soundwire/bus.h
··· 90 90 * @transport_params: Transport parameters 91 91 * @port_params: Port parameters 92 92 * @port_node: List node for Master or Slave port_list 93 + * @lane: Which lane is used 93 94 * 94 95 * SoundWire spec has no mention of ports for Master interface but the 95 96 * concept is logically extended. ··· 101 100 struct sdw_transport_params transport_params; 102 101 struct sdw_port_params port_params; 103 102 struct list_head port_node; 103 + unsigned int lane; 104 104 }; 105 105 106 106 /** ··· 151 149 int hstop; 152 150 int block_offset; 153 151 int sub_block_offset; 152 + unsigned int lane; 154 153 }; 155 154 156 155 struct sdw_dpn_prop *sdw_get_slave_dpn_prop(struct sdw_slave *slave,
-3
drivers/soundwire/bus_type.c
··· 167 167 168 168 slave->probed = false; 169 169 170 - if (slave->prop.use_domain_irq) 171 - sdw_irq_dispose_mapping(slave); 172 - 173 170 mutex_unlock(&slave->sdw_dev_lock); 174 171 175 172 if (drv->remove)
+267 -49
drivers/soundwire/generic_bandwidth_allocation.c
··· 18 18 19 19 struct sdw_group_params { 20 20 unsigned int rate; 21 + unsigned int lane; 21 22 int full_bw; 22 23 int payload_bw; 23 24 int hwidth; ··· 28 27 unsigned int count; 29 28 unsigned int max_size; 30 29 unsigned int *rates; 30 + unsigned int *lanes; 31 31 }; 32 32 33 33 void sdw_compute_slave_ports(struct sdw_master_runtime *m_rt, ··· 50 48 slave_total_ch = 0; 51 49 52 50 list_for_each_entry(p_rt, &s_rt->port_list, port_node) { 51 + if (p_rt->lane != t_data->lane) 52 + continue; 53 + 53 54 ch = hweight32(p_rt->ch_mask); 54 55 55 56 sdw_fill_xport_params(&p_rt->transport_params, ··· 61 56 sample_int, port_bo, port_bo >> 8, 62 57 t_data->hstart, 63 58 t_data->hstop, 64 - SDW_BLK_PKG_PER_PORT, 0x0); 59 + SDW_BLK_PKG_PER_PORT, p_rt->lane); 65 60 66 61 sdw_fill_port_params(&p_rt->port_params, 67 62 p_rt->num, bps, ··· 110 105 t_data.hstart = hstart; 111 106 112 107 list_for_each_entry(p_rt, &m_rt->port_list, port_node) { 108 + if (p_rt->lane != params->lane) 109 + continue; 113 110 114 111 sdw_fill_xport_params(&p_rt->transport_params, p_rt->num, 115 112 false, SDW_BLK_GRP_CNT_1, sample_int, 116 113 *port_bo, (*port_bo) >> 8, hstart, hstop, 117 - SDW_BLK_PKG_PER_PORT, 0x0); 114 + SDW_BLK_PKG_PER_PORT, p_rt->lane); 118 115 119 116 sdw_fill_port_params(&p_rt->port_params, 120 117 p_rt->num, bps, ··· 138 131 (*port_bo) += bps * ch; 139 132 } 140 133 134 + t_data.lane = params->lane; 141 135 sdw_compute_slave_ports(m_rt, &t_data); 142 136 } 143 137 ··· 146 138 struct sdw_group_params *params, int count) 147 139 { 148 140 struct sdw_master_runtime *m_rt; 149 - int hstop = bus->params.col - 1; 150 - int port_bo, i; 141 + int port_bo, i, l; 142 + int hstop; 151 143 152 144 /* Run loop for all groups to compute transport parameters */ 153 - for (i = 0; i < count; i++) { 154 - port_bo = 1; 145 + for (l = 0; l < SDW_MAX_LANES; l++) { 146 + if (l > 0 && !bus->lane_used_bandwidth[l]) 147 + continue; 148 + /* reset hstop for each lane */ 149 + hstop = bus->params.col - 1; 150 + for (i = 0; i < count; i++) { 151 + if (params[i].lane != l) 152 + continue; 153 + port_bo = 1; 155 154 156 - list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) { 157 - sdw_compute_master_ports(m_rt, &params[i], &port_bo, hstop); 155 + list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) { 156 + sdw_compute_master_ports(m_rt, &params[i], &port_bo, hstop); 157 + } 158 + 159 + hstop = hstop - params[i].hwidth; 158 160 } 159 - 160 - hstop = hstop - params[i].hwidth; 161 161 } 162 162 } 163 163 164 164 static int sdw_compute_group_params(struct sdw_bus *bus, 165 + struct sdw_stream_runtime *stream, 165 166 struct sdw_group_params *params, 166 - int *rates, int count) 167 + struct sdw_group *group) 167 168 { 168 169 struct sdw_master_runtime *m_rt; 170 + struct sdw_port_runtime *p_rt; 169 171 int sel_col = bus->params.col; 170 172 unsigned int rate, bps, ch; 171 - int i, column_needed = 0; 173 + int i, l, column_needed; 172 174 173 175 /* Calculate bandwidth per group */ 174 - for (i = 0; i < count; i++) { 175 - params[i].rate = rates[i]; 176 + for (i = 0; i < group->count; i++) { 177 + params[i].rate = group->rates[i]; 178 + params[i].lane = group->lanes[i]; 176 179 params[i].full_bw = bus->params.curr_dr_freq / params[i].rate; 177 180 } 178 181 179 182 list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) { 180 - rate = m_rt->stream->params.rate; 181 - bps = m_rt->stream->params.bps; 182 - ch = m_rt->ch_count; 183 + if (m_rt->stream == stream) { 184 + /* Only runtime during prepare should be added */ 185 + if (stream->state != SDW_STREAM_CONFIGURED) 186 + continue; 187 + } else { 188 + /* 189 + * Include runtimes with running (ENABLED state) and paused (DISABLED state) 190 + * streams 191 + */ 192 + if (m_rt->stream->state != SDW_STREAM_ENABLED && 193 + m_rt->stream->state != SDW_STREAM_DISABLED) 194 + continue; 195 + } 196 + list_for_each_entry(p_rt, &m_rt->port_list, port_node) { 197 + rate = m_rt->stream->params.rate; 198 + bps = m_rt->stream->params.bps; 199 + ch = hweight32(p_rt->ch_mask); 183 200 184 - for (i = 0; i < count; i++) { 185 - if (rate == params[i].rate) 186 - params[i].payload_bw += bps * ch; 201 + for (i = 0; i < group->count; i++) { 202 + if (rate == params[i].rate && p_rt->lane == params[i].lane) 203 + params[i].payload_bw += bps * ch; 204 + } 187 205 } 188 206 } 189 207 190 - for (i = 0; i < count; i++) { 191 - params[i].hwidth = (sel_col * 192 - params[i].payload_bw + params[i].full_bw - 1) / 193 - params[i].full_bw; 208 + for (l = 0; l < SDW_MAX_LANES; l++) { 209 + if (l > 0 && !bus->lane_used_bandwidth[l]) 210 + continue; 211 + /* reset column_needed for each lane */ 212 + column_needed = 0; 213 + for (i = 0; i < group->count; i++) { 214 + if (params[i].lane != l) 215 + continue; 194 216 195 - column_needed += params[i].hwidth; 217 + params[i].hwidth = (sel_col * params[i].payload_bw + 218 + params[i].full_bw - 1) / params[i].full_bw; 219 + 220 + column_needed += params[i].hwidth; 221 + /* There is no control column for lane 1 and above */ 222 + if (column_needed > sel_col) 223 + return -EINVAL; 224 + /* Column 0 is control column on lane 0 */ 225 + if (params[i].lane == 0 && column_needed > sel_col - 1) 226 + return -EINVAL; 227 + } 196 228 } 197 229 198 - if (column_needed > sel_col - 1) 199 - return -EINVAL; 200 230 201 231 return 0; 202 232 } 203 233 204 234 static int sdw_add_element_group_count(struct sdw_group *group, 205 - unsigned int rate) 235 + unsigned int rate, unsigned int lane) 206 236 { 207 237 int num = group->count; 208 238 int i; 209 239 210 240 for (i = 0; i <= num; i++) { 211 - if (rate == group->rates[i]) 241 + if (rate == group->rates[i] && lane == group->lanes[i]) 212 242 break; 213 243 214 244 if (i != num) ··· 254 208 255 209 if (group->count >= group->max_size) { 256 210 unsigned int *rates; 211 + unsigned int *lanes; 257 212 258 213 group->max_size += 1; 259 214 rates = krealloc(group->rates, ··· 262 215 GFP_KERNEL); 263 216 if (!rates) 264 217 return -ENOMEM; 218 + 265 219 group->rates = rates; 220 + 221 + lanes = krealloc(group->lanes, 222 + (sizeof(int) * group->max_size), 223 + GFP_KERNEL); 224 + if (!lanes) 225 + return -ENOMEM; 226 + 227 + group->lanes = lanes; 266 228 } 267 229 268 - group->rates[group->count++] = rate; 230 + group->rates[group->count] = rate; 231 + group->lanes[group->count++] = lane; 269 232 } 270 233 271 234 return 0; ··· 285 228 struct sdw_group *group) 286 229 { 287 230 struct sdw_master_runtime *m_rt; 231 + struct sdw_port_runtime *p_rt; 288 232 unsigned int rate; 289 233 int ret = 0; 290 234 ··· 295 237 if (!group->rates) 296 238 return -ENOMEM; 297 239 240 + group->lanes = kcalloc(group->max_size, sizeof(int), GFP_KERNEL); 241 + if (!group->lanes) { 242 + kfree(group->rates); 243 + group->rates = NULL; 244 + return -ENOMEM; 245 + } 246 + 298 247 list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) { 248 + if (m_rt->stream->state == SDW_STREAM_DEPREPARED) 249 + continue; 250 + 299 251 rate = m_rt->stream->params.rate; 300 252 if (m_rt == list_first_entry(&bus->m_rt_list, 301 253 struct sdw_master_runtime, 302 254 bus_node)) { 303 255 group->rates[group->count++] = rate; 304 - 305 - } else { 306 - ret = sdw_add_element_group_count(group, rate); 256 + } 257 + /* 258 + * Different ports could use different lane, add group element 259 + * even if m_rt is the first entry 260 + */ 261 + list_for_each_entry(p_rt, &m_rt->port_list, port_node) { 262 + ret = sdw_add_element_group_count(group, rate, p_rt->lane); 307 263 if (ret < 0) { 308 264 kfree(group->rates); 265 + kfree(group->lanes); 309 266 return ret; 310 267 } 311 268 } ··· 333 260 * sdw_compute_port_params: Compute transport and port parameters 334 261 * 335 262 * @bus: SDW Bus instance 263 + * @stream: Soundwire stream 336 264 */ 337 - static int sdw_compute_port_params(struct sdw_bus *bus) 265 + static int sdw_compute_port_params(struct sdw_bus *bus, struct sdw_stream_runtime *stream) 338 266 { 339 267 struct sdw_group_params *params = NULL; 340 268 struct sdw_group group; ··· 355 281 } 356 282 357 283 /* Compute transport parameters for grouped streams */ 358 - ret = sdw_compute_group_params(bus, params, 359 - &group.rates[0], group.count); 284 + ret = sdw_compute_group_params(bus, stream, params, &group); 360 285 if (ret < 0) 361 286 goto free_params; 362 287 ··· 365 292 kfree(params); 366 293 out: 367 294 kfree(group.rates); 295 + kfree(group.lanes); 368 296 369 297 return ret; 370 298 } ··· 373 299 static int sdw_select_row_col(struct sdw_bus *bus, int clk_freq) 374 300 { 375 301 struct sdw_master_prop *prop = &bus->prop; 376 - int frame_int, frame_freq; 377 302 int r, c; 378 303 379 304 for (c = 0; c < SDW_FRAME_COLS; c++) { ··· 381 308 sdw_cols[c] != prop->default_col) 382 309 continue; 383 310 384 - frame_int = sdw_rows[r] * sdw_cols[c]; 385 - frame_freq = clk_freq / frame_int; 386 - 387 - if ((clk_freq - (frame_freq * SDW_FRAME_CTRL_BITS)) < 388 - bus->params.bandwidth) 311 + if (clk_freq * (sdw_cols[c] - 1) < 312 + bus->params.bandwidth * sdw_cols[c]) 389 313 continue; 390 314 391 315 bus->params.row = sdw_rows[r]; ··· 394 324 return -EINVAL; 395 325 } 396 326 327 + static bool is_clock_scaling_supported(struct sdw_bus *bus) 328 + { 329 + struct sdw_master_runtime *m_rt; 330 + struct sdw_slave_runtime *s_rt; 331 + 332 + list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) 333 + list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) 334 + if (!is_clock_scaling_supported_by_slave(s_rt->slave)) 335 + return false; 336 + 337 + return true; 338 + } 339 + 340 + /** 341 + * is_lane_connected_to_all_peripherals: Check if the given manager lane connects to all peripherals 342 + * So that all peripherals can use the manager lane. 343 + * 344 + * @m_rt: Manager runtime 345 + * @lane: Lane number 346 + */ 347 + static bool is_lane_connected_to_all_peripherals(struct sdw_master_runtime *m_rt, unsigned int lane) 348 + { 349 + struct sdw_slave_prop *slave_prop; 350 + struct sdw_slave_runtime *s_rt; 351 + int i; 352 + 353 + list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) { 354 + slave_prop = &s_rt->slave->prop; 355 + for (i = 1; i < SDW_MAX_LANES; i++) { 356 + if (slave_prop->lane_maps[i] == lane) { 357 + dev_dbg(&s_rt->slave->dev, 358 + "M lane %d is connected to P lane %d\n", 359 + lane, i); 360 + break; 361 + } 362 + } 363 + if (i == SDW_MAX_LANES) { 364 + dev_dbg(&s_rt->slave->dev, "M lane %d is not connected\n", lane); 365 + return false; 366 + } 367 + } 368 + return true; 369 + } 370 + 371 + static int get_manager_lane(struct sdw_bus *bus, struct sdw_master_runtime *m_rt, 372 + struct sdw_slave_runtime *s_rt, unsigned int curr_dr_freq) 373 + { 374 + struct sdw_slave_prop *slave_prop = &s_rt->slave->prop; 375 + struct sdw_port_runtime *m_p_rt; 376 + unsigned int required_bandwidth; 377 + int m_lane; 378 + int l; 379 + 380 + for (l = 1; l < SDW_MAX_LANES; l++) { 381 + if (!slave_prop->lane_maps[l]) 382 + continue; 383 + 384 + required_bandwidth = 0; 385 + list_for_each_entry(m_p_rt, &m_rt->port_list, port_node) { 386 + required_bandwidth += m_rt->stream->params.rate * 387 + hweight32(m_p_rt->ch_mask) * 388 + m_rt->stream->params.bps; 389 + } 390 + if (required_bandwidth <= 391 + curr_dr_freq - bus->lane_used_bandwidth[l]) { 392 + /* Check if m_lane is connected to all Peripherals */ 393 + if (!is_lane_connected_to_all_peripherals(m_rt, 394 + slave_prop->lane_maps[l])) { 395 + dev_dbg(bus->dev, 396 + "Not all Peripherals are connected to M lane %d\n", 397 + slave_prop->lane_maps[l]); 398 + continue; 399 + } 400 + m_lane = slave_prop->lane_maps[l]; 401 + dev_dbg(&s_rt->slave->dev, "M lane %d is used\n", m_lane); 402 + bus->lane_used_bandwidth[l] += required_bandwidth; 403 + /* 404 + * Use non-zero manager lane, subtract the lane 0 405 + * bandwidth that is already calculated 406 + */ 407 + bus->params.bandwidth -= required_bandwidth; 408 + return m_lane; 409 + } 410 + } 411 + 412 + /* No available multi lane found, only lane 0 can be used */ 413 + return 0; 414 + } 415 + 397 416 /** 398 417 * sdw_compute_bus_params: Compute bus parameters 399 418 * ··· 490 331 */ 491 332 static int sdw_compute_bus_params(struct sdw_bus *bus) 492 333 { 493 - unsigned int curr_dr_freq = 0; 494 334 struct sdw_master_prop *mstr_prop = &bus->prop; 495 - int i, clk_values, ret; 335 + struct sdw_slave_prop *slave_prop; 336 + struct sdw_port_runtime *m_p_rt; 337 + struct sdw_port_runtime *s_p_rt; 338 + struct sdw_master_runtime *m_rt; 339 + struct sdw_slave_runtime *s_rt; 340 + unsigned int curr_dr_freq = 0; 341 + int i, l, clk_values, ret; 496 342 bool is_gear = false; 343 + int m_lane = 0; 497 344 u32 *clk_buf; 498 345 499 346 if (mstr_prop->num_clk_gears) { ··· 514 349 clk_buf = NULL; 515 350 } 516 351 352 + /* If dynamic scaling is not supported, don't try higher freq */ 353 + if (!is_clock_scaling_supported(bus)) 354 + clk_values = 1; 355 + 517 356 for (i = 0; i < clk_values; i++) { 518 357 if (!clk_buf) 519 358 curr_dr_freq = bus->params.max_dr_freq; ··· 526 357 (bus->params.max_dr_freq >> clk_buf[i]) : 527 358 clk_buf[i] * SDW_DOUBLE_RATE_FACTOR; 528 359 529 - if (curr_dr_freq <= bus->params.bandwidth) 530 - continue; 360 + if (curr_dr_freq * (mstr_prop->default_col - 1) >= 361 + bus->params.bandwidth * mstr_prop->default_col) 362 + break; 531 363 532 - break; 364 + list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) { 365 + /* 366 + * Get the first s_rt that will be used to find the available lane that 367 + * can be used. No need to check all Peripherals because we can't use 368 + * multi-lane if we can't find any available lane for the first Peripheral. 369 + */ 370 + s_rt = list_first_entry(&m_rt->slave_rt_list, 371 + struct sdw_slave_runtime, m_rt_node); 372 + 373 + /* 374 + * Find the available Manager lane that connected to the first Peripheral. 375 + */ 376 + m_lane = get_manager_lane(bus, m_rt, s_rt, curr_dr_freq); 377 + if (m_lane > 0) 378 + goto out; 379 + } 533 380 534 381 /* 535 382 * TODO: Check all the Slave(s) port(s) audio modes and find ··· 559 374 __func__, bus->params.bandwidth); 560 375 return -EINVAL; 561 376 } 377 + out: 378 + /* multilane can be used */ 379 + if (m_lane > 0) { 380 + /* Set Peripheral lanes */ 381 + list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) { 382 + slave_prop = &s_rt->slave->prop; 383 + for (l = 1; l < SDW_MAX_LANES; l++) { 384 + if (slave_prop->lane_maps[l] == m_lane) { 385 + list_for_each_entry(s_p_rt, &s_rt->port_list, port_node) { 386 + s_p_rt->lane = l; 387 + dev_dbg(&s_rt->slave->dev, 388 + "Set P lane %d for port %d\n", 389 + l, s_p_rt->num); 390 + } 391 + break; 392 + } 393 + } 394 + } 395 + /* 396 + * Set Manager lanes. Configure the last m_rt in bus->m_rt_list only since 397 + * we don't want to touch other m_rts that are already working. 398 + */ 399 + list_for_each_entry(m_p_rt, &m_rt->port_list, port_node) { 400 + m_p_rt->lane = m_lane; 401 + } 402 + } 403 + 404 + if (!mstr_prop->default_frame_rate || !mstr_prop->default_row) 405 + return -EINVAL; 406 + 407 + mstr_prop->default_col = curr_dr_freq / mstr_prop->default_frame_rate / 408 + mstr_prop->default_row; 562 409 563 410 ret = sdw_select_row_col(bus, curr_dr_freq); 564 411 if (ret < 0) { ··· 607 390 * sdw_compute_params: Compute bus, transport and port parameters 608 391 * 609 392 * @bus: SDW Bus instance 393 + * @stream: Soundwire stream 610 394 */ 611 - int sdw_compute_params(struct sdw_bus *bus) 395 + int sdw_compute_params(struct sdw_bus *bus, struct sdw_stream_runtime *stream) 612 396 { 613 397 int ret; 614 398 ··· 619 401 return ret; 620 402 621 403 /* Compute transport and port params */ 622 - ret = sdw_compute_port_params(bus); 404 + ret = sdw_compute_port_params(bus, stream); 623 405 if (ret < 0) { 624 406 dev_err(bus->dev, "Compute transport params failed: %d\n", ret); 625 407 return ret;
+8 -4
drivers/soundwire/irq.c
··· 46 46 irq_domain_remove(bus->domain); 47 47 } 48 48 49 + static void sdw_irq_dispose_mapping(void *data) 50 + { 51 + struct sdw_slave *slave = data; 52 + 53 + irq_dispose_mapping(irq_find_mapping(slave->bus->domain, slave->dev_num)); 54 + } 55 + 49 56 void sdw_irq_create_mapping(struct sdw_slave *slave) 50 57 { 51 58 slave->irq = irq_create_mapping(slave->bus->domain, slave->dev_num); 52 59 if (!slave->irq) 53 60 dev_warn(&slave->dev, "Failed to map IRQ\n"); 54 - } 55 61 56 - void sdw_irq_dispose_mapping(struct sdw_slave *slave) 57 - { 58 - irq_dispose_mapping(irq_find_mapping(slave->bus->domain, slave->dev_num)); 62 + devm_add_action_or_reset(&slave->dev, sdw_irq_dispose_mapping, slave); 59 63 }
-5
drivers/soundwire/irq.h
··· 16 16 struct fwnode_handle *fwnode); 17 17 void sdw_irq_delete(struct sdw_bus *bus); 18 18 void sdw_irq_create_mapping(struct sdw_slave *slave); 19 - void sdw_irq_dispose_mapping(struct sdw_slave *slave); 20 19 21 20 #else /* CONFIG_IRQ_DOMAIN */ 22 21 ··· 30 31 } 31 32 32 33 static inline void sdw_irq_create_mapping(struct sdw_slave *slave) 33 - { 34 - } 35 - 36 - static inline void sdw_irq_dispose_mapping(struct sdw_slave *slave) 37 34 { 38 35 } 39 36
+39 -1
drivers/soundwire/mipi_disco.c
··· 366 366 return 0; 367 367 } 368 368 369 + /* 370 + * In MIPI DisCo spec for SoundWire, lane mapping for a slave device is done with 371 + * mipi-sdw-lane-x-mapping properties, where x is 1..7, and the values for those 372 + * properties are mipi-sdw-manager-lane-x or mipi-sdw-peripheral-link-y, where x 373 + * is an integer between 1 to 7 if the lane is connected to a manager lane, y is a 374 + * character between A to E if the lane is connected to another peripheral lane. 375 + */ 376 + int sdw_slave_read_lane_mapping(struct sdw_slave *slave) 377 + { 378 + struct sdw_slave_prop *prop = &slave->prop; 379 + struct device *dev = &slave->dev; 380 + char prop_name[30]; 381 + const char *prop_val; 382 + size_t len; 383 + int ret, i; 384 + u8 lane; 385 + 386 + for (i = 0; i < SDW_MAX_LANES; i++) { 387 + snprintf(prop_name, sizeof(prop_name), "mipi-sdw-lane-%d-mapping", i); 388 + ret = device_property_read_string(dev, prop_name, &prop_val); 389 + if (ret) 390 + continue; 391 + 392 + len = strlen(prop_val); 393 + if (len < 1) 394 + return -EINVAL; 395 + 396 + /* The last character is enough to identify the connection */ 397 + ret = kstrtou8(&prop_val[len - 1], 10, &lane); 398 + if (ret) 399 + return ret; 400 + if (in_range(lane, 1, SDW_MAX_LANES - 1)) 401 + prop->lane_maps[i] = lane; 402 + } 403 + return 0; 404 + } 405 + EXPORT_SYMBOL(sdw_slave_read_lane_mapping); 406 + 369 407 /** 370 408 * sdw_slave_read_prop() - Read Slave properties 371 409 * @slave: SDW Slave ··· 524 486 sdw_slave_read_dpn(slave, prop->sink_dpn_prop, nval, 525 487 prop->sink_ports, "sink"); 526 488 527 - return 0; 489 + return sdw_slave_read_lane_mapping(slave); 528 490 } 529 491 EXPORT_SYMBOL(sdw_slave_read_prop);
+1 -1
drivers/soundwire/qcom.c
··· 1072 1072 .pre_bank_switch = qcom_swrm_pre_bank_switch, 1073 1073 }; 1074 1074 1075 - static int qcom_swrm_compute_params(struct sdw_bus *bus) 1075 + static int qcom_swrm_compute_params(struct sdw_bus *bus, struct sdw_stream_runtime *stream) 1076 1076 { 1077 1077 struct qcom_swrm_ctrl *ctrl = to_qcom_sdw(bus); 1078 1078 struct sdw_master_runtime *m_rt;
+66 -5
drivers/soundwire/stream.c
··· 629 629 static int sdw_program_params(struct sdw_bus *bus, bool prepare) 630 630 { 631 631 struct sdw_master_runtime *m_rt; 632 + struct sdw_slave *slave; 632 633 int ret = 0; 634 + u32 addr1; 633 635 636 + /* Check if all Peripherals comply with SDCA */ 637 + list_for_each_entry(slave, &bus->slaves, node) { 638 + if (!slave->dev_num_sticky) 639 + continue; 640 + if (!is_clock_scaling_supported_by_slave(slave)) { 641 + dev_dbg(&slave->dev, "The Peripheral doesn't comply with SDCA\n"); 642 + goto manager_runtime; 643 + } 644 + } 645 + 646 + if (bus->params.next_bank) 647 + addr1 = SDW_SCP_BUSCLOCK_SCALE_B1; 648 + else 649 + addr1 = SDW_SCP_BUSCLOCK_SCALE_B0; 650 + 651 + /* Program SDW_SCP_BUSCLOCK_SCALE if all Peripherals comply with SDCA */ 652 + list_for_each_entry(slave, &bus->slaves, node) { 653 + int scale_index; 654 + u8 base; 655 + 656 + if (!slave->dev_num_sticky) 657 + continue; 658 + scale_index = sdw_slave_get_scale_index(slave, &base); 659 + if (scale_index < 0) 660 + return scale_index; 661 + 662 + ret = sdw_write_no_pm(slave, addr1, scale_index); 663 + if (ret < 0) { 664 + dev_err(&slave->dev, "SDW_SCP_BUSCLOCK_SCALE register write failed\n"); 665 + return ret; 666 + } 667 + } 668 + 669 + manager_runtime: 634 670 list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) { 635 671 636 672 /* ··· 1419 1383 1420 1384 /* Compute params */ 1421 1385 if (bus->compute_params) { 1422 - ret = bus->compute_params(bus); 1386 + ret = bus->compute_params(bus, stream); 1423 1387 if (ret < 0) { 1424 1388 dev_err(bus->dev, "Compute params failed: %d\n", 1425 1389 ret); ··· 1678 1642 static int _sdw_deprepare_stream(struct sdw_stream_runtime *stream) 1679 1643 { 1680 1644 struct sdw_master_runtime *m_rt; 1645 + struct sdw_port_runtime *p_rt; 1646 + unsigned int multi_lane_bandwidth; 1647 + unsigned int bandwidth; 1681 1648 struct sdw_bus *bus; 1649 + int state = stream->state; 1682 1650 int ret = 0; 1651 + 1652 + /* 1653 + * first mark the state as DEPREPARED so that it is not taken into account 1654 + * for bit allocation 1655 + */ 1656 + stream->state = SDW_STREAM_DEPREPARED; 1683 1657 1684 1658 list_for_each_entry(m_rt, &stream->master_list, stream_node) { 1685 1659 bus = m_rt->bus; ··· 1698 1652 if (ret < 0) { 1699 1653 dev_err(bus->dev, 1700 1654 "De-prepare port(s) failed: %d\n", ret); 1655 + stream->state = state; 1701 1656 return ret; 1702 1657 } 1703 1658 1659 + multi_lane_bandwidth = 0; 1660 + 1661 + list_for_each_entry(p_rt, &m_rt->port_list, port_node) { 1662 + if (!p_rt->lane) 1663 + continue; 1664 + 1665 + bandwidth = m_rt->stream->params.rate * hweight32(p_rt->ch_mask) * 1666 + m_rt->stream->params.bps; 1667 + multi_lane_bandwidth += bandwidth; 1668 + bus->lane_used_bandwidth[p_rt->lane] -= bandwidth; 1669 + if (!bus->lane_used_bandwidth[p_rt->lane]) 1670 + p_rt->lane = 0; 1671 + } 1704 1672 /* TODO: Update this during Device-Device support */ 1705 - bus->params.bandwidth -= m_rt->stream->params.rate * 1706 - m_rt->ch_count * m_rt->stream->params.bps; 1673 + bandwidth = m_rt->stream->params.rate * m_rt->ch_count * m_rt->stream->params.bps; 1674 + bus->params.bandwidth -= bandwidth - multi_lane_bandwidth; 1707 1675 1708 1676 /* Compute params */ 1709 1677 if (bus->compute_params) { 1710 - ret = bus->compute_params(bus); 1678 + ret = bus->compute_params(bus, stream); 1711 1679 if (ret < 0) { 1712 1680 dev_err(bus->dev, "Compute params failed: %d\n", 1713 1681 ret); 1682 + stream->state = state; 1714 1683 return ret; 1715 1684 } 1716 1685 } ··· 1734 1673 ret = sdw_program_params(bus, false); 1735 1674 if (ret < 0) { 1736 1675 dev_err(bus->dev, "%s: Program params failed: %d\n", __func__, ret); 1676 + stream->state = state; 1737 1677 return ret; 1738 1678 } 1739 1679 } 1740 1680 1741 - stream->state = SDW_STREAM_DEPREPARED; 1742 1681 return do_bank_switch(stream); 1743 1682 } 1744 1683
+82 -72
include/linux/soundwire/sdw.h
··· 54 54 #define SDW_MAX_PORTS 15 55 55 #define SDW_VALID_PORT_RANGE(n) ((n) < SDW_MAX_PORTS && (n) >= 1) 56 56 57 + #define SDW_MAX_LANES 8 58 + 57 59 enum { 58 60 SDW_PORT_DIRN_SINK = 0, 59 61 SDW_PORT_DIRN_SOURCE, ··· 358 356 * and masks are supported 359 357 * @commit_register_supported: is PCP_Commit register supported 360 358 * @scp_int1_mask: SCP_INT1_MASK desired settings 359 + * @lane_maps: Lane mapping for the slave, only valid if lane_control_support is set 361 360 * @clock_reg_supported: the Peripheral implements the clock base and scale 362 361 * registers introduced with the SoundWire 1.2 specification. SDCA devices 363 362 * do not need to set this boolean property as the registers are required. ··· 388 385 u32 sdca_interrupt_register_list; 389 386 u8 commit_register_supported; 390 387 u8 scp_int1_mask; 388 + u8 lane_maps[SDW_MAX_LANES]; 391 389 bool clock_reg_supported; 392 390 bool use_domain_irq; 393 391 }; ··· 454 450 455 451 int sdw_master_read_prop(struct sdw_bus *bus); 456 452 int sdw_slave_read_prop(struct sdw_slave *slave); 453 + int sdw_slave_read_lane_mapping(struct sdw_slave *slave); 457 454 458 455 /* 459 456 * SDW Slave Structures and APIs ··· 855 850 int dev_num); 856 851 }; 857 852 858 - /** 859 - * struct sdw_bus - SoundWire bus 860 - * @dev: Shortcut to &bus->md->dev to avoid changing the entire code. 861 - * @md: Master device 862 - * @bus_lock_key: bus lock key associated to @bus_lock 863 - * @bus_lock: bus lock 864 - * @slaves: list of Slaves on this bus 865 - * @msg_lock_key: message lock key associated to @msg_lock 866 - * @msg_lock: message lock 867 - * @m_rt_list: List of Master instance of all stream(s) running on Bus. This 868 - * is used to compute and program bus bandwidth, clock, frame shape, 869 - * transport and port parameters 870 - * @defer_msg: Defer message 871 - * @params: Current bus parameters 872 - * @stream_refcount: number of streams currently using this bus 873 - * @ops: Master callback ops 874 - * @port_ops: Master port callback ops 875 - * @prop: Master properties 876 - * @vendor_specific_prop: pointer to non-standard properties 877 - * @hw_sync_min_links: Number of links used by a stream above which 878 - * hardware-based synchronization is required. This value is only 879 - * meaningful if multi_link is set. If set to 1, hardware-based 880 - * synchronization will be used even if a stream only uses a single 881 - * SoundWire segment. 882 - * @controller_id: system-unique controller ID. If set to -1, the bus @id will be used. 883 - * @link_id: Link id number, can be 0 to N, unique for each Controller 884 - * @id: bus system-wide unique id 885 - * @compute_params: points to Bus resource management implementation 886 - * @assigned: Bitmap for Slave device numbers. 887 - * Bit set implies used number, bit clear implies unused number. 888 - * @clk_stop_timeout: Clock stop timeout computed 889 - * @bank_switch_timeout: Bank switch timeout computed 890 - * @domain: IRQ domain 891 - * @irq_chip: IRQ chip 892 - * @debugfs: Bus debugfs (optional) 893 - * @multi_link: Store bus property that indicates if multi links 894 - * are supported. This flag is populated by drivers after reading 895 - * appropriate firmware (ACPI/DT). 896 - */ 897 - struct sdw_bus { 898 - struct device *dev; 899 - struct sdw_master_device *md; 900 - struct lock_class_key bus_lock_key; 901 - struct mutex bus_lock; 902 - struct list_head slaves; 903 - struct lock_class_key msg_lock_key; 904 - struct mutex msg_lock; 905 - struct list_head m_rt_list; 906 - struct sdw_defer defer_msg; 907 - struct sdw_bus_params params; 908 - int stream_refcount; 909 - const struct sdw_master_ops *ops; 910 - const struct sdw_master_port_ops *port_ops; 911 - struct sdw_master_prop prop; 912 - void *vendor_specific_prop; 913 - int hw_sync_min_links; 914 - int controller_id; 915 - unsigned int link_id; 916 - int id; 917 - int (*compute_params)(struct sdw_bus *bus); 918 - DECLARE_BITMAP(assigned, SDW_MAX_DEVICES); 919 - unsigned int clk_stop_timeout; 920 - u32 bank_switch_timeout; 921 - struct irq_chip irq_chip; 922 - struct irq_domain *domain; 923 - #ifdef CONFIG_DEBUG_FS 924 - struct dentry *debugfs; 925 - #endif 926 - bool multi_link; 927 - }; 928 - 929 853 int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent, 930 854 struct fwnode_handle *fwnode); 931 855 void sdw_bus_master_delete(struct sdw_bus *bus); ··· 944 1010 struct list_head master_list; 945 1011 }; 946 1012 1013 + /** 1014 + * struct sdw_bus - SoundWire bus 1015 + * @dev: Shortcut to &bus->md->dev to avoid changing the entire code. 1016 + * @md: Master device 1017 + * @bus_lock_key: bus lock key associated to @bus_lock 1018 + * @bus_lock: bus lock 1019 + * @slaves: list of Slaves on this bus 1020 + * @msg_lock_key: message lock key associated to @msg_lock 1021 + * @msg_lock: message lock 1022 + * @m_rt_list: List of Master instance of all stream(s) running on Bus. This 1023 + * is used to compute and program bus bandwidth, clock, frame shape, 1024 + * transport and port parameters 1025 + * @defer_msg: Defer message 1026 + * @params: Current bus parameters 1027 + * @stream_refcount: number of streams currently using this bus 1028 + * @ops: Master callback ops 1029 + * @port_ops: Master port callback ops 1030 + * @prop: Master properties 1031 + * @vendor_specific_prop: pointer to non-standard properties 1032 + * @hw_sync_min_links: Number of links used by a stream above which 1033 + * hardware-based synchronization is required. This value is only 1034 + * meaningful if multi_link is set. If set to 1, hardware-based 1035 + * synchronization will be used even if a stream only uses a single 1036 + * SoundWire segment. 1037 + * @controller_id: system-unique controller ID. If set to -1, the bus @id will be used. 1038 + * @link_id: Link id number, can be 0 to N, unique for each Controller 1039 + * @id: bus system-wide unique id 1040 + * @compute_params: points to Bus resource management implementation 1041 + * @assigned: Bitmap for Slave device numbers. 1042 + * Bit set implies used number, bit clear implies unused number. 1043 + * @clk_stop_timeout: Clock stop timeout computed 1044 + * @bank_switch_timeout: Bank switch timeout computed 1045 + * @domain: IRQ domain 1046 + * @irq_chip: IRQ chip 1047 + * @debugfs: Bus debugfs (optional) 1048 + * @multi_link: Store bus property that indicates if multi links 1049 + * are supported. This flag is populated by drivers after reading 1050 + * appropriate firmware (ACPI/DT). 1051 + * @lane_used_bandwidth: how much bandwidth in bits per second is used by each lane 1052 + */ 1053 + struct sdw_bus { 1054 + struct device *dev; 1055 + struct sdw_master_device *md; 1056 + struct lock_class_key bus_lock_key; 1057 + struct mutex bus_lock; 1058 + struct list_head slaves; 1059 + struct lock_class_key msg_lock_key; 1060 + struct mutex msg_lock; 1061 + struct list_head m_rt_list; 1062 + struct sdw_defer defer_msg; 1063 + struct sdw_bus_params params; 1064 + int stream_refcount; 1065 + const struct sdw_master_ops *ops; 1066 + const struct sdw_master_port_ops *port_ops; 1067 + struct sdw_master_prop prop; 1068 + void *vendor_specific_prop; 1069 + int hw_sync_min_links; 1070 + int controller_id; 1071 + unsigned int link_id; 1072 + int id; 1073 + int (*compute_params)(struct sdw_bus *bus, struct sdw_stream_runtime *stream); 1074 + DECLARE_BITMAP(assigned, SDW_MAX_DEVICES); 1075 + unsigned int clk_stop_timeout; 1076 + u32 bank_switch_timeout; 1077 + struct irq_chip irq_chip; 1078 + struct irq_domain *domain; 1079 + #ifdef CONFIG_DEBUG_FS 1080 + struct dentry *debugfs; 1081 + #endif 1082 + bool multi_link; 1083 + unsigned int lane_used_bandwidth[SDW_MAX_LANES]; 1084 + }; 1085 + 947 1086 struct sdw_stream_runtime *sdw_alloc_stream(const char *stream_name); 948 1087 void sdw_release_stream(struct sdw_stream_runtime *stream); 949 1088 950 - int sdw_compute_params(struct sdw_bus *bus); 1089 + int sdw_compute_params(struct sdw_bus *bus, struct sdw_stream_runtime *stream); 951 1090 952 1091 int sdw_stream_add_master(struct sdw_bus *bus, 953 1092 struct sdw_stream_config *stream_config, ··· 1041 1034 1042 1035 int sdw_compare_devid(struct sdw_slave *slave, struct sdw_slave_id id); 1043 1036 void sdw_extract_slave_id(struct sdw_bus *bus, u64 addr, struct sdw_slave_id *id); 1037 + bool is_clock_scaling_supported_by_slave(struct sdw_slave *slave); 1044 1038 1045 1039 #if IS_ENABLED(CONFIG_SOUNDWIRE) 1046 1040 ··· 1052 1044 struct sdw_stream_runtime *stream); 1053 1045 int sdw_stream_remove_slave(struct sdw_slave *slave, 1054 1046 struct sdw_stream_runtime *stream); 1047 + 1048 + int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base); 1055 1049 1056 1050 /* messaging and data APIs */ 1057 1051 int sdw_read(struct sdw_slave *slave, u32 addr);