mirror of
https://github.com/torvalds/linux.git
synced 2024-11-25 21:51:40 +00:00
916f562fb2
side. The two main highlights in the core framework are the addition of an bulk clk_get API that handles optional clks and an extra debugfs file that tells the developer about the current parent of a clk. The driver updates are dominated by i.MX in the diffstat, but that is mostly because that SoC has started converting to the clk_hw style of clk registration. The next big update is in the Amlogic meson clk driver that gained some support for audio, cpu, and temperature clks while fixing some PLL issues. Finally, the biggest thing that stands out is the conversion of a large part of the Allwinner sunxi-ng driver to the new clk parent scheme that uses less strings and more pointer comparisons to match clk parents and children up. In general, it looks like we have a lot of little fixes and tweaks here and there to clk data along with the normal addition of a handful of new drivers and a couple new core framework features. Core: - Add a 'clk_parent' file in clk debugfs - Add a clk_bulk_get_optional() API (with devm too) New Drivers: - Support gated clk controller on MIPS based BCM63XX SoCs - Support SiLabs Si5341 and Si5340 chips - Support for CPU clks on Raspberry Pi devices - Audsys clock driver for MediaTek MT8516 SoCs Updates: - Convert a large portion of the Allwinner sunxi-ng driver to new clk parent scheme - Small frequency support for SiLabs Si544 chips - Slow clk support for AT91 SAM9X60 SoCs - Remove dead code in various clk drivers (-Wunused) - Support for Marvell 98DX1135 SoCs - Get duty cycle of generic pwm clks - Improvement in mmc phase calculation and cleanup of some rate defintions - Switch i.MX6 and i.MX7 clock drivers to clk_hw based APIs - Add GPIO, SNVS and GIC clocks for i.MX8 drivers - Mark imx6sx/ul/ull/sll MMDC_P1_IPG and imx8mm DRAM_APB as critical clock - Correct imx7ulp nic1_bus_clk and imx8mm audio_pll2_clk clock setting - Add clks for new Exynos5422 Dynamic Memory Controller driver - Clock definition for Exynos4412 Mali - Add CMM (Color Management Module) clocks on Renesas R-Car H3, M3-N, E3, and D3 - Add TPU (Timer Pulse Unit / PWM) clocks on Renesas RZ/G2M - Support for 32 bit clock IDs in TI's sci-clks for J721e SoCs - TI clock probing done from DT by default instead of firmware - Fix Amlogic Meson mpll fractional part and spread sprectrum issues - Add Amlogic meson8 audio clocks - Add Amlogic g12a temperature sensors clocks - Add Amlogic g12a and g12b cpu clocks - Add TPU (Timer Pulse Unit / PWM) clocks on Renesas R-Car H3, M3-W, and M3-N - Add CMM (Color Management Module) clocks on Renesas R-Car M3-W - Add Clock Domain support on Renesas RZ/N1 -----BEGIN PGP SIGNATURE----- iQJFBAABCAAvFiEE9L57QeeUxqYDyoaDrQKIl8bklSUFAl0uBEERHHNib3lkQGtl cm5lbC5vcmcACgkQrQKIl8bklSWucw/9ELKlfvdxrc8mdIuzt+CpKdNiSG88shXY hF+vnuE6Jhv5hmlbA/DbplPTAnHT/FQF65/GPQMAYy2wYO6CjleNxQyepiVv4h8/ tWoXu5vYZXubtQyMnYTffREzjYFPBNAscLUhXNwJKRno7nT0qKCk62WgOMfaW/KN lP5dKmrL7rdJDUvxHEStrwP515Lg5Wkhj3+XzgbgFUKGuGlvHfwUOEZucT++kqhu Z1vMjPv2ksHQf3r15BsbX/6jMIONEt2Xd6jA3Lm7ebDXJl2hjX4Gq0Kkl5pmkj2w F0V7Tw4XYk6DkSl7HQaOBgQ8KV0Mw2L8Vj6eEDhUwx6wPGlQ5YTKkUCJkjs0mUyb UpO3TuPFN2W0hsTNDzwYpjqcfodDn159XJcduv1/ZpIanUvHgx0uVzQ7iwwYwW+l VR4SipY5AEn9hpief30X7TAUSKsE4do58imYeoGBrq78zdsJaEcDAMX7AcYdXVQ9 ahBS8ME/d1JEBNdRsSW7eTAfu8dZdI08uR8/T37GRG59XyZSjsyVmZ6kHCYrBygF AyLNMsXMCbW1rOoIpWkuGMD86XZy40laLg8T7WWTaq28t1VQ0BaBTGM4/eEexs3p FhZ1M7aH+PsDLrI2IGTBt/4xAMv+dhDS7HnxRlOONbWnLWVqmR+tYzF0aCkqJCmd O2zWCGffeYs= =mK0C -----END PGP SIGNATURE----- Merge tag 'clk-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux Pull clk updates from Stephen Boyd: "This round of clk driver and framework updates is heavy on the driver update side. The two main highlights in the core framework are the addition of an bulk clk_get API that handles optional clks and an extra debugfs file that tells the developer about the current parent of a clk. The driver updates are dominated by i.MX in the diffstat, but that is mostly because that SoC has started converting to the clk_hw style of clk registration. The next big update is in the Amlogic meson clk driver that gained some support for audio, cpu, and temperature clks while fixing some PLL issues. Finally, the biggest thing that stands out is the conversion of a large part of the Allwinner sunxi-ng driver to the new clk parent scheme that uses less strings and more pointer comparisons to match clk parents and children up. In general, it looks like we have a lot of little fixes and tweaks here and there to clk data along with the normal addition of a handful of new drivers and a couple new core framework features. Core: - Add a 'clk_parent' file in clk debugfs - Add a clk_bulk_get_optional() API (with devm too) New Drivers: - Support gated clk controller on MIPS based BCM63XX SoCs - Support SiLabs Si5341 and Si5340 chips - Support for CPU clks on Raspberry Pi devices - Audsys clock driver for MediaTek MT8516 SoCs Updates: - Convert a large portion of the Allwinner sunxi-ng driver to new clk parent scheme - Small frequency support for SiLabs Si544 chips - Slow clk support for AT91 SAM9X60 SoCs - Remove dead code in various clk drivers (-Wunused) - Support for Marvell 98DX1135 SoCs - Get duty cycle of generic pwm clks - Improvement in mmc phase calculation and cleanup of some rate defintions - Switch i.MX6 and i.MX7 clock drivers to clk_hw based APIs - Add GPIO, SNVS and GIC clocks for i.MX8 drivers - Mark imx6sx/ul/ull/sll MMDC_P1_IPG and imx8mm DRAM_APB as critical clock - Correct imx7ulp nic1_bus_clk and imx8mm audio_pll2_clk clock setting - Add clks for new Exynos5422 Dynamic Memory Controller driver - Clock definition for Exynos4412 Mali - Add CMM (Color Management Module) clocks on Renesas R-Car H3, M3-N, E3, and D3 - Add TPU (Timer Pulse Unit / PWM) clocks on Renesas RZ/G2M - Support for 32 bit clock IDs in TI's sci-clks for J721e SoCs - TI clock probing done from DT by default instead of firmware - Fix Amlogic Meson mpll fractional part and spread sprectrum issues - Add Amlogic meson8 audio clocks - Add Amlogic g12a temperature sensors clocks - Add Amlogic g12a and g12b cpu clocks - Add TPU (Timer Pulse Unit / PWM) clocks on Renesas R-Car H3, M3-W, and M3-N - Add CMM (Color Management Module) clocks on Renesas R-Car M3-W - Add Clock Domain support on Renesas RZ/N1" * tag 'clk-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux: (190 commits) clk: consoldiate the __clk_get_hw() declarations clk: sprd: Add check for return value of sprd_clk_regmap_init() clk: lochnagar: Update DT binding doc to include the primary SPDIF MCLK clk: Add Si5341/Si5340 driver dt-bindings: clock: Add silabs,si5341 clk: clk-si544: Implement small frequency change support clk: add BCM63XX gated clock controller driver devicetree: document the BCM63XX gated clock bindings clk: at91: sckc: use dedicated functions to unregister clock clk: at91: sckc: improve error path for sama5d4 sck registration clk: at91: sckc: remove unnecessary line clk: at91: sckc: improve error path for sam9x5 sck register clk: at91: sckc: add support to free slow clock osclillator clk: at91: sckc: add support to free slow rc oscillator clk: at91: sckc: add support to free slow oscillator clk: rockchip: export HDMIPHY clock on rk3228 clk: rockchip: add watchdog pclk on rk3328 clk: rockchip: add clock id for hdmi_phy special clock on rk3228 clk: rockchip: add clock id for watchdog pclk on rk3328 clk: at91: sckc: add support for SAM9X60 ...
492 lines
12 KiB
C
492 lines
12 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* Copyright 2012 Freescale Semiconductor, Inc.
|
|
* Copyright 2012 Linaro Ltd.
|
|
*/
|
|
|
|
#include <linux/clk-provider.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/io.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/jiffies.h>
|
|
#include <linux/err.h>
|
|
#include "clk.h"
|
|
|
|
#define PLL_NUM_OFFSET 0x10
|
|
#define PLL_DENOM_OFFSET 0x20
|
|
#define PLL_IMX7_NUM_OFFSET 0x20
|
|
#define PLL_IMX7_DENOM_OFFSET 0x30
|
|
|
|
#define PLL_VF610_NUM_OFFSET 0x20
|
|
#define PLL_VF610_DENOM_OFFSET 0x30
|
|
|
|
#define BM_PLL_POWER (0x1 << 12)
|
|
#define BM_PLL_LOCK (0x1 << 31)
|
|
#define IMX7_ENET_PLL_POWER (0x1 << 5)
|
|
#define IMX7_DDR_PLL_POWER (0x1 << 20)
|
|
|
|
/**
|
|
* struct clk_pllv3 - IMX PLL clock version 3
|
|
* @clk_hw: clock source
|
|
* @base: base address of PLL registers
|
|
* @power_bit: pll power bit mask
|
|
* @powerup_set: set power_bit to power up the PLL
|
|
* @div_mask: mask of divider bits
|
|
* @div_shift: shift of divider bits
|
|
*
|
|
* IMX PLL clock version 3, found on i.MX6 series. Divider for pllv3
|
|
* is actually a multiplier, and always sits at bit 0.
|
|
*/
|
|
struct clk_pllv3 {
|
|
struct clk_hw hw;
|
|
void __iomem *base;
|
|
u32 power_bit;
|
|
bool powerup_set;
|
|
u32 div_mask;
|
|
u32 div_shift;
|
|
unsigned long ref_clock;
|
|
u32 num_offset;
|
|
u32 denom_offset;
|
|
};
|
|
|
|
#define to_clk_pllv3(_hw) container_of(_hw, struct clk_pllv3, hw)
|
|
|
|
static int clk_pllv3_wait_lock(struct clk_pllv3 *pll)
|
|
{
|
|
unsigned long timeout = jiffies + msecs_to_jiffies(10);
|
|
u32 val = readl_relaxed(pll->base) & pll->power_bit;
|
|
|
|
/* No need to wait for lock when pll is not powered up */
|
|
if ((pll->powerup_set && !val) || (!pll->powerup_set && val))
|
|
return 0;
|
|
|
|
/* Wait for PLL to lock */
|
|
do {
|
|
if (readl_relaxed(pll->base) & BM_PLL_LOCK)
|
|
break;
|
|
if (time_after(jiffies, timeout))
|
|
break;
|
|
usleep_range(50, 500);
|
|
} while (1);
|
|
|
|
return readl_relaxed(pll->base) & BM_PLL_LOCK ? 0 : -ETIMEDOUT;
|
|
}
|
|
|
|
static int clk_pllv3_prepare(struct clk_hw *hw)
|
|
{
|
|
struct clk_pllv3 *pll = to_clk_pllv3(hw);
|
|
u32 val;
|
|
|
|
val = readl_relaxed(pll->base);
|
|
if (pll->powerup_set)
|
|
val |= pll->power_bit;
|
|
else
|
|
val &= ~pll->power_bit;
|
|
writel_relaxed(val, pll->base);
|
|
|
|
return clk_pllv3_wait_lock(pll);
|
|
}
|
|
|
|
static void clk_pllv3_unprepare(struct clk_hw *hw)
|
|
{
|
|
struct clk_pllv3 *pll = to_clk_pllv3(hw);
|
|
u32 val;
|
|
|
|
val = readl_relaxed(pll->base);
|
|
if (pll->powerup_set)
|
|
val &= ~pll->power_bit;
|
|
else
|
|
val |= pll->power_bit;
|
|
writel_relaxed(val, pll->base);
|
|
}
|
|
|
|
static int clk_pllv3_is_prepared(struct clk_hw *hw)
|
|
{
|
|
struct clk_pllv3 *pll = to_clk_pllv3(hw);
|
|
|
|
if (readl_relaxed(pll->base) & BM_PLL_LOCK)
|
|
return 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static unsigned long clk_pllv3_recalc_rate(struct clk_hw *hw,
|
|
unsigned long parent_rate)
|
|
{
|
|
struct clk_pllv3 *pll = to_clk_pllv3(hw);
|
|
u32 div = (readl_relaxed(pll->base) >> pll->div_shift) & pll->div_mask;
|
|
|
|
return (div == 1) ? parent_rate * 22 : parent_rate * 20;
|
|
}
|
|
|
|
static long clk_pllv3_round_rate(struct clk_hw *hw, unsigned long rate,
|
|
unsigned long *prate)
|
|
{
|
|
unsigned long parent_rate = *prate;
|
|
|
|
return (rate >= parent_rate * 22) ? parent_rate * 22 :
|
|
parent_rate * 20;
|
|
}
|
|
|
|
static int clk_pllv3_set_rate(struct clk_hw *hw, unsigned long rate,
|
|
unsigned long parent_rate)
|
|
{
|
|
struct clk_pllv3 *pll = to_clk_pllv3(hw);
|
|
u32 val, div;
|
|
|
|
if (rate == parent_rate * 22)
|
|
div = 1;
|
|
else if (rate == parent_rate * 20)
|
|
div = 0;
|
|
else
|
|
return -EINVAL;
|
|
|
|
val = readl_relaxed(pll->base);
|
|
val &= ~(pll->div_mask << pll->div_shift);
|
|
val |= (div << pll->div_shift);
|
|
writel_relaxed(val, pll->base);
|
|
|
|
return clk_pllv3_wait_lock(pll);
|
|
}
|
|
|
|
static const struct clk_ops clk_pllv3_ops = {
|
|
.prepare = clk_pllv3_prepare,
|
|
.unprepare = clk_pllv3_unprepare,
|
|
.is_prepared = clk_pllv3_is_prepared,
|
|
.recalc_rate = clk_pllv3_recalc_rate,
|
|
.round_rate = clk_pllv3_round_rate,
|
|
.set_rate = clk_pllv3_set_rate,
|
|
};
|
|
|
|
static unsigned long clk_pllv3_sys_recalc_rate(struct clk_hw *hw,
|
|
unsigned long parent_rate)
|
|
{
|
|
struct clk_pllv3 *pll = to_clk_pllv3(hw);
|
|
u32 div = readl_relaxed(pll->base) & pll->div_mask;
|
|
|
|
return parent_rate * div / 2;
|
|
}
|
|
|
|
static long clk_pllv3_sys_round_rate(struct clk_hw *hw, unsigned long rate,
|
|
unsigned long *prate)
|
|
{
|
|
unsigned long parent_rate = *prate;
|
|
unsigned long min_rate = parent_rate * 54 / 2;
|
|
unsigned long max_rate = parent_rate * 108 / 2;
|
|
u32 div;
|
|
|
|
if (rate > max_rate)
|
|
rate = max_rate;
|
|
else if (rate < min_rate)
|
|
rate = min_rate;
|
|
div = rate * 2 / parent_rate;
|
|
|
|
return parent_rate * div / 2;
|
|
}
|
|
|
|
static int clk_pllv3_sys_set_rate(struct clk_hw *hw, unsigned long rate,
|
|
unsigned long parent_rate)
|
|
{
|
|
struct clk_pllv3 *pll = to_clk_pllv3(hw);
|
|
unsigned long min_rate = parent_rate * 54 / 2;
|
|
unsigned long max_rate = parent_rate * 108 / 2;
|
|
u32 val, div;
|
|
|
|
if (rate < min_rate || rate > max_rate)
|
|
return -EINVAL;
|
|
|
|
div = rate * 2 / parent_rate;
|
|
val = readl_relaxed(pll->base);
|
|
val &= ~pll->div_mask;
|
|
val |= div;
|
|
writel_relaxed(val, pll->base);
|
|
|
|
return clk_pllv3_wait_lock(pll);
|
|
}
|
|
|
|
static const struct clk_ops clk_pllv3_sys_ops = {
|
|
.prepare = clk_pllv3_prepare,
|
|
.unprepare = clk_pllv3_unprepare,
|
|
.is_prepared = clk_pllv3_is_prepared,
|
|
.recalc_rate = clk_pllv3_sys_recalc_rate,
|
|
.round_rate = clk_pllv3_sys_round_rate,
|
|
.set_rate = clk_pllv3_sys_set_rate,
|
|
};
|
|
|
|
static unsigned long clk_pllv3_av_recalc_rate(struct clk_hw *hw,
|
|
unsigned long parent_rate)
|
|
{
|
|
struct clk_pllv3 *pll = to_clk_pllv3(hw);
|
|
u32 mfn = readl_relaxed(pll->base + pll->num_offset);
|
|
u32 mfd = readl_relaxed(pll->base + pll->denom_offset);
|
|
u32 div = readl_relaxed(pll->base) & pll->div_mask;
|
|
u64 temp64 = (u64)parent_rate;
|
|
|
|
temp64 *= mfn;
|
|
do_div(temp64, mfd);
|
|
|
|
return parent_rate * div + (unsigned long)temp64;
|
|
}
|
|
|
|
static long clk_pllv3_av_round_rate(struct clk_hw *hw, unsigned long rate,
|
|
unsigned long *prate)
|
|
{
|
|
unsigned long parent_rate = *prate;
|
|
unsigned long min_rate = parent_rate * 27;
|
|
unsigned long max_rate = parent_rate * 54;
|
|
u32 div;
|
|
u32 mfn, mfd = 1000000;
|
|
u32 max_mfd = 0x3FFFFFFF;
|
|
u64 temp64;
|
|
|
|
if (rate > max_rate)
|
|
rate = max_rate;
|
|
else if (rate < min_rate)
|
|
rate = min_rate;
|
|
|
|
if (parent_rate <= max_mfd)
|
|
mfd = parent_rate;
|
|
|
|
div = rate / parent_rate;
|
|
temp64 = (u64) (rate - div * parent_rate);
|
|
temp64 *= mfd;
|
|
do_div(temp64, parent_rate);
|
|
mfn = temp64;
|
|
|
|
temp64 = (u64)parent_rate;
|
|
temp64 *= mfn;
|
|
do_div(temp64, mfd);
|
|
|
|
return parent_rate * div + (unsigned long)temp64;
|
|
}
|
|
|
|
static int clk_pllv3_av_set_rate(struct clk_hw *hw, unsigned long rate,
|
|
unsigned long parent_rate)
|
|
{
|
|
struct clk_pllv3 *pll = to_clk_pllv3(hw);
|
|
unsigned long min_rate = parent_rate * 27;
|
|
unsigned long max_rate = parent_rate * 54;
|
|
u32 val, div;
|
|
u32 mfn, mfd = 1000000;
|
|
u32 max_mfd = 0x3FFFFFFF;
|
|
u64 temp64;
|
|
|
|
if (rate < min_rate || rate > max_rate)
|
|
return -EINVAL;
|
|
|
|
if (parent_rate <= max_mfd)
|
|
mfd = parent_rate;
|
|
|
|
div = rate / parent_rate;
|
|
temp64 = (u64) (rate - div * parent_rate);
|
|
temp64 *= mfd;
|
|
do_div(temp64, parent_rate);
|
|
mfn = temp64;
|
|
|
|
val = readl_relaxed(pll->base);
|
|
val &= ~pll->div_mask;
|
|
val |= div;
|
|
writel_relaxed(val, pll->base);
|
|
writel_relaxed(mfn, pll->base + pll->num_offset);
|
|
writel_relaxed(mfd, pll->base + pll->denom_offset);
|
|
|
|
return clk_pllv3_wait_lock(pll);
|
|
}
|
|
|
|
static const struct clk_ops clk_pllv3_av_ops = {
|
|
.prepare = clk_pllv3_prepare,
|
|
.unprepare = clk_pllv3_unprepare,
|
|
.is_prepared = clk_pllv3_is_prepared,
|
|
.recalc_rate = clk_pllv3_av_recalc_rate,
|
|
.round_rate = clk_pllv3_av_round_rate,
|
|
.set_rate = clk_pllv3_av_set_rate,
|
|
};
|
|
|
|
struct clk_pllv3_vf610_mf {
|
|
u32 mfi; /* integer part, can be 20 or 22 */
|
|
u32 mfn; /* numerator, 30-bit value */
|
|
u32 mfd; /* denominator, 30-bit value, must be less than mfn */
|
|
};
|
|
|
|
static unsigned long clk_pllv3_vf610_mf_to_rate(unsigned long parent_rate,
|
|
struct clk_pllv3_vf610_mf mf)
|
|
{
|
|
u64 temp64;
|
|
|
|
temp64 = parent_rate;
|
|
temp64 *= mf.mfn;
|
|
do_div(temp64, mf.mfd);
|
|
|
|
return (parent_rate * mf.mfi) + temp64;
|
|
}
|
|
|
|
static struct clk_pllv3_vf610_mf clk_pllv3_vf610_rate_to_mf(
|
|
unsigned long parent_rate, unsigned long rate)
|
|
{
|
|
struct clk_pllv3_vf610_mf mf;
|
|
u64 temp64;
|
|
|
|
mf.mfi = (rate >= 22 * parent_rate) ? 22 : 20;
|
|
mf.mfd = 0x3fffffff; /* use max supported value for best accuracy */
|
|
|
|
if (rate <= parent_rate * mf.mfi)
|
|
mf.mfn = 0;
|
|
else if (rate >= parent_rate * (mf.mfi + 1))
|
|
mf.mfn = mf.mfd - 1;
|
|
else {
|
|
/* rate = parent_rate * (mfi + mfn/mfd) */
|
|
temp64 = rate - parent_rate * mf.mfi;
|
|
temp64 *= mf.mfd;
|
|
do_div(temp64, parent_rate);
|
|
mf.mfn = temp64;
|
|
}
|
|
|
|
return mf;
|
|
}
|
|
|
|
static unsigned long clk_pllv3_vf610_recalc_rate(struct clk_hw *hw,
|
|
unsigned long parent_rate)
|
|
{
|
|
struct clk_pllv3 *pll = to_clk_pllv3(hw);
|
|
struct clk_pllv3_vf610_mf mf;
|
|
|
|
mf.mfn = readl_relaxed(pll->base + pll->num_offset);
|
|
mf.mfd = readl_relaxed(pll->base + pll->denom_offset);
|
|
mf.mfi = (readl_relaxed(pll->base) & pll->div_mask) ? 22 : 20;
|
|
|
|
return clk_pllv3_vf610_mf_to_rate(parent_rate, mf);
|
|
}
|
|
|
|
static long clk_pllv3_vf610_round_rate(struct clk_hw *hw, unsigned long rate,
|
|
unsigned long *prate)
|
|
{
|
|
struct clk_pllv3_vf610_mf mf = clk_pllv3_vf610_rate_to_mf(*prate, rate);
|
|
|
|
return clk_pllv3_vf610_mf_to_rate(*prate, mf);
|
|
}
|
|
|
|
static int clk_pllv3_vf610_set_rate(struct clk_hw *hw, unsigned long rate,
|
|
unsigned long parent_rate)
|
|
{
|
|
struct clk_pllv3 *pll = to_clk_pllv3(hw);
|
|
struct clk_pllv3_vf610_mf mf =
|
|
clk_pllv3_vf610_rate_to_mf(parent_rate, rate);
|
|
u32 val;
|
|
|
|
val = readl_relaxed(pll->base);
|
|
if (mf.mfi == 20)
|
|
val &= ~pll->div_mask; /* clear bit for mfi=20 */
|
|
else
|
|
val |= pll->div_mask; /* set bit for mfi=22 */
|
|
writel_relaxed(val, pll->base);
|
|
|
|
writel_relaxed(mf.mfn, pll->base + pll->num_offset);
|
|
writel_relaxed(mf.mfd, pll->base + pll->denom_offset);
|
|
|
|
return clk_pllv3_wait_lock(pll);
|
|
}
|
|
|
|
static const struct clk_ops clk_pllv3_vf610_ops = {
|
|
.prepare = clk_pllv3_prepare,
|
|
.unprepare = clk_pllv3_unprepare,
|
|
.is_prepared = clk_pllv3_is_prepared,
|
|
.recalc_rate = clk_pllv3_vf610_recalc_rate,
|
|
.round_rate = clk_pllv3_vf610_round_rate,
|
|
.set_rate = clk_pllv3_vf610_set_rate,
|
|
};
|
|
|
|
static unsigned long clk_pllv3_enet_recalc_rate(struct clk_hw *hw,
|
|
unsigned long parent_rate)
|
|
{
|
|
struct clk_pllv3 *pll = to_clk_pllv3(hw);
|
|
|
|
return pll->ref_clock;
|
|
}
|
|
|
|
static const struct clk_ops clk_pllv3_enet_ops = {
|
|
.prepare = clk_pllv3_prepare,
|
|
.unprepare = clk_pllv3_unprepare,
|
|
.is_prepared = clk_pllv3_is_prepared,
|
|
.recalc_rate = clk_pllv3_enet_recalc_rate,
|
|
};
|
|
|
|
struct clk_hw *imx_clk_hw_pllv3(enum imx_pllv3_type type, const char *name,
|
|
const char *parent_name, void __iomem *base,
|
|
u32 div_mask)
|
|
{
|
|
struct clk_pllv3 *pll;
|
|
const struct clk_ops *ops;
|
|
struct clk_hw *hw;
|
|
struct clk_init_data init;
|
|
int ret;
|
|
|
|
pll = kzalloc(sizeof(*pll), GFP_KERNEL);
|
|
if (!pll)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
pll->power_bit = BM_PLL_POWER;
|
|
pll->num_offset = PLL_NUM_OFFSET;
|
|
pll->denom_offset = PLL_DENOM_OFFSET;
|
|
|
|
switch (type) {
|
|
case IMX_PLLV3_SYS:
|
|
ops = &clk_pllv3_sys_ops;
|
|
break;
|
|
case IMX_PLLV3_SYS_VF610:
|
|
ops = &clk_pllv3_vf610_ops;
|
|
pll->num_offset = PLL_VF610_NUM_OFFSET;
|
|
pll->denom_offset = PLL_VF610_DENOM_OFFSET;
|
|
break;
|
|
case IMX_PLLV3_USB_VF610:
|
|
pll->div_shift = 1;
|
|
/* fall through */
|
|
case IMX_PLLV3_USB:
|
|
ops = &clk_pllv3_ops;
|
|
pll->powerup_set = true;
|
|
break;
|
|
case IMX_PLLV3_AV_IMX7:
|
|
pll->num_offset = PLL_IMX7_NUM_OFFSET;
|
|
pll->denom_offset = PLL_IMX7_DENOM_OFFSET;
|
|
/* fall through */
|
|
case IMX_PLLV3_AV:
|
|
ops = &clk_pllv3_av_ops;
|
|
break;
|
|
case IMX_PLLV3_ENET_IMX7:
|
|
pll->power_bit = IMX7_ENET_PLL_POWER;
|
|
pll->ref_clock = 1000000000;
|
|
ops = &clk_pllv3_enet_ops;
|
|
break;
|
|
case IMX_PLLV3_ENET:
|
|
pll->ref_clock = 500000000;
|
|
ops = &clk_pllv3_enet_ops;
|
|
break;
|
|
case IMX_PLLV3_DDR_IMX7:
|
|
pll->power_bit = IMX7_DDR_PLL_POWER;
|
|
pll->num_offset = PLL_IMX7_NUM_OFFSET;
|
|
pll->denom_offset = PLL_IMX7_DENOM_OFFSET;
|
|
ops = &clk_pllv3_av_ops;
|
|
break;
|
|
default:
|
|
ops = &clk_pllv3_ops;
|
|
}
|
|
pll->base = base;
|
|
pll->div_mask = div_mask;
|
|
|
|
init.name = name;
|
|
init.ops = ops;
|
|
init.flags = 0;
|
|
init.parent_names = &parent_name;
|
|
init.num_parents = 1;
|
|
|
|
pll->hw.init = &init;
|
|
hw = &pll->hw;
|
|
|
|
ret = clk_hw_register(NULL, hw);
|
|
if (ret) {
|
|
kfree(pll);
|
|
return ERR_PTR(ret);
|
|
}
|
|
|
|
return hw;
|
|
}
|