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

drivers: clk: st: Correct the pll-type for A9 for stih418

Add support for new PLL-type for stih418 A9-PLL.
Currently the 407_A9_PLL type being used, it is corrected with this patch
4600c28 PLL allows to reach higher frequencies
so its programming algorithm is extended.

Signed-off-by: Pankaj Dev <pankaj.dev@st.com>
Signed-off-by: Gabriel Fernandez <gabriel.fernandez@linaro.org>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

authored by

Gabriel Fernandez and committed by
Stephen Boyd
0829ea5a 46a57afd

+195
+1
Documentation/devicetree/bindings/clock/st/st,clkgen-pll.txt
··· 23 23 "st,stih407-plls-c32-a9", "st,clkgen-plls-c32" 24 24 "sst,plls-c32-cx_0", "st,clkgen-plls-c32" 25 25 "sst,plls-c32-cx_1", "st,clkgen-plls-c32" 26 + "st,stih418-plls-c28-a9", "st,clkgen-plls-c32" 26 27 27 28 "st,stih415-gpu-pll-c32", "st,clkgengpu-pll-c32" 28 29 "st,stih416-gpu-pll-c32", "st,clkgengpu-pll-c32"
+194
drivers/clk/st/clkgen-pll.c
··· 44 44 45 45 #define C32_MAX_ODFS (4) 46 46 47 + /* 48 + * PLL configuration register bits for PLL4600 C28 49 + */ 50 + #define C28_NDIV_MASK (0xff) 51 + #define C28_IDF_MASK (0x7) 52 + #define C28_ODF_MASK (0x3f) 53 + 47 54 struct clkgen_pll_data { 48 55 struct clkgen_field pdn_status; 49 56 struct clkgen_field pdn_ctrl; ··· 75 68 static const struct clk_ops stm_pll3200c32_ops; 76 69 static const struct clk_ops stm_pll3200c32_a9_ops; 77 70 static const struct clk_ops st_pll1200c32_ops; 71 + static const struct clk_ops stm_pll4600c28_ops; 78 72 79 73 static const struct clkgen_pll_data st_pll1600c65_ax = { 80 74 .pdn_status = CLKGEN_FIELD(0x0, 0x1, 19), ··· 262 254 .switch2pll = CLKGEN_FIELD(0x1a4, 0x1, 1), 263 255 .lock = &clkgen_a9_lock, 264 256 .ops = &stm_pll3200c32_a9_ops, 257 + }; 258 + 259 + static struct clkgen_pll_data st_pll4600c28_418_a9 = { 260 + /* 418 A9 */ 261 + .pdn_status = CLKGEN_FIELD(0x1a8, 0x1, 0), 262 + .pdn_ctrl = CLKGEN_FIELD(0x1a8, 0x1, 0), 263 + .locked_status = CLKGEN_FIELD(0x87c, 0x1, 0), 264 + .ndiv = CLKGEN_FIELD(0x1b0, C28_NDIV_MASK, 0), 265 + .idf = CLKGEN_FIELD(0x1a8, C28_IDF_MASK, 25), 266 + .num_odfs = 1, 267 + .odf = { CLKGEN_FIELD(0x1b0, C28_ODF_MASK, 8) }, 268 + .odf_gate = { CLKGEN_FIELD(0x1ac, 0x1, 28) }, 269 + .switch2pll_en = true, 270 + .switch2pll = CLKGEN_FIELD(0x1a4, 0x1, 1), 271 + .lock = &clkgen_a9_lock, 272 + .ops = &stm_pll4600c28_ops, 265 273 }; 266 274 267 275 /** ··· 635 611 return rate; 636 612 } 637 613 614 + /* PLL output structure 615 + * FVCO >> /2 >> FVCOBY2 (no output) 616 + * |> Divider (ODF) >> PHI 617 + * 618 + * FVCOby2 output = (input * 2 * NDIV) / IDF (assuming FRAC_CONTROL==L) 619 + * 620 + * Rules: 621 + * 4Mhz <= INFF input <= 350Mhz 622 + * 4Mhz <= INFIN (INFF / IDF) <= 50Mhz 623 + * 19.05Mhz <= FVCOby2 output (PHI w ODF=1) <= 3000Mhz 624 + * 1 <= i (register/dec value for IDF) <= 7 625 + * 8 <= n (register/dec value for NDIV) <= 246 626 + */ 627 + 628 + static int clk_pll4600c28_get_params(unsigned long input, unsigned long output, 629 + struct stm_pll *pll) 630 + { 631 + 632 + unsigned long i, infin, n; 633 + unsigned long deviation = ~0; 634 + unsigned long new_freq, new_deviation; 635 + 636 + /* Output clock range: 19Mhz to 3000Mhz */ 637 + if (output < 19000000 || output > 3000000000u) 638 + return -EINVAL; 639 + 640 + /* For better jitter, IDF should be smallest and NDIV must be maximum */ 641 + for (i = 1; i <= 7 && deviation; i++) { 642 + /* INFIN checks */ 643 + infin = input / i; 644 + if (infin < 4000000 || infin > 50000000) 645 + continue; /* Invalid case */ 646 + 647 + n = output / (infin * 2); 648 + if (n < 8 || n > 246) 649 + continue; /* Invalid case */ 650 + if (n < 246) 651 + n++; /* To work around 'y' when n=x.y */ 652 + 653 + for (; n >= 8 && deviation; n--) { 654 + new_freq = infin * 2 * n; 655 + if (new_freq < output) 656 + break; /* Optimization: shorting loop */ 657 + 658 + new_deviation = new_freq - output; 659 + if (!new_deviation || new_deviation < deviation) { 660 + pll->idf = i; 661 + pll->ndiv = n; 662 + deviation = new_deviation; 663 + } 664 + } 665 + } 666 + 667 + if (deviation == ~0) /* No solution found */ 668 + return -EINVAL; 669 + 670 + return 0; 671 + } 672 + 673 + static int clk_pll4600c28_get_rate(unsigned long input, struct stm_pll *pll, 674 + unsigned long *rate) 675 + { 676 + if (!pll->idf) 677 + pll->idf = 1; 678 + 679 + *rate = (input / pll->idf) * 2 * pll->ndiv; 680 + 681 + return 0; 682 + } 683 + 684 + static unsigned long recalc_stm_pll4600c28(struct clk_hw *hw, 685 + unsigned long parent_rate) 686 + { 687 + struct clkgen_pll *pll = to_clkgen_pll(hw); 688 + struct stm_pll params; 689 + unsigned long rate; 690 + 691 + if (!clkgen_pll_is_enabled(hw) || !clkgen_pll_is_locked(hw)) 692 + return 0; 693 + 694 + params.ndiv = CLKGEN_READ(pll, ndiv); 695 + params.idf = CLKGEN_READ(pll, idf); 696 + 697 + clk_pll4600c28_get_rate(parent_rate, &params, &rate); 698 + 699 + pr_debug("%s:%s rate %lu\n", __clk_get_name(hw->clk), __func__, rate); 700 + 701 + return rate; 702 + } 703 + 704 + static long round_rate_stm_pll4600c28(struct clk_hw *hw, unsigned long rate, 705 + unsigned long *prate) 706 + { 707 + struct stm_pll params; 708 + 709 + if (!clk_pll4600c28_get_params(*prate, rate, &params)) { 710 + clk_pll4600c28_get_rate(*prate, &params, &rate); 711 + } else { 712 + pr_debug("%s: %s rate %ld Invalid\n", __func__, 713 + __clk_get_name(hw->clk), rate); 714 + return 0; 715 + } 716 + 717 + pr_debug("%s: %s new rate %ld [ndiv=%u] [idf=%u]\n", 718 + __func__, __clk_get_name(hw->clk), 719 + rate, (unsigned int)params.ndiv, 720 + (unsigned int)params.idf); 721 + 722 + return rate; 723 + } 724 + 725 + static int set_rate_stm_pll4600c28(struct clk_hw *hw, unsigned long rate, 726 + unsigned long parent_rate) 727 + { 728 + struct clkgen_pll *pll = to_clkgen_pll(hw); 729 + struct stm_pll params; 730 + long hwrate; 731 + unsigned long flags = 0; 732 + 733 + if (!rate || !parent_rate) 734 + return -EINVAL; 735 + 736 + if (!clk_pll4600c28_get_params(parent_rate, rate, &params)) { 737 + clk_pll4600c28_get_rate(parent_rate, &params, &hwrate); 738 + } else { 739 + pr_debug("%s: %s rate %ld Invalid\n", __func__, 740 + __clk_get_name(hw->clk), rate); 741 + return -EINVAL; 742 + } 743 + 744 + pr_debug("%s: %s new rate %ld [ndiv=0x%x] [idf=0x%x]\n", 745 + __func__, __clk_get_name(hw->clk), 746 + hwrate, (unsigned int)params.ndiv, 747 + (unsigned int)params.idf); 748 + 749 + if (!hwrate) 750 + return -EINVAL; 751 + 752 + pll->ndiv = params.ndiv; 753 + pll->idf = params.idf; 754 + 755 + __clkgen_pll_disable(hw); 756 + 757 + if (pll->lock) 758 + spin_lock_irqsave(pll->lock, flags); 759 + 760 + CLKGEN_WRITE(pll, ndiv, pll->ndiv); 761 + CLKGEN_WRITE(pll, idf, pll->idf); 762 + 763 + if (pll->lock) 764 + spin_unlock_irqrestore(pll->lock, flags); 765 + 766 + __clkgen_pll_enable(hw); 767 + 768 + return 0; 769 + } 770 + 638 771 static const struct clk_ops st_pll1600c65_ops = { 639 772 .enable = clkgen_pll_enable, 640 773 .disable = clkgen_pll_disable, ··· 827 646 .disable = clkgen_pll_disable, 828 647 .is_enabled = clkgen_pll_is_enabled, 829 648 .recalc_rate = recalc_stm_pll1200c32, 649 + }; 650 + 651 + static const struct clk_ops stm_pll4600c28_ops = { 652 + .enable = clkgen_pll_enable, 653 + .disable = clkgen_pll_disable, 654 + .is_enabled = clkgen_pll_is_enabled, 655 + .recalc_rate = recalc_stm_pll4600c28, 656 + .round_rate = round_rate_stm_pll4600c28, 657 + .set_rate = set_rate_stm_pll4600c28, 830 658 }; 831 659 832 660 static struct clk * __init clkgen_pll_register(const char *parent_name, ··· 1082 892 { 1083 893 .compatible = "st,stih407-plls-c32-a9", 1084 894 .data = &st_pll3200c32_407_a9, 895 + }, 896 + { 897 + .compatible = "st,stih418-plls-c28-a9", 898 + .data = &st_pll4600c28_418_a9, 1085 899 }, 1086 900 {} 1087 901 };