dt/bindings: clk: Add YAML schemas for LS1028A Display Clock bindings
Subsystems (2)
PATCH v4 1/2 dt/bindings: clk: Add YAML schemas for LS1028A Display Clock bindings
LS1028A has a clock domain PXLCLK0 used for provide pixel clocks to Display output interface. Add a YAML schema for this.
--- .../devicetree/bindings/clock/fsl,plldig.yaml | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/fsl,plldig.yaml
Documentation/devicetree/bindings/clock/fsl,plldig.yaml new file +43 -0
@@ -0,0 +1,43 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/bindings/clock/fsl,plldig.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NXP QorIQ Layerscape LS1028A Display PIXEL Clock Binding + +maintainers: + - Wen He <[email protected]> + +description: | + NXP LS1028A has a clock domain PXLCLK0 used for the Display output + interface in the display core, as implemented in TSMC CLN28HPM PLL. + which generate and offers pixel clocks to Display. + +properties: + compatible: + const: fsl,ls1028a-plldig + + reg: + maxItems: 1 + + '#clock-cells': + const: 0 + +required: + - compatible + - reg + - clocks + - '#clock-cells' + +examples: + # Display PIXEL Clock node: + - | + dpclk: clock-display@f1f0000 { + compatible = "fsl,ls1028a-plldig"; + reg = <0x0 0xf1f0000 0x0 0xffff>; + #clock-cells = <0>; + clocks = <&osc_27m>; + }; + +...
Signature · 1 line
2.17.1
PATCH v4 2/2 clk: ls1028a: Add clock driver for Display output interface
Add clock driver for QorIQ LS1028A Display output interfaces(LCD, DPHY), as implemented in TSMC CLN28HPM PLL, this PLL supports the programmable integer division and range of the display output pixel clock's 27-594MHz.
---
change in v4:
- correction some code according the Stephen comments.
- update calc algorithm.
drivers/clk/Kconfig | 10 ++ drivers/clk/Makefile | 1 + drivers/clk/clk-plldig.c | 298 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 309 insertions(+) create mode 100644 drivers/clk/clk-plldig.c
drivers/clk/Kconfig +10 -0
@@ -223,6 +223,16 @@ config CLK_QORIQ This adds the clock driver support for Freescale QorIQ platforms using common clock framework. +config CLK_LS1028A_PLLDIG + bool "Clock driver for LS1028A Display output" + depends on ARCH_LAYERSCAPE || COMPILE_TEST + default ARCH_LAYERSCAPE + help + This driver support the Display output interfaces(LCD, DPHY) pixel clocks + of the QorIQ Layerscape LS1028A, as implemented TSMC CLN28HPM PLL. Not all + features of the PLL are currently supported by the driver. By default, + configured bypass mode with this PLL. + config COMMON_CLK_XGENE bool "Clock driver for APM XGene SoC" default ARCH_XGENE
drivers/clk/Makefile +1 -0
@@ -44,6 +44,7 @@ obj-$(CONFIG_COMMON_CLK_OXNAS) += clk-oxnas.o obj-$(CONFIG_COMMON_CLK_PALMAS) += clk-palmas.o obj-$(CONFIG_COMMON_CLK_PWM) += clk-pwm.o obj-$(CONFIG_CLK_QORIQ) += clk-qoriq.o +obj-$(CONFIG_CLK_LS1028A_PLLDIG) += clk-plldig.o obj-$(CONFIG_COMMON_CLK_RK808) += clk-rk808.o obj-$(CONFIG_COMMON_CLK_HI655X) += clk-hi655x.o obj-$(CONFIG_COMMON_CLK_S2MPS11) += clk-s2mps11.o
drivers/clk/clk-plldig.c new file +298 -0
298 lines not on this page · raw message
Signature · 1 line
2.17.1
Stephen Boyd
maintainerRe: [v4 2/2] clk: ls1028a: Add clock driver for Display output interface
Quoting Wen He (2019-08-29 03:59:19)
drivers/clk/Kconfig config CLK_QORIQ · line 227
Quoted 10 lines
drivers/clk/Kconfig +2
-0@@ -223,6 +223,16 @@ config CLK_QORIQ This adds the clock driver support for Freescale QorIQ platforms using common clock framework. +config CLK_LS1028A_PLLDIG + bool "Clock driver for LS1028A Display output"
Is this a tristate? The driver is made to be a module but it isn't allowed to be compiled as such.
Quoted 42 lines
drivers/clk/Kconfig +8
-0+ depends on ARCH_LAYERSCAPE || COMPILE_TEST + default ARCH_LAYERSCAPE + help + This driver support the Display output interfaces(LCD, DPHY) pixel clocks + of the QorIQ Layerscape LS1028A, as implemented TSMC CLN28HPM PLL. Not all + features of the PLL are currently supported by the driver. By default, + configured bypass mode with this PLL. + config COMMON_CLK_XGENE bool "Clock driver for APM XGene SoC" default ARCH_XGENEdrivers/clk/clk-plldig.c new file +25
-0@@ -0,0 +1,298 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2019 NXP +* +* Clock driver for LS1028A Display output interfaces(LCD, DPHY). +*/ + +#include <linux/clk-provider.h> +#include <linux/device.h> +#include <linux/module.h> +#include <linux/err.h> +#include <linux/io.h> +#include <linux/iopoll.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/slab.h> + +/* PLLDIG register offsets and bit masks */ +#define PLLDIG_REG_PLLSR 0x24 +#define PLLDIG_REG_PLLDV 0x28 +#define PLLDIG_REG_PLLFM 0x2c +#define PLLDIG_REG_PLLFD 0x30 +#define PLLDIG_REG_PLLCAL1 0x38
drivers/clk/clk-plldig.c line 35
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+#define PLLDIG_REG_PLLCAL2 0x3c +#define PLLDIG_LOCK_MASK BIT(2) +#define PLLDIG_SSCGBYP_ENABLE BIT(30) +#define PLLDIG_FDEN BIT(30) +#define PLLDIG_DTHRCTL (0x3 << 16) + +/* macro to get/set values into register */ +#define PLLDIG_GET_MULT (x) (((x) & ~(0xffffff00)) << 0) +#define PLLDIG_GET_RFDPHI1 (x) ((u32)(x) >> 25) +#define PLLDIG_SET_RFDPHI1 (x) ((u32)(x) << 25)
Maybe you can use the FIELD_GET() APIs and genmask from bitfield.h?
Quoted 13 lines
drivers/clk/clk-plldig.c new file +13
-0+ +/* Maximum of the divider */ +#define MAX_RFDPHI1 63 + +/* Best value of multiplication factor divider */ +#define PLLDIG_DEFAULE_MULT 44 + +/* +* Clock configuration relationship between the PHI1 frequency(fpll_phi) and +* the output frequency of the PLL is determined by the PLLDV, according to +* the following equation: +* fpll_phi = (pll_ref * mfd) / div_rfdphi1 +*/
drivers/clk/clk-plldig.c line 58
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+struct plldig_phi1_param { +unsigned long rate; +unsigned int rfdphi1; +unsigned int mfd; +}; + +enum plldig_phi1_freq_range { +PHI1_MIN =27000000U , +PHI1_MAX =600000000U +};
Please just inline these values in the one place they're used.
drivers/clk/clk-plldig.c line 63
Quoted 5 lines
drivers/clk/clk-plldig.c new file +5
-0+ +struct clk_plldig { +struct clk_hw hw; +void __iomem *regs; +struct device *dev;
Please remove this, it is unused.
drivers/clk/clk-plldig.c line 67
Quoted 4 lines
drivers/clk/clk-plldig.c new file +4
-0+}; + +#define to_clk_plldig (_hw) container_of(_hw, struct clk_plldig, hw) +#define LOCK_TIMEOUT_US USEC_PER_MSEC
Is this used?
Quoted 73 lines
drivers/clk/clk-plldig.c new file +73
-0+ +static int plldig_enable (struct clk_hw *hw) +{ +struct clk_plldig *data =to_clk_plldig (hw); +u32 val; + + val =readl (data->regs +PLLDIG_REG_PLLFM ); +/* +* Use Bypass mode with PLL off by default, the frequency overshoot +* detector output was disable. SSCG Bypass mode should be enable. +*/ + val |=PLLDIG_SSCGBYP_ENABLE ; +writel (val, data->regs +PLLDIG_REG_PLLFM ); + + val =readl (data->regs +PLLDIG_REG_PLLFD ); +/* Disable dither and Sigma delta modulation in bypass mode */ + val |= (PLLDIG_FDEN |PLLDIG_DTHRCTL ); +writel (val, data->regs +PLLDIG_REG_PLLFD ); + +return 0 ; +} + +static void plldig_disable (struct clk_hw *hw) +{ +struct clk_plldig *data =to_clk_plldig (hw); +u32 val; + + val =readl (data->regs +PLLDIG_REG_PLLFM ); + + val &= ~PLLDIG_SSCGBYP_ENABLE ; +writel (val, data->regs +PLLDIG_REG_PLLFM ); +} + +static int plldig_is_enabled (struct clk_hw *hw) +{ +struct clk_plldig *data =to_clk_plldig (hw); + +return (readl (data->regs +PLLDIG_REG_PLLFM ) &PLLDIG_SSCGBYP_ENABLE ); +} + +static unsigned long plldig_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +struct clk_plldig *data =to_clk_plldig (hw); +u32 mult, div, val; + + val =readl (data->regs +PLLDIG_REG_PLLDV ); + +/* Check if PLL is bypassed */ +if (val &PLLDIG_SSCGBYP_ENABLE ) +return parent_rate; + +/* Checkout multiplication factor divider value */ + mult = val; + mult =PLLDIG_GET_MULT (mult); + +/* Checkout divider value of the output frequency */ + div = val; + div =PLLDIG_GET_RFDPHI1 (div); + +return (parent_rate * mult) / div; +} + +static int plldig_calc_target_rate (unsigned long target_rate, +unsigned long parent_rate, +struct plldig_phi1_param *phi1_out) +{ +unsigned int div, mfd, ret; +unsigned long round_rate; + +/* +* Firstly, check the target rate whether is divisible +* by the best VCO frequency.
drivers/clk/clk-plldig.c line 150
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+*/ + mfd =PLLDIG_DEFAULE_MULT ; + round_rate = parent_rate * mfd; + div = round_rate / target_rate; +if (!div || div >MAX_RFDPHI1 ) +return -EINVAL ; + + ret = round_rate % target_rate; +if (!ret) + goto out;
Please get rid of ret and do the test here directly and then put the below code into the if statement to remove the goto.
if (round_rate % target_rate) {
/*
* Otherwise, try a rounding algorithm to driven the target rate,
* this algorithm allows tolerances between the target rate and
* real rate, it based on the best VCO output frequency.
*/
mfd = PLLDIG_DEFAULE_MULT;
round_rate = parent_rate * mfd;
/*
* Add half of the target rate so the result will be
* rounded to cloeset instead of rounded down.
*/
round_rate += (target_rate / 2);
div = round_rate / target_rate;
if (!div || div > MAX_RFDPHI1)
return -EINVAL;
}Quoted 7 lines
drivers/clk/clk-plldig.c new file +7
-0+ phi1_out->rfdphi1 =PLLDIG_SET_RFDPHI1 (div); + phi1_out->mfd = mfd; + phi1_out->rate = target_rate; + +return 0 ; +} +
drivers/clk/clk-plldig.c line 186
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+static int plldig_determine_rate (struct clk_hw *hw, +struct clk_rate_request *req) +{ +int ret; +struct clk_hw *parent; +struct plldig_phi1_param phi1_param; +unsigned long parent_rate; + +if (req->rate ==0 || req->rate <PHI1_MIN || req->rate >PHI1_MAX ) +return -EINVAL ;
Preferably you clamp the requested rate to min/max instead of just returning a failure. That way the clk_set_rate() API "works" by trying to achieve some frequency that is there. You'll have to look at the request that is passed into this function to make sure that the min/max of the request is within the range this clk supports, but it will be better than just blindly returning a failure because this function should try to round the rate to something that is supported.
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+ + parent =clk_hw_get_parent (hw); + parent_rate =clk_hw_get_rate (parent); + + ret =plldig_calc_target_rate (req->rate, parent_rate, &phi1_param); +if (ret) +return ret; + + req->rate = phi1_param.rate; +
drivers/clk/clk-plldig.c line 206
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+return 0 ; +} + +static int plldig_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) +{ +struct clk_plldig *data =to_clk_plldig (hw); +struct plldig_phi1_param phi1_param; +unsigned int rfdphi1, val, cond; +int ret = -ETIMEDOUT ;
Drop this initial assignment please.
drivers/clk/clk-plldig.c line 210
Quoted 4 lines
drivers/clk/clk-plldig.c new file +4
-0+ + ret =plldig_calc_target_rate (rate, parent_rate, &phi1_param); +if (ret) +return ret;
Because it's overwritten immediately.
Quoted 7 lines
drivers/clk/clk-plldig.c new file +7
-0+ + val =readl (data->regs +PLLDIG_REG_PLLDV ); + val = phi1_param.mfd; + rfdphi1 = phi1_param.rfdphi1; + val |= rfdphi1; + +writel (val, data->regs +PLLDIG_REG_PLLDV );
drivers/clk/clk-plldig.c line 227
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+ +/* delay 200us make sure that old lock state is cleared */ +udelay (200 ); + +/* Wait until PLL is locked or timeout (maximum 1000 usecs) */ + ret =readl_poll_timeout_atomic (data->regs +PLLDIG_REG_PLLSR , cond, + cond &PLLDIG_LOCK_MASK ,0 , +USEC_PER_MSEC ); + +return ret;
Just return readl_poll_timeout_atomic(...) here.
Quoted 8 lines
drivers/clk/clk-plldig.c new file +8
-0+} + +static const struct clk_ops plldig_clk_ops = { + .enable = plldig_enable, + .disable = plldig_disable, + .is_enabled = plldig_is_enabled, + .recalc_rate = plldig_recalc_rate, + .determine_rate = plldig_determine_rate,
drivers/clk/clk-plldig.c line 245
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+ .set_rate = plldig_set_rate, +}; + +static int plldig_clk_probe (struct platform_device *pdev) +{ +struct clk_plldig *data; +struct resource *mem; +struct clk_init_data init = {}; +struct device *dev = &pdev->dev; +struct clk_parent_data parent_data;
Set this to = { .index = 0 }
drivers/clk/clk-plldig.c line 258
Quoted 13 lines
drivers/clk/clk-plldig.c new file +13
-0+int ret; + + data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + data->regs =devm_ioremap_resource (dev, mem); +if (IS_ERR (data->regs)) +return PTR_ERR (data->regs); + + parent_data.name =of_clk_get_parent_name (dev->of_node,0 ); + parent_data.index =0 ;
And don't assign these.
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+ + init.name = dev->of_node->name; + init.ops = &plldig_clk_ops; + init.parent_data = &parent_data; + init.num_parents =1 ; + + data->hw.init = &init; + data->dev = dev; + + ret =devm_clk_hw_register (dev, &data->hw);
drivers/clk/clk-plldig.c line 278
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+if (ret) { +dev_err (dev,"failed to register %s clock\n" , init.name); +return ret; + } + + ret =devm_of_clk_add_hw_provider (dev, of_clk_hw_simple_get, &data->hw); +if (ret) +dev_err (dev,"failed adding the clock provider\n" ); + +return ret;
I'd prefer to just see return devm_of_clk_add_hw_provider(), but not a big deal.
RE: [EXT] Re: [v4 2/2] clk: ls1028a: Add clock driver for Display output interface
Quoted 78 lines
-----Original Message-----
From: Stephen Boyd <[email protected]>
Sent: 2019年9月17日 4:27
To: Mark Rutland <[email protected]>; Michael Turquette <[email protected]>; Rob Herring <[email protected]>; Wen He <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Leo Li <[email protected]>; [email protected]; Wen He <[email protected]>
Subject: [EXT] Re: [v4 2/2] clk: ls1028a: Add clock driver for Display output interfaceQuoting Wen He (2019-08-29 03:59:19)
drivers/clk/Kconfig config CLK_QORIQ · line 227
Quoted 10 lines
drivers/clk/Kconfig index renamed from drivers/clk/Kconfig +0
-0
801fa1cd0321..ab05f342af04100644drivers/clk/Kconfig +2
-0@@ -223,6 +223,16 @@ config CLK_QORIQ This adds the clock driver support for Freescale QorIQ platforms using common clock framework. +config CLK_LS1028A_PLLDIG + bool "Clock driver for LS1028A Display output"Is this a tristate? The driver is made to be a module but it isn't allowed to be compiled as such.
drivers/clk/Kconfig config CLK_QORIQ
Quoted 4 lines
drivers/clk/Kconfig +4
-0+ depends on ARCH_LAYERSCAPE || COMPILE_TEST + default ARCH_LAYERSCAPE + help + This driver support the Display output interfaces(LCD, DPHY)pixel clocks
drivers/clk/Kconfig config CLK_QORIQ · line 232
Quoted 1 line
drivers/clk/Kconfig +1
-0+ of the QorIQ Layerscape LS1028A, as implemented TSMCCLN28HPM PLL. Not all
drivers/clk/Kconfig config CLK_QORIQ · line 233
Quoted 1 line
drivers/clk/Kconfig +1
-0+ features of the PLL are currently supported by the driver. Bydefault,
Quoted 39 lines
drivers/clk/Kconfig +2
-0+ configured bypass mode with this PLL. + config COMMON_CLK_XGENE bool "Clock driver for APM XGene SoC" default ARCH_XGENEdrivers/clk/clk-plldig.c new renamed from drivers/clk/clk-plldig.c +0
-0file mode 100644 index 000000000000..d3239bcf59de
drivers/clk/clk-plldig.c new file +29
-0@@ -0,0 +1,298 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2019 NXP +* +* Clock driver for LS1028A Display output interfaces(LCD, DPHY). +*/ + +#include <linux/clk-provider.h> +#include <linux/device.h> +#include <linux/module.h> +#include <linux/err.h> +#include <linux/io.h> +#include <linux/iopoll.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/slab.h> + +/* PLLDIG register offsets and bit masks */ +#define PLLDIG_REG_PLLSR 0x24 +#define PLLDIG_REG_PLLDV 0x28 +#define PLLDIG_REG_PLLFM 0x2c +#define PLLDIG_REG_PLLFD 0x30 +#define PLLDIG_REG_PLLCAL1 0x38 +#define PLLDIG_REG_PLLCAL2 0x3c +#define PLLDIG_LOCK_MASK BIT(2) +#define PLLDIG_SSCGBYP_ENABLE BIT(30) +#define PLLDIG_FDEN BIT(30)
Quoted 8 lines
drivers/clk/clk-plldig.c line 35
Quoted 6 lines
drivers/clk/clk-plldig.c new file +6
-0+#define PLLDIG_DTHRCTL (0x3 << 16) + +/* macro to get/set values into register */ +#define PLLDIG_GET_MULT (x) (((x) & ~(0xffffff00)) << 0) +#define PLLDIG_GET_RFDPHI1 (x) ((u32)(x) >> 25) +#define PLLDIG_SET_RFDPHI1 (x) ((u32)(x) << 25)Maybe you can use the
FIELD_GET()APIs and genmask frombitfield.h?
Hmm, that a good idea.
Quoted 28 lines
Quoted 15 lines
drivers/clk/clk-plldig.c new file +14
-0+ +/* Maximum of the divider */ +#define MAX_RFDPHI1 63 + +/* Best value of multiplication factor divider */ +#define PLLDIG_DEFAULE_MULT 44 + +/* +* Clock configuration relationship between the PHI1 +frequency(fpll_phi) and +* the output frequency of the PLL is determined by the PLLDV, +according to +* the following equation: + * fpll_phi = (pll_ref * mfd) / div_rfdphi1 */ structdrivers/clk/clk-plldig.c line 58
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+plldig_phi1_param { +unsigned long rate; +unsigned int rfdphi1; +unsigned int mfd; +}; + +enum plldig_phi1_freq_range { +PHI1_MIN =27000000U , +PHI1_MAX =600000000U +};Please just inline these values in the one place they're used.
Quoted 7 lines
drivers/clk/clk-plldig.c line 63
Quoted 5 lines
drivers/clk/clk-plldig.c new file +5
-0+ +struct clk_plldig { +struct clk_hw hw; +void __iomem *regs; +struct device *dev;Please remove this, it is unused.
It is used for probe.
Quoted 7 lines
drivers/clk/clk-plldig.c line 67
Quoted 5 lines
drivers/clk/clk-plldig.c new file +4
-0+}; + +#define to_clk_plldig (_hw) container_of(_hw, struct clk_plldig, hw) +#define LOCK_TIMEOUT_US USEC_PER_MSECIs this used?
Yes, it is used.
Quoted 76 lines
drivers/clk/clk-plldig.c
Quoted 9 lines
drivers/clk/clk-plldig.c new file +8
-0+ +static int plldig_enable (struct clk_hw *hw) { +struct clk_plldig *data =to_clk_plldig (hw); +u32 val; + + val =readl (data->regs +PLLDIG_REG_PLLFM ); +/* +* Use Bypass mode with PLL off by default, the frequency overshoot
drivers/clk/clk-plldig.c line 77
Quoted 1 line
drivers/clk/clk-plldig.c new file +1
-0+* detector output was disable. SSCG Bypass mode should be enable.
Quoted 41 lines
drivers/clk/clk-plldig.c new file +41
-0+*/ + val |=PLLDIG_SSCGBYP_ENABLE ; +writel (val, data->regs +PLLDIG_REG_PLLFM ); + + val =readl (data->regs +PLLDIG_REG_PLLFD ); +/* Disable dither and Sigma delta modulation in bypass mode */ + val |= (PLLDIG_FDEN |PLLDIG_DTHRCTL ); +writel (val, data->regs +PLLDIG_REG_PLLFD ); + +return 0 ; +} + +static void plldig_disable (struct clk_hw *hw) { +struct clk_plldig *data =to_clk_plldig (hw); +u32 val; + + val =readl (data->regs +PLLDIG_REG_PLLFM ); + + val &= ~PLLDIG_SSCGBYP_ENABLE ; +writel (val, data->regs +PLLDIG_REG_PLLFM ); } + +static int plldig_is_enabled (struct clk_hw *hw) { +struct clk_plldig *data =to_clk_plldig (hw); + +return (readl (data->regs +PLLDIG_REG_PLLFM ) & +PLLDIG_SSCGBYP_ENABLE ); } + +static unsigned long plldig_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) { +struct clk_plldig *data =to_clk_plldig (hw); +u32 mult, div, val; + + val =readl (data->regs +PLLDIG_REG_PLLDV ); + +/* Check if PLL is bypassed */ +if (val &PLLDIG_SSCGBYP_ENABLE ) +return parent_rate; + +/* Checkout multiplication factor divider value */ + mult = val; + mult =PLLDIG_GET_MULT (mult);drivers/clk/clk-plldig.c
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+ +/* Checkout divider value of the output frequency */ + div = val; + div =PLLDIG_GET_RFDPHI1 (div); + +return (parent_rate * mult) / div; } + +static int plldig_calc_target_rate (unsigned long target_rate, +unsigned long parent_rate, + struct plldig_phi1_param
*phi1_out)Quoted 12 lines
drivers/clk/clk-plldig.c new file +12
-0+{ +unsigned int div, mfd, ret; +unsigned long round_rate; + +/* +* Firstly, check the target rate whether is divisible +* by the best VCO frequency. +*/ + mfd =PLLDIG_DEFAULE_MULT ; + round_rate = parent_rate * mfd; + div = round_rate / target_rate; +if (!div || div >MAX_RFDPHI1 )
Quoted 8 lines
drivers/clk/clk-plldig.c line 150
Quoted 5 lines
drivers/clk/clk-plldig.c new file +5
-0+return -EINVAL ; + + ret = round_rate % target_rate; +if (!ret) + goto out;Please get rid of ret and do the test here directly and then put the below code into the if statement to remove the goto.
Here provide two condition to test the request target rate whether meet.
1. always check the request rate whether is divisible by the VCO frequency.
2. If option#1 is not meet, trying to rounding.
Option#1 and option#2 both need use the below code, if remove the goto, will see the duplicate code statement.
Quoted 42 lines
if (round_rate % target_rate) { /* * Otherwise, try a rounding algorithm to driven the target rate, * this algorithm allows tolerances between the target rate and * real rate, it based on the best VCO output frequency. */ mfd = PLLDIG_DEFAULE_MULT; round_rate = parent_rate * mfd; /* * Add half of the target rate so the result will be * rounded to cloeset instead of rounded down. */ round_rate += (target_rate / 2); div = round_rate / target_rate; if (!div || div > MAX_RFDPHI1) return -EINVAL; }Quoted 5 lines
drivers/clk/clk-plldig.c new file +5
-0+ phi1_out->rfdphi1 =PLLDIG_SET_RFDPHI1 (div); + phi1_out->mfd = mfd; + phi1_out->rate = target_rate; + +return 0 ;drivers/clk/clk-plldig.c
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+} + +static int plldig_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) { + int ret; + struct clk_hw *parent; + struct plldig_phi1_param phi1_param; + unsigned long parent_rate; + + if (req->rate == 0 || req->rate < PHI1_MIN || req->rate >
PHI1_MAX)drivers/clk/clk-plldig.c line 161
Quoted 1 line
drivers/clk/clk-plldig.c new file +1
-0+return -EINVAL ;
Quoted 7 lines
Preferably you clamp the requested rate to min/max instead of just returning a failure. That way the
clk_set_rate()API "works" by trying to achieve some frequency that is there. You'll have to look at the request that is passed into this function to make sure that the min/max of the request is within the range this clk supports, but it will be better than just blindly returning a failure because this function should try to round the rate to something that is supported.
I agree with you.
Quoted 44 lines
Quoted 10 lines
drivers/clk/clk-plldig.c new file +9
-0+ + parent =clk_hw_get_parent (hw); + parent_rate =clk_hw_get_rate (parent); + + ret =plldig_calc_target_rate (req->rate, parent_rate, &phi1_param); +if (ret) +return ret; + + req->rate = phi1_param.rate;drivers/clk/clk-plldig.c line 206
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+ +return 0 ; +} + +static int plldig_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) { +struct clk_plldig *data =to_clk_plldig (hw); +struct plldig_phi1_param phi1_param; +unsigned int rfdphi1, val, cond; +int ret = -ETIMEDOUT ;Drop this initial assignment please.
drivers/clk/clk-plldig.c line 210
Quoted 4 lines
drivers/clk/clk-plldig.c new file +4
-0+ + ret =plldig_calc_target_rate (rate, parent_rate, &phi1_param); +if (ret) +return ret;Because it's overwritten immediately.
drivers/clk/clk-plldig.c
Quoted 13 lines
drivers/clk/clk-plldig.c new file +13
-0+ + val =readl (data->regs +PLLDIG_REG_PLLDV ); + val = phi1_param.mfd; + rfdphi1 = phi1_param.rfdphi1; + val |= rfdphi1; + +writel (val, data->regs +PLLDIG_REG_PLLDV ); + +/* delay 200us make sure that old lock state is cleared */ +udelay (200 ); + +/* Wait until PLL is locked or timeout (maximum 1000 usecs) */ + ret = readl_poll_timeout_atomic(data->regs + PLLDIG_REG_PLLSR,cond,
Quoted 7 lines
drivers/clk/clk-plldig.c line 198
Quoted 1 line
drivers/clk/clk-plldig.c new file +1
-0+ cond & PLLDIG_LOCK_MASK,0,
drivers/clk/clk-plldig.c line 227
Quoted 3 lines
drivers/clk/clk-plldig.c new file +3
-0+ USEC_PER_MSEC); + +return ret;Just return
readl_poll_timeout_atomic(...)here.
Maybe use below code will to best describes.
If (ret)
return -ETIMEOUT;
return 0;
Quoted 12 lines
Quoted 12 lines
drivers/clk/clk-plldig.c new file +11
-0+} + +static const struct clk_ops plldig_clk_ops = { + .enable = plldig_enable, + .disable = plldig_disable, + .is_enabled = plldig_is_enabled, + .recalc_rate = plldig_recalc_rate, + .determine_rate = plldig_determine_rate, + .set_rate = plldig_set_rate, +}; +
Quoted 8 lines
drivers/clk/clk-plldig.c line 245
Quoted 6 lines
drivers/clk/clk-plldig.c new file +6
-0+static int plldig_clk_probe (struct platform_device *pdev) { +struct clk_plldig *data; +struct resource *mem; +struct clk_init_data init = {}; +struct device *dev = &pdev->dev; +struct clk_parent_data parent_data;Set this to = { .index = 0 }
Understand,
Quoted 16 lines
Quoted 4 lines
drivers/clk/clk-plldig.c new file +3
-0+int ret; + + data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL );drivers/clk/clk-plldig.c line 258
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+if (!data) +return -ENOMEM ; + + mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + data->regs =devm_ioremap_resource (dev, mem); +if (IS_ERR (data->regs)) +return PTR_ERR (data->regs); + + parent_data.name =of_clk_get_parent_name (dev->of_node,0 ); + parent_data.index =0 ;And don't assign these.
Understand,
Quoted 18 lines
Quoted 7 lines
drivers/clk/clk-plldig.c new file +6
-0+ + init.name = dev->of_node->name; + init.ops = &plldig_clk_ops; + init.parent_data = &parent_data; + init.num_parents =1 ; +drivers/clk/clk-plldig.c
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+ data->hw.init = &init; + data->dev = dev; + + ret =devm_clk_hw_register (dev, &data->hw); +if (ret) { +dev_err (dev,"failed to register %s clock\n" , init.name); +return ret; + } + + ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get,
&data->hw);
Quoted 7 lines
drivers/clk/clk-plldig.c line 278
Quoted 4 lines
drivers/clk/clk-plldig.c new file +4
-0+if (ret) +dev_err (dev,"failed adding the clock provider\n" ); + +return ret;I'd prefer to just see return
devm_of_clk_add_hw_provider(), but not a big deal.
Understand, thank you for the review.
Best Regards,
Wen
Stephen Boyd
maintainerRE: [EXT] Re: [v4 2/2] clk: ls1028a: Add clock driver for Display output interface
Quoting Wen He (2019-09-18 02:20:26)
Quoted 8 lines
Quoted 8 lines
-----Original Message-----
From: Stephen Boyd <[email protected]>
Quoting Wen He (2019-08-29 03:59:19)Quoted 5 lines
drivers/clk/clk-plldig.c new renamed from drivers/clk/clk-plldig.c +0
-0file mode 100644 index 000000000000..d3239bcf59de
drivers/clk/clk-plldig.c new file +0
-0@@ -0,0 +1,298 @@
[...]
Quoted 37 lines
Quoted 29 lines
Quoted 16 lines
drivers/clk/clk-plldig.c new file +14
-0+ +/* Maximum of the divider */ +#define MAX_RFDPHI1 63 + +/* Best value of multiplication factor divider */ +#define PLLDIG_DEFAULE_MULT 44 + +/* +* Clock configuration relationship between the PHI1 +frequency(fpll_phi) and +* the output frequency of the PLL is determined by the PLLDV, +according to +* the following equation: + * fpll_phi = (pll_ref * mfd) / div_rfdphi1 */ structdrivers/clk/clk-plldig.c line 58
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+plldig_phi1_param { +unsigned long rate; +unsigned int rfdphi1; +unsigned int mfd; +}; + +enum plldig_phi1_freq_range { +PHI1_MIN =27000000U , +PHI1_MAX =600000000U +};Please just inline these values in the one place they're used.
Quoted 7 lines
drivers/clk/clk-plldig.c line 63
Quoted 5 lines
drivers/clk/clk-plldig.c new file +5
-0+ +struct clk_plldig { +struct clk_hw hw; +void __iomem *regs; +struct device *dev;Please remove this, it is unused.
Quoted 1 line
It is used for probe.
Use a local variable and don't store it away forever in the struct.
Quoted 21 lines
Quoted 21 lines
Quoted 4 lines
drivers/clk/clk-plldig.c new file +3
-0+ + val =readl (data->regs +PLLDIG_REG_PLLDV ); + val = phi1_param.mfd;drivers/clk/clk-plldig.c
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+ rfdphi1 = phi1_param.rfdphi1; + val |= rfdphi1; + +writel (val, data->regs +PLLDIG_REG_PLLDV ); + +/* delay 200us make sure that old lock state is cleared */ +udelay (200 ); + +/* Wait until PLL is locked or timeout (maximum 1000 usecs) */ + ret = readl_poll_timeout_atomic(data->regs + PLLDIG_REG_PLLSR,cond,
Quoted 1 line
+ cond &
PLLDIG_LOCK_MASK,0,
Quoted 3 lines
drivers/clk/clk-plldig.c new file +3
-0+ USEC_PER_MSEC); + +return ret;
Quoted 8 lines
Quoted 1 line
Just return
readl_poll_timeout_atomic(...)here.Maybe use below code will to best describes.
If (ret)
return -ETIMEOUT;return 0;
No, just return readl_poll_timeout_atomic().
RE: [EXT] Re: [v4 2/2] clk: ls1028a: Add clock driver for Display output interface
Quoted 61 lines
-----Original Message-----
From: Stephen Boyd <[email protected]>
Sent: 2019年9月19日 1:01
To: [email protected]; [email protected]; [email protected]; [email protected]; Mark Rutland <[email protected]>; Michael Turquette <[email protected]>; Rob Herring <[email protected]>; Wen He <[email protected]>
Cc: Leo Li <[email protected]>; [email protected]
Subject: RE: [EXT] Re: [v4 2/2] clk: ls1028a: Add clock driver for Display output interfaceQuoting Wen He (2019-09-18 02:20:26)
Quoted 8 lines
Quoted 8 lines
-----Original Message-----
From: Stephen Boyd <[email protected]> Quoting Wen He (2019-08-29 03:59:19)Quoted 5 lines
drivers/clk/clk-plldig.c new file +0
-0@@ -0,0 +1,298 @@[...]
Quoted 37 lines
Quoted 36 lines
Quoted 16 lines
drivers/clk/clk-plldig.c new file +14
-0+ +/* Maximum of the divider */ +#define MAX_RFDPHI1 63 + +/* Best value of multiplication factor divider */ +#define PLLDIG_DEFAULE_MULT 44 + +/* +* Clock configuration relationship between the PHI1 +frequency(fpll_phi) and +* the output frequency of the PLL is determined by the PLLDV, +according to +* the following equation: + * fpll_phi = (pll_ref * mfd) / div_rfdphi1 */ structdrivers/clk/clk-plldig.c line 58
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+plldig_phi1_param { +unsigned long rate; +unsigned int rfdphi1; +unsigned int mfd; +}; + +enum plldig_phi1_freq_range { +PHI1_MIN =27000000U , +PHI1_MAX =600000000U +};Please just inline these values in the one place they're used.
drivers/clk/clk-plldig.c line 63
Quoted 5 lines
drivers/clk/clk-plldig.c new file +5
-0+ +struct clk_plldig { +struct clk_hw hw; +void __iomem *regs; +struct device *dev;Please remove this, it is unused.
Quoted 4 lines
Quoted 1 line
It is used for probe.
Use a local variable and don't store it away forever in the struct.
Understand, will remove it.
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
Quoted 5 lines
drivers/clk/clk-plldig.c new file +4
-0+ + val =readl (data->regs +PLLDIG_REG_PLLDV ); + val = phi1_param.mfd; + rfdphi1 = phi1_param.rfdphi1;drivers/clk/clk-plldig.c
Quoted 10 lines
drivers/clk/clk-plldig.c new file +10
-0+ val |= rfdphi1; + +writel (val, data->regs +PLLDIG_REG_PLLDV ); + +/* delay 200us make sure that old lock state is cleared */ +udelay (200 ); + +/* Wait until PLL is locked or timeout (maximum 1000 usecs) */ + ret = readl_poll_timeout_atomic(data->regs + + PLLDIG_REG_PLLSR,cond,
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ cond &
PLLDIG_LOCK_MASK,Quoted 7 lines
Quoted 6 lines
0,
drivers/clk/clk-plldig.c line 227
Quoted 3 lines
drivers/clk/clk-plldig.c new file +3
-0+ USEC_PER_MSEC); + +return ret;Just return
readl_poll_timeout_atomic(...)here.
Quoted 8 lines
Quoted 6 lines
Maybe use below code will to best describes.
If (ret)
return -ETIMEOUT;return 0;
No, just return
readl_poll_timeout_atomic().
Understand, I will send next version patch for this.
Thanks && Best Regards,
Wen