Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'qcom-geni-immutable-for-mark-brown' of git://git.kernel.org/pub/scm/linux/kernel/git/agross/linux into spi-4.20

Immutable branch for QCOM Geni patches

+28 -26
+24 -17
drivers/soc/qcom/qcom-geni-se.c
··· 513 513 */ 514 514 int geni_se_clk_tbl_get(struct geni_se *se, unsigned long **tbl) 515 515 { 516 - unsigned long freq = 0; 516 + long freq = 0; 517 517 int i; 518 518 519 519 if (se->clk_perf_tbl) { ··· 529 529 530 530 for (i = 0; i < MAX_CLK_PERF_LEVEL; i++) { 531 531 freq = clk_round_rate(se->clk, freq + 1); 532 - if (!freq || freq == se->clk_perf_tbl[i - 1]) 532 + if (freq <= 0 || freq == se->clk_perf_tbl[i - 1]) 533 533 break; 534 534 se->clk_perf_tbl[i] = freq; 535 535 } ··· 544 544 * @se: Pointer to the concerned serial engine. 545 545 * @req_freq: Requested clock frequency. 546 546 * @index: Index of the resultant frequency in the table. 547 - * @res_freq: Resultant frequency which matches or is closer to the 548 - * requested frequency. 547 + * @res_freq: Resultant frequency of the source clock. 549 548 * @exact: Flag to indicate exact multiple requirement of the requested 550 549 * frequency. 551 550 * 552 - * This function is called by the protocol drivers to determine the matching 553 - * or exact multiple of the requested frequency, as provided by the serial 554 - * engine clock in order to meet the performance requirements. If there is 555 - * no matching or exact multiple of the requested frequency found, then it 556 - * selects the closest floor frequency, if exact flag is not set. 551 + * This function is called by the protocol drivers to determine the best match 552 + * of the requested frequency as provided by the serial engine clock in order 553 + * to meet the performance requirements. 554 + * 555 + * If we return success: 556 + * - if @exact is true then @res_freq / <an_integer> == @req_freq 557 + * - if @exact is false then @res_freq / <an_integer> <= @req_freq 557 558 * 558 559 * Return: 0 on success, standard Linux error codes on failure. 559 560 */ ··· 565 564 unsigned long *tbl; 566 565 int num_clk_levels; 567 566 int i; 567 + unsigned long best_delta; 568 + unsigned long new_delta; 569 + unsigned int divider; 568 570 569 571 num_clk_levels = geni_se_clk_tbl_get(se, &tbl); 570 572 if (num_clk_levels < 0) ··· 576 572 if (num_clk_levels == 0) 577 573 return -EINVAL; 578 574 579 - *res_freq = 0; 575 + best_delta = ULONG_MAX; 580 576 for (i = 0; i < num_clk_levels; i++) { 581 - if (!(tbl[i] % req_freq)) { 577 + divider = DIV_ROUND_UP(tbl[i], req_freq); 578 + new_delta = req_freq - tbl[i] / divider; 579 + if (new_delta < best_delta) { 580 + /* We have a new best! */ 582 581 *index = i; 583 582 *res_freq = tbl[i]; 584 - return 0; 585 - } 586 583 587 - if (!(*res_freq) || ((tbl[i] > *res_freq) && 588 - (tbl[i] < req_freq))) { 589 - *index = i; 590 - *res_freq = tbl[i]; 584 + /* If the new best is exact then we're done */ 585 + if (new_delta == 0) 586 + return 0; 587 + 588 + /* Record how close we got */ 589 + best_delta = new_delta; 591 590 } 592 591 } 593 592
+4 -9
include/linux/qcom-geni-se.h
··· 225 225 #define HW_VER_MINOR_SHFT 16 226 226 #define HW_VER_STEP_MASK GENMASK(15, 0) 227 227 228 + #define GENI_SE_VERSION_MAJOR(ver) ((ver & HW_VER_MAJOR_MASK) >> HW_VER_MAJOR_SHFT) 229 + #define GENI_SE_VERSION_MINOR(ver) ((ver & HW_VER_MINOR_MASK) >> HW_VER_MINOR_SHFT) 230 + #define GENI_SE_VERSION_STEP(ver) (ver & HW_VER_STEP_MASK) 231 + 228 232 #if IS_ENABLED(CONFIG_QCOM_GENI_SE) 229 233 230 234 u32 geni_se_get_qup_hw_version(struct geni_se *se); 231 - 232 - #define geni_se_get_wrapper_version(se, major, minor, step) do { \ 233 - u32 ver; \ 234 - \ 235 - ver = geni_se_get_qup_hw_version(se); \ 236 - major = (ver & HW_VER_MAJOR_MASK) >> HW_VER_MAJOR_SHFT; \ 237 - minor = (ver & HW_VER_MINOR_MASK) >> HW_VER_MINOR_SHFT; \ 238 - step = version & HW_VER_STEP_MASK; \ 239 - } while (0) 240 235 241 236 /** 242 237 * geni_se_read_proto() - Read the protocol configured for a serial engine