forked from luck/tmp_suning_uos_patched
db865ee447
- Support for Xilinx Versal platform clks - Display clk controller on qcom sc7180 - Video clk controller on qcom sc7180 - Graphics clk controller on qcom sc7180 - CPU PLLs for qcom msm8916 - Fixes for clk controllers on qcom msm8998 SoCs - Move qcom msm8974 gfx3d clk to RPM control - Display port clk support on qcom sdm845 SoCs - Global clk controller on qcom ipq6018 - Adjust composite clk to new way of describing clk parents - Add a driver for BCLK of Freescale SAI cores * clk-imx: (32 commits) clk: imx: Add support for i.MX8MP clock driver dt-bindings: imx: Add clock binding doc for i.MX8MP clk: imx: gate4: Switch imx_clk_gate4_flags() to clk_hw based API clk: imx: imx8mq: Switch to clk_hw based API clk: imx: imx8mm: Switch to clk_hw based API clk: imx: imx8mn: Switch to clk_hw based API clk: imx: Remove __init for imx_obtain_fixed_clk_hw() API clk: imx: gate3: Switch to clk_hw based API clk: imx: add hw API imx_clk_hw_mux2_flags clk: imx: add imx_unregister_hw_clocks clk: imx: clk-composite-8m: Switch to clk_hw based API clk: imx: clk-pll14xx: Switch to clk_hw based API clk: imx7up: Rename the clks to hws clk: imx: Rename the imx_clk_divider_gate to imply it's clk_hw based clk: imx: Rename the imx_clk_pfdv2 to imply it's clk_hw based clk: imx: Rename the imx_clk_pllv4 to imply it's clk_hw based clk: imx: Rename sccg and frac pll register to suggest clk_hw clk: imx: imx7ulp composite: Rename to show is clk_hw based clk: imx: pllv2: Switch to clk_hw based API clk: imx: pllv1: Switch to clk_hw based API ... * clk-ti: clk: ti: clkctrl: Fix hidden dependency to node name clk: ti: add clkctrl data dra7 sgx clk: ti: omap5: Add missing AESS clock clk: ti: dra7: fix parent for gmac_clkctrl clk: ti: dra7: add vpe clkctrl data clk: ti: dra7: add cam clkctrl data dt-bindings: clock: Move ti-dra7-atl.h to dt-bindings/clock * clk-xilinx: clk: zynqmp: Add support for clock with CLK_DIVIDER_POWER_OF_TWO flag clk: zynqmp: Fix divider calculation clk: zynqmp: Add support for get max divider clk: zynqmp: Warn user if clock user are more than allowed clk: zynqmp: Extend driver for versal dt-bindings: clock: Add bindings for versal clock driver * clk-nvidia: clk: tegra20/30: Explicitly set parent clock for Video Decoder clk: tegra20/30: Don't pre-initialize displays parent clock clk: tegra: divider: Check UART's divider enable-bit state on rate's recalculation clk: tegra: clk-dfll: Remove call to pm_runtime_irq_safe() clk: tegra: Mark fuse clock as critical * clk-qcom: (35 commits) clk: qcom: rpmh: Sort OF match table dt-bindings: fix warnings in validation of qcom,gcc.yaml dt-binding: fix compilation error of the example in qcom,gcc.yaml clk: qcom: Add ipq6018 Global Clock Controller support clk: qcom: Add DT bindings for ipq6018 gcc clock controller clk: qcom: gcc-msm8996: Fix parent for CLKREF clocks clk: qcom: rpmh: Add IPA clock for SC7180 clk: qcom: rpmh: skip undefined clocks when registering clk: qcom: Add video clock controller driver for SC7180 dt-bindings: clock: Introduce SC7180 QCOM Video clock bindings dt-bindings: clock: Add YAML schemas for the QCOM VIDEOCC clock bindings clk: qcom: Add graphics clock controller driver for SC7180 dt-bindings: clock: Introduce SC7180 QCOM Graphics clock bindings dt-bindings: clock: Add YAML schemas for the QCOM GPUCC clock bindings clk: qcom: apcs-msm8916: use clk_parent_data to specify the parent clk: qcom: Add display clock controller driver for SC7180 dt-bindings: clock: Introduce QCOM sc7180 display clock bindings dt-bindings: clock: Add YAML schemas for the QCOM DISPCC clock bindings clk: qcom: clk-alpha-pll: Add support for Fabia PLL calibration clk: qcom: alpha-pll: Remove useless read from set rate ... * clk-freescale: clk: fsl-sai: new driver dt-bindings: clock: document the fsl-sai driver clk: composite: add _register_composite_pdata() variants * clk-qoriq: clk: qoriq: add ls1088a hwaccel clocks support clk: ls1028a: Add clock driver for Display output interface dt/bindings: clk: Add YAML schemas for LS1028A Display Clock bindings
182 lines
4.1 KiB
C
182 lines
4.1 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Copyright 2018 NXP
|
|
*/
|
|
|
|
#include <linux/clk-provider.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/io.h>
|
|
#include <linux/slab.h>
|
|
|
|
#include "clk.h"
|
|
|
|
#define PCG_PREDIV_SHIFT 16
|
|
#define PCG_PREDIV_WIDTH 3
|
|
#define PCG_PREDIV_MAX 8
|
|
|
|
#define PCG_DIV_SHIFT 0
|
|
#define PCG_DIV_WIDTH 6
|
|
#define PCG_DIV_MAX 64
|
|
|
|
#define PCG_PCS_SHIFT 24
|
|
#define PCG_PCS_MASK 0x7
|
|
|
|
#define PCG_CGC_SHIFT 28
|
|
|
|
static unsigned long imx8m_clk_composite_divider_recalc_rate(struct clk_hw *hw,
|
|
unsigned long parent_rate)
|
|
{
|
|
struct clk_divider *divider = to_clk_divider(hw);
|
|
unsigned long prediv_rate;
|
|
unsigned int prediv_value;
|
|
unsigned int div_value;
|
|
|
|
prediv_value = readl(divider->reg) >> divider->shift;
|
|
prediv_value &= clk_div_mask(divider->width);
|
|
|
|
prediv_rate = divider_recalc_rate(hw, parent_rate, prediv_value,
|
|
NULL, divider->flags,
|
|
divider->width);
|
|
|
|
div_value = readl(divider->reg) >> PCG_DIV_SHIFT;
|
|
div_value &= clk_div_mask(PCG_DIV_WIDTH);
|
|
|
|
return divider_recalc_rate(hw, prediv_rate, div_value, NULL,
|
|
divider->flags, PCG_DIV_WIDTH);
|
|
}
|
|
|
|
static int imx8m_clk_composite_compute_dividers(unsigned long rate,
|
|
unsigned long parent_rate,
|
|
int *prediv, int *postdiv)
|
|
{
|
|
int div1, div2;
|
|
int error = INT_MAX;
|
|
int ret = -EINVAL;
|
|
|
|
*prediv = 1;
|
|
*postdiv = 1;
|
|
|
|
for (div1 = 1; div1 <= PCG_PREDIV_MAX; div1++) {
|
|
for (div2 = 1; div2 <= PCG_DIV_MAX; div2++) {
|
|
int new_error = ((parent_rate / div1) / div2) - rate;
|
|
|
|
if (abs(new_error) < abs(error)) {
|
|
*prediv = div1;
|
|
*postdiv = div2;
|
|
error = new_error;
|
|
ret = 0;
|
|
}
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
static long imx8m_clk_composite_divider_round_rate(struct clk_hw *hw,
|
|
unsigned long rate,
|
|
unsigned long *prate)
|
|
{
|
|
int prediv_value;
|
|
int div_value;
|
|
|
|
imx8m_clk_composite_compute_dividers(rate, *prate,
|
|
&prediv_value, &div_value);
|
|
rate = DIV_ROUND_UP(*prate, prediv_value);
|
|
|
|
return DIV_ROUND_UP(rate, div_value);
|
|
|
|
}
|
|
|
|
static int imx8m_clk_composite_divider_set_rate(struct clk_hw *hw,
|
|
unsigned long rate,
|
|
unsigned long parent_rate)
|
|
{
|
|
struct clk_divider *divider = to_clk_divider(hw);
|
|
unsigned long flags = 0;
|
|
int prediv_value;
|
|
int div_value;
|
|
int ret;
|
|
u32 val;
|
|
|
|
ret = imx8m_clk_composite_compute_dividers(rate, parent_rate,
|
|
&prediv_value, &div_value);
|
|
if (ret)
|
|
return -EINVAL;
|
|
|
|
spin_lock_irqsave(divider->lock, flags);
|
|
|
|
val = readl(divider->reg);
|
|
val &= ~((clk_div_mask(divider->width) << divider->shift) |
|
|
(clk_div_mask(PCG_DIV_WIDTH) << PCG_DIV_SHIFT));
|
|
|
|
val |= (u32)(prediv_value - 1) << divider->shift;
|
|
val |= (u32)(div_value - 1) << PCG_DIV_SHIFT;
|
|
writel(val, divider->reg);
|
|
|
|
spin_unlock_irqrestore(divider->lock, flags);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static const struct clk_ops imx8m_clk_composite_divider_ops = {
|
|
.recalc_rate = imx8m_clk_composite_divider_recalc_rate,
|
|
.round_rate = imx8m_clk_composite_divider_round_rate,
|
|
.set_rate = imx8m_clk_composite_divider_set_rate,
|
|
};
|
|
|
|
struct clk_hw *imx8m_clk_hw_composite_flags(const char *name,
|
|
const char * const *parent_names,
|
|
int num_parents, void __iomem *reg,
|
|
unsigned long flags)
|
|
{
|
|
struct clk_hw *hw = ERR_PTR(-ENOMEM), *mux_hw;
|
|
struct clk_hw *div_hw, *gate_hw;
|
|
struct clk_divider *div = NULL;
|
|
struct clk_gate *gate = NULL;
|
|
struct clk_mux *mux = NULL;
|
|
|
|
mux = kzalloc(sizeof(*mux), GFP_KERNEL);
|
|
if (!mux)
|
|
goto fail;
|
|
|
|
mux_hw = &mux->hw;
|
|
mux->reg = reg;
|
|
mux->shift = PCG_PCS_SHIFT;
|
|
mux->mask = PCG_PCS_MASK;
|
|
mux->lock = &imx_ccm_lock;
|
|
|
|
div = kzalloc(sizeof(*div), GFP_KERNEL);
|
|
if (!div)
|
|
goto fail;
|
|
|
|
div_hw = &div->hw;
|
|
div->reg = reg;
|
|
div->shift = PCG_PREDIV_SHIFT;
|
|
div->width = PCG_PREDIV_WIDTH;
|
|
div->lock = &imx_ccm_lock;
|
|
div->flags = CLK_DIVIDER_ROUND_CLOSEST;
|
|
|
|
gate = kzalloc(sizeof(*gate), GFP_KERNEL);
|
|
if (!gate)
|
|
goto fail;
|
|
|
|
gate_hw = &gate->hw;
|
|
gate->reg = reg;
|
|
gate->bit_idx = PCG_CGC_SHIFT;
|
|
gate->lock = &imx_ccm_lock;
|
|
|
|
hw = clk_hw_register_composite(NULL, name, parent_names, num_parents,
|
|
mux_hw, &clk_mux_ops, div_hw,
|
|
&imx8m_clk_composite_divider_ops,
|
|
gate_hw, &clk_gate_ops, flags);
|
|
if (IS_ERR(hw))
|
|
goto fail;
|
|
|
|
return hw;
|
|
|
|
fail:
|
|
kfree(gate);
|
|
kfree(div);
|
|
kfree(mux);
|
|
return ERR_CAST(hw);
|
|
}
|