generic_bandwidth_allocation.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
  2. // Copyright(c) 2015-2020 Intel Corporation.
  3. /*
  4. * Bandwidth management algorithm based on 2^n gears
  5. *
  6. */
  7. #include <linux/bitops.h>
  8. #include <linux/device.h>
  9. #include <linux/module.h>
  10. #include <linux/mod_devicetable.h>
  11. #include <linux/slab.h>
  12. #include <linux/soundwire/sdw.h>
  13. #include "bus.h"
  14. #define SDW_STRM_RATE_GROUPING 1
  15. struct sdw_group_params {
  16. unsigned int rate;
  17. unsigned int lane;
  18. int full_bw;
  19. int payload_bw;
  20. int hwidth;
  21. };
  22. struct sdw_group {
  23. unsigned int count;
  24. unsigned int max_size;
  25. unsigned int *rates;
  26. unsigned int *lanes;
  27. };
  28. void sdw_compute_slave_ports(struct sdw_master_runtime *m_rt,
  29. struct sdw_transport_data *t_data)
  30. {
  31. struct sdw_slave_runtime *s_rt = NULL;
  32. struct sdw_port_runtime *p_rt;
  33. int port_bo, sample_int;
  34. unsigned int rate, bps, ch = 0;
  35. unsigned int slave_total_ch;
  36. struct sdw_bus_params *b_params = &m_rt->bus->params;
  37. port_bo = t_data->block_offset;
  38. list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) {
  39. rate = m_rt->stream->params.rate;
  40. bps = m_rt->stream->params.bps;
  41. sample_int = (m_rt->bus->params.curr_dr_freq / rate);
  42. slave_total_ch = 0;
  43. list_for_each_entry(p_rt, &s_rt->port_list, port_node) {
  44. if (p_rt->lane != t_data->lane)
  45. continue;
  46. ch = hweight32(p_rt->ch_mask);
  47. sdw_fill_xport_params(&p_rt->transport_params,
  48. p_rt->num, false,
  49. SDW_BLK_GRP_CNT_1,
  50. sample_int, port_bo, port_bo >> 8,
  51. t_data->hstart,
  52. t_data->hstop,
  53. SDW_BLK_PKG_PER_PORT, p_rt->lane);
  54. sdw_fill_port_params(&p_rt->port_params,
  55. p_rt->num, bps,
  56. SDW_PORT_FLOW_MODE_ISOCH,
  57. b_params->s_data_mode);
  58. port_bo += bps * ch;
  59. slave_total_ch += ch;
  60. }
  61. if (m_rt->direction == SDW_DATA_DIR_TX &&
  62. m_rt->ch_count == slave_total_ch) {
  63. /*
  64. * Slave devices were configured to access all channels
  65. * of the stream, which indicates that they operate in
  66. * 'mirror mode'. Make sure we reset the port offset for
  67. * the next device in the list
  68. */
  69. port_bo = t_data->block_offset;
  70. }
  71. }
  72. }
  73. EXPORT_SYMBOL(sdw_compute_slave_ports);
  74. static void sdw_compute_dp0_slave_ports(struct sdw_master_runtime *m_rt)
  75. {
  76. struct sdw_bus *bus = m_rt->bus;
  77. struct sdw_slave_runtime *s_rt;
  78. struct sdw_port_runtime *p_rt;
  79. list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) {
  80. list_for_each_entry(p_rt, &s_rt->port_list, port_node) {
  81. sdw_fill_xport_params(&p_rt->transport_params, p_rt->num, false,
  82. SDW_BLK_GRP_CNT_1, bus->params.col, 0, 0, 1,
  83. bus->params.col - 1, SDW_BLK_PKG_PER_PORT, 0x0);
  84. sdw_fill_port_params(&p_rt->port_params, p_rt->num, bus->params.col - 1,
  85. SDW_PORT_FLOW_MODE_ISOCH, SDW_PORT_DATA_MODE_NORMAL);
  86. }
  87. }
  88. }
  89. static void sdw_compute_dp0_master_ports(struct sdw_master_runtime *m_rt)
  90. {
  91. struct sdw_port_runtime *p_rt;
  92. struct sdw_bus *bus = m_rt->bus;
  93. list_for_each_entry(p_rt, &m_rt->port_list, port_node) {
  94. sdw_fill_xport_params(&p_rt->transport_params, p_rt->num, false,
  95. SDW_BLK_GRP_CNT_1, bus->params.col, 0, 0, 1,
  96. bus->params.col - 1, SDW_BLK_PKG_PER_PORT, 0x0);
  97. sdw_fill_port_params(&p_rt->port_params, p_rt->num, bus->params.col - 1,
  98. SDW_PORT_FLOW_MODE_ISOCH, SDW_PORT_DATA_MODE_NORMAL);
  99. }
  100. }
  101. static void sdw_compute_dp0_port_params(struct sdw_bus *bus)
  102. {
  103. struct sdw_master_runtime *m_rt;
  104. list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) {
  105. /* DP0 is for BPT only */
  106. if (m_rt->stream->type != SDW_STREAM_BPT)
  107. continue;
  108. sdw_compute_dp0_master_ports(m_rt);
  109. sdw_compute_dp0_slave_ports(m_rt);
  110. }
  111. }
  112. static void sdw_compute_master_ports(struct sdw_master_runtime *m_rt,
  113. struct sdw_group_params *params,
  114. int *port_bo, int hstop)
  115. {
  116. struct sdw_transport_data t_data = {0};
  117. struct sdw_port_runtime *p_rt;
  118. struct sdw_bus *bus = m_rt->bus;
  119. struct sdw_bus_params *b_params = &bus->params;
  120. int sample_int, hstart = 0;
  121. unsigned int rate, bps, ch;
  122. rate = m_rt->stream->params.rate;
  123. bps = m_rt->stream->params.bps;
  124. ch = m_rt->ch_count;
  125. sample_int = (bus->params.curr_dr_freq / rate);
  126. if (rate != params->rate)
  127. return;
  128. t_data.hstop = hstop;
  129. hstart = hstop - params->hwidth + 1;
  130. t_data.hstart = hstart;
  131. list_for_each_entry(p_rt, &m_rt->port_list, port_node) {
  132. if (p_rt->lane != params->lane)
  133. continue;
  134. sdw_fill_xport_params(&p_rt->transport_params, p_rt->num,
  135. false, SDW_BLK_GRP_CNT_1, sample_int,
  136. *port_bo, (*port_bo) >> 8, hstart, hstop,
  137. SDW_BLK_PKG_PER_PORT, p_rt->lane);
  138. sdw_fill_port_params(&p_rt->port_params,
  139. p_rt->num, bps,
  140. SDW_PORT_FLOW_MODE_ISOCH,
  141. b_params->m_data_mode);
  142. /* Check for first entry */
  143. if (!(p_rt == list_first_entry(&m_rt->port_list,
  144. struct sdw_port_runtime,
  145. port_node))) {
  146. (*port_bo) += bps * ch;
  147. continue;
  148. }
  149. t_data.hstart = hstart;
  150. t_data.hstop = hstop;
  151. t_data.block_offset = *port_bo;
  152. t_data.sub_block_offset = 0;
  153. (*port_bo) += bps * ch;
  154. }
  155. t_data.lane = params->lane;
  156. sdw_compute_slave_ports(m_rt, &t_data);
  157. }
  158. static void _sdw_compute_port_params(struct sdw_bus *bus,
  159. struct sdw_group_params *params, int count)
  160. {
  161. struct sdw_master_runtime *m_rt;
  162. int port_bo, i, l;
  163. int hstop;
  164. /* Run loop for all groups to compute transport parameters */
  165. for (l = 0; l < SDW_MAX_LANES; l++) {
  166. if (l > 0 && !bus->lane_used_bandwidth[l])
  167. continue;
  168. /* reset hstop for each lane */
  169. hstop = bus->params.col - 1;
  170. for (i = 0; i < count; i++) {
  171. if (params[i].lane != l)
  172. continue;
  173. port_bo = 1;
  174. list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) {
  175. /*
  176. * Only runtimes with CONFIGURED, PREPARED, ENABLED, and DISABLED
  177. * states should be included in the bandwidth calculation.
  178. */
  179. if (m_rt->stream->state > SDW_STREAM_DISABLED ||
  180. m_rt->stream->state < SDW_STREAM_CONFIGURED)
  181. continue;
  182. sdw_compute_master_ports(m_rt, &params[i], &port_bo, hstop);
  183. }
  184. hstop = hstop - params[i].hwidth;
  185. }
  186. }
  187. }
  188. static int sdw_compute_group_params(struct sdw_bus *bus,
  189. struct sdw_stream_runtime *stream,
  190. struct sdw_group_params *params,
  191. struct sdw_group *group)
  192. {
  193. struct sdw_master_runtime *m_rt;
  194. struct sdw_port_runtime *p_rt;
  195. int sel_col = bus->params.col;
  196. unsigned int rate, bps, ch;
  197. int i, l, column_needed;
  198. /* Calculate bandwidth per group */
  199. for (i = 0; i < group->count; i++) {
  200. params[i].rate = group->rates[i];
  201. params[i].lane = group->lanes[i];
  202. params[i].full_bw = bus->params.curr_dr_freq / params[i].rate;
  203. }
  204. list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) {
  205. if (m_rt->stream == stream) {
  206. /* Only runtime during prepare should be added */
  207. if (stream->state != SDW_STREAM_CONFIGURED)
  208. continue;
  209. } else {
  210. /*
  211. * Include runtimes with running (ENABLED/PREPARED state) and
  212. * paused (DISABLED state) streams
  213. */
  214. if (m_rt->stream->state != SDW_STREAM_ENABLED &&
  215. m_rt->stream->state != SDW_STREAM_PREPARED &&
  216. m_rt->stream->state != SDW_STREAM_DISABLED)
  217. continue;
  218. }
  219. list_for_each_entry(p_rt, &m_rt->port_list, port_node) {
  220. rate = m_rt->stream->params.rate;
  221. bps = m_rt->stream->params.bps;
  222. ch = hweight32(p_rt->ch_mask);
  223. for (i = 0; i < group->count; i++) {
  224. if (rate == params[i].rate && p_rt->lane == params[i].lane)
  225. params[i].payload_bw += bps * ch;
  226. }
  227. }
  228. }
  229. for (l = 0; l < SDW_MAX_LANES; l++) {
  230. if (l > 0 && !bus->lane_used_bandwidth[l])
  231. continue;
  232. /* reset column_needed for each lane */
  233. column_needed = 0;
  234. for (i = 0; i < group->count; i++) {
  235. if (params[i].lane != l)
  236. continue;
  237. params[i].hwidth = (sel_col * params[i].payload_bw +
  238. params[i].full_bw - 1) / params[i].full_bw;
  239. column_needed += params[i].hwidth;
  240. /* There is no control column for lane 1 and above */
  241. if (column_needed > sel_col)
  242. return -EINVAL;
  243. /* Column 0 is control column on lane 0 */
  244. if (params[i].lane == 0 && column_needed > sel_col - 1)
  245. return -EINVAL;
  246. }
  247. }
  248. return 0;
  249. }
  250. static int sdw_add_element_group_count(struct sdw_group *group,
  251. unsigned int rate, unsigned int lane)
  252. {
  253. int num = group->count;
  254. int i;
  255. for (i = 0; i <= num; i++) {
  256. if (rate == group->rates[i] && lane == group->lanes[i])
  257. break;
  258. if (i != num)
  259. continue;
  260. if (group->count >= group->max_size) {
  261. unsigned int *rates;
  262. unsigned int *lanes;
  263. group->max_size += 1;
  264. rates = krealloc(group->rates,
  265. (sizeof(int) * group->max_size),
  266. GFP_KERNEL);
  267. if (!rates)
  268. return -ENOMEM;
  269. group->rates = rates;
  270. lanes = krealloc(group->lanes,
  271. (sizeof(int) * group->max_size),
  272. GFP_KERNEL);
  273. if (!lanes)
  274. return -ENOMEM;
  275. group->lanes = lanes;
  276. }
  277. group->rates[group->count] = rate;
  278. group->lanes[group->count++] = lane;
  279. }
  280. return 0;
  281. }
  282. static int sdw_get_group_count(struct sdw_bus *bus,
  283. struct sdw_group *group)
  284. {
  285. struct sdw_master_runtime *m_rt;
  286. struct sdw_port_runtime *p_rt;
  287. unsigned int rate;
  288. int ret = 0;
  289. group->count = 0;
  290. group->max_size = SDW_STRM_RATE_GROUPING;
  291. group->rates = kcalloc(group->max_size, sizeof(int), GFP_KERNEL);
  292. if (!group->rates)
  293. return -ENOMEM;
  294. group->lanes = kcalloc(group->max_size, sizeof(int), GFP_KERNEL);
  295. if (!group->lanes) {
  296. kfree(group->rates);
  297. group->rates = NULL;
  298. return -ENOMEM;
  299. }
  300. list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) {
  301. if (m_rt->stream->state == SDW_STREAM_DEPREPARED)
  302. continue;
  303. rate = m_rt->stream->params.rate;
  304. if (m_rt == list_first_entry(&bus->m_rt_list,
  305. struct sdw_master_runtime,
  306. bus_node)) {
  307. group->rates[group->count++] = rate;
  308. }
  309. /*
  310. * Different ports could use different lane, add group element
  311. * even if m_rt is the first entry
  312. */
  313. list_for_each_entry(p_rt, &m_rt->port_list, port_node) {
  314. ret = sdw_add_element_group_count(group, rate, p_rt->lane);
  315. if (ret < 0) {
  316. kfree(group->rates);
  317. kfree(group->lanes);
  318. return ret;
  319. }
  320. }
  321. }
  322. return ret;
  323. }
  324. /**
  325. * sdw_compute_port_params: Compute transport and port parameters
  326. *
  327. * @bus: SDW Bus instance
  328. * @stream: Soundwire stream
  329. */
  330. static int sdw_compute_port_params(struct sdw_bus *bus, struct sdw_stream_runtime *stream)
  331. {
  332. struct sdw_group_params *params = NULL;
  333. struct sdw_group group;
  334. int ret;
  335. ret = sdw_get_group_count(bus, &group);
  336. if (ret < 0)
  337. return ret;
  338. if (group.count == 0)
  339. goto out;
  340. params = kzalloc_objs(*params, group.count);
  341. if (!params) {
  342. ret = -ENOMEM;
  343. goto out;
  344. }
  345. /* Compute transport parameters for grouped streams */
  346. ret = sdw_compute_group_params(bus, stream, params, &group);
  347. if (ret < 0)
  348. goto free_params;
  349. _sdw_compute_port_params(bus, params, group.count);
  350. free_params:
  351. kfree(params);
  352. out:
  353. kfree(group.rates);
  354. kfree(group.lanes);
  355. return ret;
  356. }
  357. static int sdw_select_row_col(struct sdw_bus *bus, int clk_freq)
  358. {
  359. struct sdw_master_prop *prop = &bus->prop;
  360. int r, c;
  361. for (c = 0; c < SDW_FRAME_COLS; c++) {
  362. for (r = 0; r < SDW_FRAME_ROWS; r++) {
  363. if (sdw_rows[r] != prop->default_row ||
  364. sdw_cols[c] != prop->default_col)
  365. continue;
  366. if (clk_freq * (sdw_cols[c] - 1) <
  367. bus->params.bandwidth * sdw_cols[c])
  368. continue;
  369. bus->params.row = sdw_rows[r];
  370. bus->params.col = sdw_cols[c];
  371. return 0;
  372. }
  373. }
  374. return -EINVAL;
  375. }
  376. static bool is_clock_scaling_supported(struct sdw_bus *bus)
  377. {
  378. struct sdw_master_runtime *m_rt;
  379. struct sdw_slave_runtime *s_rt;
  380. list_for_each_entry(m_rt, &bus->m_rt_list, bus_node)
  381. list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node)
  382. if (!is_clock_scaling_supported_by_slave(s_rt->slave))
  383. return false;
  384. return true;
  385. }
  386. /**
  387. * is_lane_connected_to_all_peripherals: Check if the given manager lane connects to all peripherals
  388. * So that all peripherals can use the manager lane.
  389. *
  390. * @m_rt: Manager runtime
  391. * @lane: Lane number
  392. */
  393. static bool is_lane_connected_to_all_peripherals(struct sdw_master_runtime *m_rt, unsigned int lane)
  394. {
  395. struct sdw_slave_prop *slave_prop;
  396. struct sdw_slave_runtime *s_rt;
  397. int i;
  398. list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) {
  399. slave_prop = &s_rt->slave->prop;
  400. for (i = 1; i < SDW_MAX_LANES; i++) {
  401. if (slave_prop->lane_maps[i] == lane) {
  402. dev_dbg(&s_rt->slave->dev,
  403. "M lane %d is connected to P lane %d\n",
  404. lane, i);
  405. break;
  406. }
  407. }
  408. if (i == SDW_MAX_LANES) {
  409. dev_dbg(&s_rt->slave->dev, "M lane %d is not connected\n", lane);
  410. return false;
  411. }
  412. }
  413. return true;
  414. }
  415. static int get_manager_lane(struct sdw_bus *bus, struct sdw_master_runtime *m_rt,
  416. struct sdw_slave_runtime *s_rt, unsigned int curr_dr_freq)
  417. {
  418. struct sdw_slave_prop *slave_prop = &s_rt->slave->prop;
  419. struct sdw_port_runtime *m_p_rt;
  420. unsigned int required_bandwidth;
  421. int m_lane;
  422. int l;
  423. for (l = 1; l < SDW_MAX_LANES; l++) {
  424. if (!slave_prop->lane_maps[l])
  425. continue;
  426. required_bandwidth = 0;
  427. list_for_each_entry(m_p_rt, &m_rt->port_list, port_node) {
  428. required_bandwidth += m_rt->stream->params.rate *
  429. hweight32(m_p_rt->ch_mask) *
  430. m_rt->stream->params.bps;
  431. }
  432. if (required_bandwidth <=
  433. curr_dr_freq - bus->lane_used_bandwidth[l]) {
  434. /* Check if m_lane is connected to all Peripherals */
  435. if (!is_lane_connected_to_all_peripherals(m_rt,
  436. slave_prop->lane_maps[l])) {
  437. dev_dbg(bus->dev,
  438. "Not all Peripherals are connected to M lane %d\n",
  439. slave_prop->lane_maps[l]);
  440. continue;
  441. }
  442. m_lane = slave_prop->lane_maps[l];
  443. dev_dbg(&s_rt->slave->dev, "M lane %d is used\n", m_lane);
  444. bus->lane_used_bandwidth[l] += required_bandwidth;
  445. /*
  446. * Use non-zero manager lane, subtract the lane 0
  447. * bandwidth that is already calculated
  448. */
  449. bus->params.bandwidth -= required_bandwidth;
  450. return m_lane;
  451. }
  452. }
  453. /* No available multi lane found, only lane 0 can be used */
  454. return 0;
  455. }
  456. /**
  457. * sdw_compute_bus_params: Compute bus parameters
  458. *
  459. * @bus: SDW Bus instance
  460. */
  461. static int sdw_compute_bus_params(struct sdw_bus *bus)
  462. {
  463. struct sdw_master_prop *mstr_prop = &bus->prop;
  464. struct sdw_slave_prop *slave_prop;
  465. struct sdw_port_runtime *m_p_rt;
  466. struct sdw_port_runtime *s_p_rt;
  467. struct sdw_master_runtime *m_rt;
  468. struct sdw_slave_runtime *s_rt;
  469. unsigned int curr_dr_freq = 0;
  470. int i, l, clk_values, ret;
  471. bool is_gear = false;
  472. int m_lane = 0;
  473. u32 *clk_buf;
  474. if (mstr_prop->num_clk_gears) {
  475. clk_values = mstr_prop->num_clk_gears;
  476. clk_buf = mstr_prop->clk_gears;
  477. is_gear = true;
  478. } else if (mstr_prop->num_clk_freq) {
  479. clk_values = mstr_prop->num_clk_freq;
  480. clk_buf = mstr_prop->clk_freq;
  481. } else {
  482. clk_values = 1;
  483. clk_buf = NULL;
  484. }
  485. /* If dynamic scaling is not supported, don't try higher freq */
  486. if (!is_clock_scaling_supported(bus))
  487. clk_values = 1;
  488. for (i = 0; i < clk_values; i++) {
  489. if (!clk_buf)
  490. curr_dr_freq = bus->params.max_dr_freq;
  491. else
  492. curr_dr_freq = (is_gear) ?
  493. (bus->params.max_dr_freq >> clk_buf[i]) :
  494. clk_buf[i] * SDW_DOUBLE_RATE_FACTOR;
  495. if (curr_dr_freq * (mstr_prop->default_col - 1) >=
  496. bus->params.bandwidth * mstr_prop->default_col)
  497. break;
  498. list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) {
  499. /*
  500. * Get the first s_rt that will be used to find the available lane that
  501. * can be used. No need to check all Peripherals because we can't use
  502. * multi-lane if we can't find any available lane for the first Peripheral.
  503. */
  504. s_rt = list_first_entry(&m_rt->slave_rt_list,
  505. struct sdw_slave_runtime, m_rt_node);
  506. /*
  507. * Find the available Manager lane that connected to the first Peripheral.
  508. */
  509. m_lane = get_manager_lane(bus, m_rt, s_rt, curr_dr_freq);
  510. if (m_lane > 0)
  511. goto out;
  512. }
  513. /*
  514. * TODO: Check all the Slave(s) port(s) audio modes and find
  515. * whether given clock rate is supported with glitchless
  516. * transition.
  517. */
  518. }
  519. if (i == clk_values) {
  520. dev_err(bus->dev, "%s: could not find clock value for bandwidth %d\n",
  521. __func__, bus->params.bandwidth);
  522. return -EINVAL;
  523. }
  524. out:
  525. /* multilane can be used */
  526. if (m_lane > 0) {
  527. /* Set Peripheral lanes */
  528. list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) {
  529. slave_prop = &s_rt->slave->prop;
  530. for (l = 1; l < SDW_MAX_LANES; l++) {
  531. if (slave_prop->lane_maps[l] == m_lane) {
  532. list_for_each_entry(s_p_rt, &s_rt->port_list, port_node) {
  533. s_p_rt->lane = l;
  534. dev_dbg(&s_rt->slave->dev,
  535. "Set P lane %d for port %d\n",
  536. l, s_p_rt->num);
  537. }
  538. break;
  539. }
  540. }
  541. }
  542. /*
  543. * Set Manager lanes. Configure the last m_rt in bus->m_rt_list only since
  544. * we don't want to touch other m_rts that are already working.
  545. */
  546. list_for_each_entry(m_p_rt, &m_rt->port_list, port_node) {
  547. m_p_rt->lane = m_lane;
  548. }
  549. }
  550. if (!mstr_prop->default_frame_rate || !mstr_prop->default_row)
  551. return -EINVAL;
  552. mstr_prop->default_col = curr_dr_freq / mstr_prop->default_frame_rate /
  553. mstr_prop->default_row;
  554. ret = sdw_select_row_col(bus, curr_dr_freq);
  555. if (ret < 0) {
  556. dev_err(bus->dev, "%s: could not find frame configuration for bus dr_freq %d\n",
  557. __func__, curr_dr_freq);
  558. return -EINVAL;
  559. }
  560. bus->params.curr_dr_freq = curr_dr_freq;
  561. return 0;
  562. }
  563. /**
  564. * sdw_compute_params: Compute bus, transport and port parameters
  565. *
  566. * @bus: SDW Bus instance
  567. * @stream: Soundwire stream
  568. */
  569. int sdw_compute_params(struct sdw_bus *bus, struct sdw_stream_runtime *stream)
  570. {
  571. int ret;
  572. /* Computes clock frequency, frame shape and frame frequency */
  573. ret = sdw_compute_bus_params(bus);
  574. if (ret < 0)
  575. return ret;
  576. if (stream->type == SDW_STREAM_BPT) {
  577. sdw_compute_dp0_port_params(bus);
  578. return 0;
  579. }
  580. /* Compute transport and port params */
  581. ret = sdw_compute_port_params(bus, stream);
  582. if (ret < 0) {
  583. dev_err(bus->dev, "Compute transport params failed: %d\n", ret);
  584. return ret;
  585. }
  586. return 0;
  587. }
  588. EXPORT_SYMBOL(sdw_compute_params);
  589. MODULE_LICENSE("Dual BSD/GPL");
  590. MODULE_DESCRIPTION("SoundWire Generic Bandwidth Allocation");