ARM: S3C24XX: Convert S3C2416 to common clock framework
Subsystems (5)
cover ARM: S3C24XX: Convert S3C2416 to common clock framework
Due to the upcoming change in pwm/samsung-time handling, this series is meant as mere discussion source. Nevertheless applied to the current linux-samsung for-next it sucessfully enables the s3c2416 to use the common clock framework.
This series is dependant on the previous samsung-clock fixes and obviously tested on a s3c2416.
Heiko Stuebner (7):
clk: samsung: add plls used in s3c2416 and s3c2443
ARM: S3C24XX: add soc_is_s3c2416 and soc_is_s3c2443
ARM: S3C24XX: enable legacy clock code only when SAMSUNG_CLOCK selected
clk: samsung: add clock-driver for s3c2416, s3c2443 and s3c2450
DO_NOT_APPLY: add clock driver for Samsung pwm clocks
ARM: SAMSUNG: use clk_prepare_enable in samsung-time
DO_NOT_APPLY: convert s3c2416 to use the common clock framework
arch/arm/mach-s3c24xx/Kconfig | 2 +- arch/arm/mach-s3c24xx/Makefile | 2 +- arch/arm/mach-s3c24xx/clock-s3c2416.c | 173 ---------- arch/arm/mach-s3c24xx/common-s3c2443.c | 12 + arch/arm/mach-s3c24xx/common.c | 2 + arch/arm/mach-s3c24xx/common.h | 9 + arch/arm/mach-s3c24xx/mach-smdk2416.c | 9 +- arch/arm/plat-samsung/include/plat/cpu.h | 20 + arch/arm/plat-samsung/samsung-time.c | 6 +- drivers/clk/samsung/Makefile | 1 + drivers/clk/samsung/clk-pll.c | 376 ++++++++++++++++++++ drivers/clk/samsung/clk-pll.h | 8 + drivers/clk/samsung/clk-pwm.c | 554 ++++++++++++++++++++++++++++++ drivers/clk/samsung/clk-s3c2443.c | 463 +++++++++++++++++++++++++ 14 files changed, 1457 insertions(+), 180 deletions(-) delete mode 100644 arch/arm/mach-s3c24xx/clock-s3c2416.c create mode 100644 drivers/clk/samsung/clk-pwm.c create mode 100644 drivers/clk/samsung/clk-s3c2443.c
Signature · 1 line
1.7.2.3
PATCH 1/7 clk: samsung: add plls used in s3c2416 and s3c2443
This adds support for pll2126x, pll3000x, pll6552x and pll6553x.
--- drivers/clk/samsung/clk-pll.c | 376 +++++++++++++++++++++++++++++++++++++++++ drivers/clk/samsung/clk-pll.h | 8 + 2 files changed, 384 insertions(+), 0 deletions(-)
drivers/clk/samsung/clk-pll.c +376 -0
@@ -400,6 +400,97 @@ struct clk * __init samsung_clk_register_pll46xx(const char *name, }/* +* PLL2126x Clock Type +*/ + +#define PLL2126X_MDIV_MASK (0xFF) +#define PLL2126X_PDIV_MASK (0x3) +#define PLL2126X_SDIV_MASK (0x3) +#define PLL2126X_MDIV_SHIFT (16) +#define PLL2126X_PDIV_SHIFT (8) +#define PLL2126X_SDIV_SHIFT (0) + +struct samsung_clk_pll2126x { +struct clk_hw hw; +const void __iomem *con_reg; +}; + +#define to_clk_pll2126x (_hw) container_of(_hw, struct samsung_clk_pll2126x, hw) + +static unsigned long samsung_pll2126x_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +struct samsung_clk_pll2126x *pll =to_clk_pll2126x (hw); +u32 pll_con, mdiv, pdiv, sdiv; +u64 fvco = parent_rate; + + pll_con =__raw_readl (pll->con_reg); + mdiv = (pll_con >>PLL2126X_MDIV_SHIFT ) &PLL2126X_MDIV_MASK ; + pdiv = (pll_con >>PLL2126X_PDIV_SHIFT ) &PLL2126X_PDIV_MASK ; + sdiv = (pll_con >>PLL2126X_SDIV_SHIFT ) &PLL2126X_SDIV_MASK ; + + fvco *= (mdiv +8 ); +do_div (fvco, (pdiv +2 ) << sdiv); + +return (unsigned long )fvco; +} + +/* todo: implement pll2126x clock round rate operation */ +static long samsung_pll2126x_round_rate (struct clk_hw *hw, +unsigned long drate,unsigned long *prate) +{ +return -ENOTSUPP ; +} + +/* todo: implement pll2126x clock set rate */ +static int samsung_pll2126x_set_rate (struct clk_hw *hw,unsigned long drate, +unsigned long prate) +{ +return -ENOTSUPP ; +} + +static const struct clk_ops samsung_pll2126x_clk_ops = { + .recalc_rate = samsung_pll2126x_recalc_rate, + .round_rate = samsung_pll2126x_round_rate, + .set_rate = samsung_pll2126x_set_rate, +}; + +struct clk *__init samsung_clk_register_pll2126x (const char *name, +const char *pname,const void __iomem *con_reg) +{ +struct samsung_clk_pll2126x *pll; +struct clk *clk; +struct clk_init_data init; + + pll =kzalloc (sizeof (*pll),GFP_KERNEL ); +if (!pll) { +pr_err ("%s: could not allocate pll clk %s\n" , __func__, name); +return NULL ; + } + + init.name = name; + init.ops = &samsung_pll2126x_clk_ops; + init.flags =CLK_GET_RATE_NOCACHE ; + init.parent_names = &pname; + init.num_parents =1 ; + + pll->hw.init = &init; + pll->con_reg = con_reg; + + clk =clk_register (NULL , &pll->hw); +if (IS_ERR (clk)) { +pr_err ("%s: failed to register pll clock %s\n" , __func__, + name); +kfree (pll); + } + +if (clk_register_clkdev (clk, name,NULL )) +pr_err ("%s: failed to register lookup for %s" , __func__, name); + +return clk; +} + +/* * PLL2550x Clock Type */
@@ -497,3 +588,288 @@ struct clk * __init samsung_clk_register_pll2550x(const char *name,return clk; } + +/* +* PLL3000x Clock Type +*/ + +#define PLL3000X_MDIV_MASK (0xFF) +#define PLL3000X_PDIV_MASK (0x3) +#define PLL3000X_SDIV_MASK (0x3) +#define PLL3000X_MDIV_SHIFT (16) +#define PLL3000X_PDIV_SHIFT (8) +#define PLL3000X_SDIV_SHIFT (0) + +struct samsung_clk_pll3000x { +struct clk_hw hw; +const void __iomem *con_reg; +}; + +#define to_clk_pll3000x (_hw) container_of(_hw, struct samsung_clk_pll3000x, hw) + +static unsigned long samsung_pll3000x_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +struct samsung_clk_pll3000x *pll =to_clk_pll3000x (hw); +u32 pll_con, mdiv, pdiv, sdiv; +u64 fvco = parent_rate; + + pll_con =__raw_readl (pll->con_reg); + mdiv = (pll_con >>PLL3000X_MDIV_SHIFT ) &PLL3000X_MDIV_MASK ; + pdiv = (pll_con >>PLL3000X_PDIV_SHIFT ) &PLL3000X_PDIV_MASK ; + sdiv = (pll_con >>PLL3000X_SDIV_SHIFT ) &PLL3000X_SDIV_MASK ; + + fvco *= (2 * (mdiv +8 )); +do_div (fvco, pdiv << sdiv); + +return (unsigned long )fvco; +} + +/* todo: implement pll3000x clock round rate operation */ +static long samsung_pll3000x_round_rate (struct clk_hw *hw, +unsigned long drate,unsigned long *prate) +{ +return -ENOTSUPP ; +} + +/* todo: implement pll3000x clock set rate */ +static int samsung_pll3000x_set_rate (struct clk_hw *hw,unsigned long drate, +unsigned long prate) +{ +return -ENOTSUPP ; +} + +static const struct clk_ops samsung_pll3000x_clk_ops = { + .recalc_rate = samsung_pll3000x_recalc_rate, + .round_rate = samsung_pll3000x_round_rate, + .set_rate = samsung_pll3000x_set_rate, +}; + +struct clk *__init samsung_clk_register_pll3000x (const char *name, +const char *pname,const void __iomem *con_reg) +{ +struct samsung_clk_pll3000x *pll; +struct clk *clk; +struct clk_init_data init; + + pll =kzalloc (sizeof (*pll),GFP_KERNEL ); +if (!pll) { +pr_err ("%s: could not allocate pll clk %s\n" , __func__, name); +return NULL ; + } + + init.name = name; + init.ops = &samsung_pll3000x_clk_ops; + init.flags =CLK_GET_RATE_NOCACHE ; + init.parent_names = &pname; + init.num_parents =1 ; + + pll->hw.init = &init; + pll->con_reg = con_reg; + + clk =clk_register (NULL , &pll->hw); +if (IS_ERR (clk)) { +pr_err ("%s: failed to register pll clock %s\n" , __func__, + name); +kfree (pll); + } + +if (clk_register_clkdev (clk, name,NULL )) +pr_err ("%s: failed to register lookup for %s" , __func__, name); + +return clk; +} + +/* +* PLL6552x Clock Type +*/ + +#define PLL6552X_MDIV_MASK (0x3FF) +#define PLL6552X_PDIV_MASK (0x3F) +#define PLL6552X_SDIV_MASK (0x7) +#define PLL6552X_MDIV_SHIFT (14) +#define PLL6552X_PDIV_SHIFT (5) +#define PLL6552X_SDIV_SHIFT (0) + +struct samsung_clk_pll6552x { +struct clk_hw hw; +const void __iomem *con_reg; +}; + +#define to_clk_pll6552x (_hw) container_of(_hw, struct samsung_clk_pll6552x, hw) + +static unsigned long samsung_pll6552x_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +struct samsung_clk_pll6552x *pll =to_clk_pll6552x (hw); +u32 pll_con, mdiv, pdiv, sdiv; +u64 fvco = parent_rate; + + pll_con =__raw_readl (pll->con_reg); + mdiv = (pll_con >>PLL6552X_MDIV_SHIFT ) &PLL6552X_MDIV_MASK ; + pdiv = (pll_con >>PLL6552X_PDIV_SHIFT ) &PLL6552X_PDIV_MASK ; + sdiv = (pll_con >>PLL6552X_SDIV_SHIFT ) &PLL6552X_SDIV_MASK ; + + fvco *= mdiv; +do_div (fvco, (pdiv << sdiv)); + +return (unsigned long )fvco; +} + +/* todo: implement pll6552x clock round rate operation */ +static long samsung_pll6552x_round_rate (struct clk_hw *hw, +unsigned long drate,unsigned long *prate) +{ +return -ENOTSUPP ; +} + +/* todo: implement pll6552x clock set rate */ +static int samsung_pll6552x_set_rate (struct clk_hw *hw,unsigned long drate, +unsigned long prate) +{ +return -ENOTSUPP ; +} + +static const struct clk_ops samsung_pll6552x_clk_ops = { + .recalc_rate = samsung_pll6552x_recalc_rate, + .round_rate = samsung_pll6552x_round_rate, + .set_rate = samsung_pll6552x_set_rate, +}; + +struct clk *__init samsung_clk_register_pll6552x (const char *name, +const char *pname,const void __iomem *con_reg) +{ +struct samsung_clk_pll6552x *pll; +struct clk *clk; +struct clk_init_data init; + + pll =kzalloc (sizeof (*pll),GFP_KERNEL ); +if (!pll) { +pr_err ("%s: could not allocate pll clk %s\n" , __func__, name); +return NULL ; + } + + init.name = name; + init.ops = &samsung_pll6552x_clk_ops; + init.flags =CLK_GET_RATE_NOCACHE ; + init.parent_names = &pname; + init.num_parents =1 ; + + pll->hw.init = &init; + pll->con_reg = con_reg; + + clk =clk_register (NULL , &pll->hw); +if (IS_ERR (clk)) { +pr_err ("%s: failed to register pll clock %s\n" , __func__, + name); +kfree (pll); + } + +if (clk_register_clkdev (clk, name,NULL )) +pr_err ("%s: failed to register lookup for %s" , __func__, name); + +return clk; +} + +/* +* PLL6553x Clock Type +*/ + +#define PLL6553X_MDIV_MASK (0x7F) +#define PLL6553X_PDIV_MASK (0x1F) +#define PLL6553X_SDIV_MASK (0x3) +#define PLL6553X_KDIV_MASK (0xFFFF) +#define PLL6553X_MDIV_SHIFT (16) +#define PLL6553X_PDIV_SHIFT (8) +#define PLL6553X_SDIV_SHIFT (0) + +struct samsung_clk_pll6553x { +struct clk_hw hw; +const void __iomem *con_reg; +}; + +#define to_clk_pll6553x (_hw) container_of(_hw, struct samsung_clk_pll6553x, hw) + +static unsigned long samsung_pll6553x_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +struct samsung_clk_pll6553x *pll =to_clk_pll6553x (hw); +u32 pll_con0, pll_con1, mdiv, pdiv, sdiv, kdiv; +u64 fvco = parent_rate; + + pll_con0 =__raw_readl (pll->con_reg); + pll_con1 =__raw_readl (pll->con_reg +4 ); + mdiv = (pll_con0 >>PLL6553X_MDIV_SHIFT ) &PLL6553X_MDIV_MASK ; + pdiv = (pll_con0 >>PLL6553X_PDIV_SHIFT ) &PLL6553X_PDIV_MASK ; + sdiv = (pll_con0 >>PLL6553X_SDIV_SHIFT ) &PLL6553X_SDIV_MASK ; + kdiv = pll_con1 &PLL6553X_KDIV_MASK ; + +/* +* We need to multiple parent_rate by mdiv (the integer part) and kdiv +* which is in 2^16ths, so shift mdiv up (does not overflow) and +* add kdiv before multiplying. The use of tmp is to avoid any +* overflows before shifting bac down into result when multipling +* by the mdiv and kdiv pair. +*/ + + fvco *= (mdiv <<16 ) + kdiv; +do_div (fvco, (pdiv << sdiv)); + fvco >>=16 ; + +return (unsigned long )fvco; +} + +/* todo: implement pll6553x clock round rate operation */ +static long samsung_pll6553x_round_rate (struct clk_hw *hw, +unsigned long drate,unsigned long *prate) +{ +return -ENOTSUPP ; +} + +/* todo: implement pll6553x clock set rate */ +static int samsung_pll6553x_set_rate (struct clk_hw *hw,unsigned long drate, +unsigned long prate) +{ +return -ENOTSUPP ; +} + +static const struct clk_ops samsung_pll6553x_clk_ops = { + .recalc_rate = samsung_pll6553x_recalc_rate, + .round_rate = samsung_pll6553x_round_rate, + .set_rate = samsung_pll6553x_set_rate, +}; + +struct clk *__init samsung_clk_register_pll6553x (const char *name, +const char *pname,const void __iomem *con_reg) +{ +struct samsung_clk_pll6553x *pll; +struct clk *clk; +struct clk_init_data init; + + pll =kzalloc (sizeof (*pll),GFP_KERNEL ); +if (!pll) { +pr_err ("%s: could not allocate pll clk %s\n" , __func__, name); +return NULL ; + } + + init.name = name; + init.ops = &samsung_pll6553x_clk_ops; + init.flags =CLK_GET_RATE_NOCACHE ; + init.parent_names = &pname; + init.num_parents =1 ; + + pll->hw.init = &init; + pll->con_reg = con_reg; + + clk =clk_register (NULL , &pll->hw); +if (IS_ERR (clk)) { +pr_err ("%s: failed to register pll clock %s\n" , __func__, + name); +kfree (pll); + } + +if (clk_register_clkdev (clk, name,NULL )) +pr_err ("%s: failed to register lookup for %s" , __func__, name); + +return clk; +}
drivers/clk/samsung/clk-pll.h +8 -0
@@ -34,8 +34,16 @@ extern struct clk * __init samsung_clk_register_pll45xx(const char *name,extern struct clk *__init samsung_clk_register_pll46xx (const char *name,const char *pname,const void __iomem *con_reg,enum pll46xx_type type); +extern struct clk *__init samsung_clk_register_pll2126x (const char *name, +const char *pname,const void __iomem *con_reg);extern struct clk *__init samsung_clk_register_pll2550x (const char *name,const char *pname,const void __iomem *reg_base,const unsigned long offset); +extern struct clk *__init samsung_clk_register_pll3000x (const char *name, +const char *pname,const void __iomem *con_reg); +extern struct clk *__init samsung_clk_register_pll6552x (const char *name, +const char *pname,const void __iomem *con_reg); +extern struct clk *__init samsung_clk_register_pll6553x (const char *name, +const char *pname,const void __iomem *con_reg);#endif /* __SAMSUNG_CLK_PLL_H */
Signature · 1 line
1.7.2.3
PATCH 1/7 clk: samsung: add plls used in s3c2416 and s3c2443
drivers/clk/samsung/clk-pll.c struct clk * __init samsung_clk_register_pll46xx(const char *name, · line 488
Quoted 9 lines · Heiko St?bner
drivers/clk/samsung/clk-pll.c +9
-0+ clk =clk_register (NULL , &pll->hw); +if (IS_ERR (clk)) { +pr_err ("%s: failed to register pll clock %s\n" , __func__, + name); +kfree (pll); + } + +if (clk_register_clkdev (clk, name,NULL )) +pr_err ("%s: failed to register lookup for %s" , __func__, name);
The above looks wrong to me.
drivers/clk/samsung/clk-pll.c struct clk * __init samsung_clk_register_pll46xx(const char *name, · line 488
Quoted 9 lines
drivers/clk/samsung/clk-pll.c +9
-0+ clk =clk_register (NULL , &pll->hw); +if (IS_ERR (clk)) { +pr_err ("%s: failed to register pll clock %s\n" , __func__, + name); +kfree (pll); + } + +if (clk_register_clkdev (clk, name,NULL )) +pr_err ("%s: failed to register lookup for %s" , __func__, name);
Same pattern here.
drivers/clk/samsung/clk-pll.c struct clk * __init samsung_clk_register_pll46xx(const char *name, · line 488
Quoted 9 lines
drivers/clk/samsung/clk-pll.c +9
-0+ clk =clk_register (NULL , &pll->hw); +if (IS_ERR (clk)) { +pr_err ("%s: failed to register pll clock %s\n" , __func__, + name); +kfree (pll); + } + +if (clk_register_clkdev (clk, name,NULL )) +pr_err ("%s: failed to register lookup for %s" , __func__, name);
And again here.
drivers/clk/samsung/clk-pll.c struct clk * __init samsung_clk_register_pll46xx(const char *name, · line 488
Quoted 9 lines
drivers/clk/samsung/clk-pll.c +9
-0+ clk =clk_register (NULL , &pll->hw); +if (IS_ERR (clk)) { +pr_err ("%s: failed to register pll clock %s\n" , __func__, + name); +kfree (pll); + } + +if (clk_register_clkdev (clk, name,NULL )) +pr_err ("%s: failed to register lookup for %s" , __func__, name);
And again here... do you notice something about these? They're all the same. Do you know what we do when we have the same thing repeated and only the data is different?
Sylwester Nawrocki
maintainerPATCH 1/7 clk: samsung: add plls used in s3c2416 and s3c2443
In reply to Heiko StübnerHi,
Quoted 13 lines · Heiko St?bner
This adds support for pll2126x, pll3000x, pll6552x and pll6553x.
Signed-off-by Heiko Stuebner <[email protected]>--- drivers/clk/samsung/clk-pll.c | 376 +++++++++++++++++++++++++++++++++++++++++ drivers/clk/samsung/clk-pll.h | 8 + 2 files changed, 384 insertions(+), 0 deletions(-)drivers/clk/samsung/clk-pll.c +0
-0@@ -400,6 +400,97 @@ struct clk * __init samsung_clk_register_pll46xx(const char *name,
...
Quoted 21 lines
drivers/clk/samsung/clk-pll.c +21
-0+struct samsung_clk_pll2126x { +struct clk_hw hw; +const void __iomem *con_reg; +}; + +#define to_clk_pll2126x (_hw) container_of(_hw, struct samsung_clk_pll2126x, hw) + +static unsigned long samsung_pll2126x_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +struct samsung_clk_pll2126x *pll =to_clk_pll2126x (hw); +u32 pll_con, mdiv, pdiv, sdiv; +u64 fvco = parent_rate; + + pll_con =__raw_readl (pll->con_reg); + mdiv = (pll_con >>PLL2126X_MDIV_SHIFT ) &PLL2126X_MDIV_MASK ; + pdiv = (pll_con >>PLL2126X_PDIV_SHIFT ) &PLL2126X_PDIV_MASK ; + sdiv = (pll_con >>PLL2126X_SDIV_SHIFT ) &PLL2126X_SDIV_MASK ; + + fvco *= (mdiv +8 ); +do_div (fvco, (pdiv +2 ) << sdiv);
drivers/clk/samsung/clk-pll.c struct clk * __init samsung_clk_register_pll46xx(const char *name, · line 443
Quoted 10 lines
drivers/clk/samsung/clk-pll.c +10
-0+ +return (unsigned long )fvco; +} + +/* todo: implement pll2126x clock round rate operation */ +static long samsung_pll2126x_round_rate (struct clk_hw *hw, +unsigned long drate,unsigned long *prate) +{ +return -ENOTSUPP ; +}
If you look at __clk_round_rate() in drivers/clk/clk.c it calls clk->ops->round_rate() recursively on the parent clock if CLK_SET_RATE_PARENT flag is set. But if the clock provides round_rate operation __clk_round_rate() will use it and will cast -ENOTSUPP you return above to unsigned long. Unless you want to loose some hair later and waste time on debugging I suggest to either remove all these callbacks that return -ENOSUPP or implement them properly right away.
I'm just wondering why __clk_round_rate() return value type is unsigned long despite the struct clk_ops round_rate return long, which might indicate the negative values round_rate might callback are properly handled by the clk core code.
Somewhat similar situation is with clk_mux_get_parent() in clk-mux.c which can return -EINVAL which is then casted to u8.
I still have sending a patch for clk_mux_get_parent() on my todo list. I guess we could just put a WARN_ON() there and return 0.
drivers/clk/samsung/clk-pll.c struct clk * __init samsung_clk_register_pll46xx(const char *name, · line 456
Quoted 12 lines
drivers/clk/samsung/clk-pll.c +12
-0+/* todo: implement pll2126x clock set rate */ +static int samsung_pll2126x_set_rate (struct clk_hw *hw,unsigned long drate, +unsigned long prate) +{ +return -ENOTSUPP ; +} + +static const struct clk_ops samsung_pll2126x_clk_ops = { + .recalc_rate = samsung_pll2126x_recalc_rate, + .round_rate = samsung_pll2126x_round_rate, + .set_rate = samsung_pll2126x_set_rate, +};
--
Thanks,
Sylwester
PATCH 1/7 clk: samsung: add plls used in s3c2416 and s3c2443
Am Dienstag, 12. M?rz 2013, 13:10:42 schrieb Sylwester Nawrocki:
Quoted 54 lines
Hi,
Quoted 16 lines · Heiko St?bner
This adds support for pll2126x, pll3000x, pll6552x and pll6553x.
Signed-off-by Heiko Stuebner <[email protected]>---
drivers/clk/samsung/clk-pll.c | 376 +++++++++++++++++++++++++++++++++++++++++ drivers/clk/samsung/clk-pll.h | 8 + 2 files changed, 384 insertions(+), 0 deletions(-)(quoted diff) +0
-0
b/drivers/clk/samsung/clk-pll.cindex 4b24511..b772f9e 100644drivers/clk/samsung/clk-pll.c +0
-0@@ -400,6 +400,97 @@ struct clk * __init samsung_clk_register_pll46xx(const char *name,...
Quoted 21 lines
drivers/clk/samsung/clk-pll.c +6
-0+struct samsung_clk_pll2126x { +struct clk_hw hw; +const void __iomem *con_reg; +}; + +#define to_clk_pll2126x (_hw) container_of(_hw, struct
samsung_clk_pll2126x, hw) +drivers/clk/samsung/clk-pll.c +14
-0+static unsigned long samsung_pll2126x_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +struct samsung_clk_pll2126x *pll =to_clk_pll2126x (hw); +u32 pll_con, mdiv, pdiv, sdiv; +u64 fvco = parent_rate; + + pll_con =__raw_readl (pll->con_reg); + mdiv = (pll_con >>PLL2126X_MDIV_SHIFT ) &PLL2126X_MDIV_MASK ; + pdiv = (pll_con >>PLL2126X_PDIV_SHIFT ) &PLL2126X_PDIV_MASK ; + sdiv = (pll_con >>PLL2126X_SDIV_SHIFT ) &PLL2126X_SDIV_MASK ; + + fvco *= (mdiv +8 ); +do_div (fvco, (pdiv +2 ) << sdiv);drivers/clk/samsung/clk-pll.c struct clk * __init samsung_clk_register_pll46xx(const char *name, · line 443
Quoted 10 lines
drivers/clk/samsung/clk-pll.c +10
-0+ +return (unsigned long )fvco; +} + +/* todo: implement pll2126x clock round rate operation */ +static long samsung_pll2126x_round_rate (struct clk_hw *hw, +unsigned long drate,unsigned long *prate) +{ +return -ENOTSUPP ; +}
Quoted 7 lines
If you look at
__clk_round_rate()indrivers/clk/clk.cit callsclk->ops->round_rate()recursively on the parent clock ifCLK_SET_RATE_PARENTflag is set. But if the clock providesround_rateoperation__clk_round_rate()will use it and will cast-ENOTSUPPyou return above to unsigned long. Unless you want to loose some hair later and waste time on debugging I suggest to either remove all these callbacks that return-ENOSUPPor implement them properly right away.
Thanks for the hint ... this is what I rightfully get for mindlessly copying from the other plls in the file;-) .
What about the other plls in the pll-file, they should be affected in the same way, right?
Quoted 28 lines
I'm just wondering why
__clk_round_rate()return value type is unsigned long despite the structclk_opsround_ratereturn long, which might indicate the negative valuesround_ratemight callback are properly handled by the clk core code.Somewhat similar situation is with
clk_mux_get_parent()inclk-mux.cwhich can return-EINVALwhich is then casted to u8.I still have sending a patch for
clk_mux_get_parent()on my todo list. I guess we could just put aWARN_ON()there and return 0.drivers/clk/samsung/clk-pll.c struct clk * __init samsung_clk_register_pll46xx(const char *name, · line 456
Quoted 12 lines
drivers/clk/samsung/clk-pll.c +2
-0+/* todo: implement pll2126x clock set rate */ +static int samsung_pll2126x_set_rate(struct clk_hw *hw, unsigned longdrate, + unsigned long prate)
drivers/clk/samsung/clk-pll.c +9
-0+{ +return -ENOTSUPP ; +} + +static const struct clk_ops samsung_pll2126x_clk_ops = { + .recalc_rate = samsung_pll2126x_recalc_rate, + .round_rate = samsung_pll2126x_round_rate, + .set_rate = samsung_pll2126x_set_rate, +};--
Thanks,
Sylwester
Sylwester Nawrocki
maintainerPATCH 1/7 clk: samsung: add plls used in s3c2416 and s3c2443
Quoted 2 lines · Heiko St?bner
Thanks for the hint ... this is what I rightfully get for mindlessly copying from the other plls in the file;-) .
:)
Quoted 2 lines
What about the other plls in the pll-file, they should be affected in the same way, right?
Yes, they're of course also affected. Otherwise we wouldn't know about the problem;) We are going to submit all fixes we have for the clk driver shortly. But those are mostly for the Exynos clocks definitions.
PATCH 2/7 ARM: S3C24XX: add soc_is_s3c2416 and soc_is_s3c2443
In reply to Heiko StübnerThis is needed to distinguish between them during at least the clock init.
--- arch/arm/plat-samsung/include/plat/cpu.h | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-)
arch/arm/plat-samsung/include/plat/cpu.h +20 -0
@@ -26,6 +26,12 @@ extern unsigned long samsung_cpu_id;#define S3C2412_CPU_ID 0x32412000#define S3C2412_CPU_MASK 0xFFFFF000 +#define S3C2416_CPU_ID 0x32450000 +#define S3C2416_CPU_MASK 0xFFFFF000 + +#define S3C2443_CPU_ID 0x32443000 +#define S3C2443_CPU_MASK 0xFFFFF000 +#define S3C6400_CPU_ID 0x36400000#define S3C6410_CPU_ID 0x36410000#define S3C64XX_CPU_MASK 0xFFFFF000
@@ -57,6 +63,8 @@ static inline int is_samsung_##name(void) \ IS_SAMSUNG_CPU(s3c24xx, S3C24XX_CPU_ID, S3C24XX_CPU_MASK) IS_SAMSUNG_CPU(s3c2412, S3C2412_CPU_ID, S3C2412_CPU_MASK) +IS_SAMSUNG_CPU(s3c2416, S3C2416_CPU_ID, S3C2416_CPU_MASK) +IS_SAMSUNG_CPU(s3c2443, S3C2443_CPU_ID, S3C2443_CPU_MASK) IS_SAMSUNG_CPU(s3c6400, S3C6400_CPU_ID, S3C64XX_CPU_MASK) IS_SAMSUNG_CPU(s3c6410, S3C6410_CPU_ID, S3C64XX_CPU_MASK)IS_SAMSUNG_CPU (s5p6440,S5P6440_CPU_ID ,S5P64XX_CPU_MASK )
@@ -84,6 +92,18 @@ IS_SAMSUNG_CPU(exynos5440, EXYNOS5440_SOC_ID, EXYNOS5_SOC_MASK)# define soc_is_s3c2412 () 0#endif +#if defined(CONFIG_CPU_S3C2416 ) +# define soc_is_s3c2416 () is_samsung_s3c2416() +#else +# define soc_is_s3c2416 () 0 +#endif + +#if defined(CONFIG_CPU_S3C2443 ) +# define soc_is_s3c2443 () is_samsung_s3c2443() +#else +# define soc_is_s3c2443 () 0 +#endif +#if defined(CONFIG_CPU_S3C6400 ) || defined(CONFIG_CPU_S3C6410 )# define soc_is_s3c64xx () (is_samsung_s3c6400() || is_samsung_s3c6410())#else
Signature · 1 line
1.7.2.3
PATCH 3/7 ARM: S3C24XX: enable legacy clock code only when SAMSUNG_CLOCK selected
In reply to Heiko StübnerThis enables a smooth transition, as not all S3C24XX SoCs need to be converted at the same time and can instead simply exchange their select SAMSUNG_CLOCK with a select COMMON_CLK after the conversion.
--- arch/arm/mach-s3c24xx/common-s3c2443.c | 2 ++ arch/arm/mach-s3c24xx/common.c | 2 ++ 2 files changed, 4 insertions(+), 0 deletions(-)
arch/arm/mach-s3c24xx/common-s3c2443.c +2 -0
@@ -28,6 +28,7 @@#include <plat/cpu-freq.h> +#ifdef CONFIG_SAMSUNG_CLOCK static int s3c2443_gate (void __iomem *reg,struct clk *clk,int enable) {u32 ctrlbit = clk->ctrlbit;
@@ -673,3 +674,4 @@ void __init s3c2443_common_init_clocks(int xtal, pll_fn get_mpll, s3c2443_common_setup_clocks(get_mpll); } +#endif
arch/arm/mach-s3c24xx/common.c +2 -0
@@ -285,6 +285,7 @@ struct s3c24xx_uart_resources s3c2410_uart_resources[] __initdata = {/* initialise all the clocks */ +#ifdef CONFIG_SAMSUNG_CLOCK void __init_or_cpufreq s3c24xx_setup_clocks(unsigned long fclk,unsigned long hclk,unsigned long pclk)
@@ -297,3 +298,4 @@ void __init_or_cpufreq s3c24xx_setup_clocks(unsigned long fclk, clk_p.rate = pclk; clk_f.rate = fclk; } +#endif
Signature · 1 line
1.7.2.3
PATCH 4/7 clk: samsung: add clock-driver for s3c2416, s3c2443 and s3c2450
In reply to Heiko StübnerThe three SoCs share a common clock tree which only differs in the existence of some special clocks. The s3c2450 specific clocks will only be reachable via DT in the near future, as there is no generic way to distinguish between the similar s3c2416 and s3c2450 SoCs.
As with all parts common to these three SoCs the driver is named after the s3c2443, as it was the first SoC introducing this structure and there exists no other label to describe this s3c24xx epoch.
The clock structure is built according to the manuals of the included SoCs and might include changes in comparison to the previous clock structure. As an example the sclk_uart was never handled previously and the div_uart was made the clock used by the serial driver.
--- drivers/clk/samsung/Makefile | 1 + drivers/clk/samsung/clk-s3c2443.c | 463 +++++++++++++++++++++++++++++++++++++ 2 files changed, 464 insertions(+), 0 deletions(-) create mode 100644 drivers/clk/samsung/clk-s3c2443.c
drivers/clk/samsung/Makefile +1 -0
@@ -6,3 +6,4 @@ obj-$(CONFIG_COMMON_CLK) += clk.o clk-pll.o obj-$(CONFIG_ARCH_EXYNOS4) += clk-exynos4.o obj-$(CONFIG_SOC_EXYNOS5250) += clk-exynos5250.o obj-$(CONFIG_SOC_EXYNOS5440) += clk-exynos5440.o +obj-$(CONFIG_S3C2443_COMMON) += clk-s3c2443.o
drivers/clk/samsung/clk-s3c2443.c new file +463 -0
463 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH 5/7 DO_NOT_APPLY: add clock driver for Samsung pwm clocks
In reply to Heiko StübnerThis ports the pwm-clock code from plat-samsung to the common clock framework to make available the pwm clocks used by samsung-time and the samsung pwm driver.
This is needed to enable the usage of the samsung-time clocksource when using the common clock framework on s3c arches but the correct solution will be in the upcoming time/pwm driver which will handle the pwm clocks itself.
--- drivers/clk/samsung/Makefile | 2 +- drivers/clk/samsung/clk-pwm.c | 554 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 555 insertions(+), 1 deletions(-) create mode 100644 drivers/clk/samsung/clk-pwm.c
drivers/clk/samsung/Makefile +1 -1
@@ -6,4 +6,4 @@ obj-$(CONFIG_COMMON_CLK) += clk.o clk-pll.o obj-$(CONFIG_ARCH_EXYNOS4) += clk-exynos4.o obj-$(CONFIG_SOC_EXYNOS5250) += clk-exynos5250.o obj-$(CONFIG_SOC_EXYNOS5440) += clk-exynos5440.o -obj-$(CONFIG_S3C2443_COMMON) += clk-s3c2443.o +obj-$(CONFIG_S3C2443_COMMON) += clk-s3c2443.o clk-pwm.o
drivers/clk/samsung/clk-pwm.c new file +554 -0
554 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH 6/7 ARM: SAMSUNG: use clk_prepare_enable in samsung-time
In reply to Heiko StübnerThe common clock framework expects clocks to be prepared before they are enabled.
--- arch/arm/plat-samsung/samsung-time.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
arch/arm/plat-samsung/samsung-time.c +3 -3
@@ -355,7 +355,7 @@ static void __init samsung_timer_resources(void)if (IS_ERR (timerclk))panic ("failed to get timers clock for timer" ); -clk_enable (timerclk); +clk_prepare_enable (timerclk);sprintf (devname,"s3c24xx-pwm.%lu" , event_id); s3c_device_timer[event_id].id = event_id;
@@ -369,7 +369,7 @@ static void __init samsung_timer_resources(void)if (IS_ERR (tdiv_event))panic ("failed to get pwm-tdiv clock for event timer" ); -clk_enable (tin_event); +clk_prepare_enable (tin_event);sprintf (devname,"s3c24xx-pwm.%lu" , source_id); s3c_device_timer[source_id].id = source_id;
@@ -383,7 +383,7 @@ static void __init samsung_timer_resources(void)if (IS_ERR (tdiv_source))panic ("failed to get pwm-tdiv clock for source timer" ); -clk_enable (tin_source); +clk_prepare_enable (tin_source); }void __init samsung_timer_init (void )
Signature · 1 line
1.7.2.3
PATCH 6/7 ARM: SAMSUNG: use clk_prepare_enable in samsung-time
Hi,
Quoted 13 lines · Heiko St?bner
The common clock framework expects clocks to be prepared before they are enabled.
Signed-off-by Heiko Stuebner <[email protected]>--- arch/arm/plat-samsung/samsung-time.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)arch/arm/plat-samsung/samsung-time.c +0
-0
arch/arm/plat-samsung/samsung-time.c static void __init samsung_timer_resources(void) · line 357
Quoted 3 lines
arch/arm/plat-samsung/samsung-time.c +0
-0@@ -355,7 +355,7 @@ static void __init samsung_timer_resources(void)if (IS_ERR (timerclk))panic ("failed to get timers clock for timer" );
Also how about calling the clk_prepare_enable() only if the clk_get() call is a sucess? Though clk framework will take care of it. Just thinking even to avoid that call if clk_get() fails since you are modifying the code.
arch/arm/plat-samsung/samsung-time.c static void __init samsung_timer_resources(void) · line 371
Quoted 9 lines
arch/arm/plat-samsung/samsung-time.c +1
-1-clk_enable (timerclk); +clk_prepare_enable (timerclk);sprintf (devname,"s3c24xx-pwm.%lu" , event_id); s3c_device_timer[event_id].id = event_id;@@ -369,7 +369,7 @@ static void __init samsung_timer_resources(void)if (IS_ERR (tdiv_event))panic ("failed to get pwm-tdiv clock for event timer" );
Same here...
arch/arm/plat-samsung/samsung-time.c static void __init samsung_timer_resources(void) · line 374
Quoted 4 lines
arch/arm/plat-samsung/samsung-time.c +1
-1-clk_enable (tin_event); +clk_prepare_enable (tin_event);sprintf (devname,"s3c24xx-pwm.%lu" , source_id);
Regards,
Pankaj Jangra
PATCH 6/7 ARM: SAMSUNG: use clk_prepare_enable in samsung-time
Hi,
Am Mittwoch, 13. M?rz 2013, 17:59:04 schrieb Pankaj Jangra:
Quoted 18 lines
Hi,
Quoted 15 lines · Heiko St?bner
The common clock framework expects clocks to be prepared before they are enabled.
Signed-off-by Heiko Stuebner <[email protected]>---
arch/arm/plat-samsung/samsung-time.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)(quoted diff) +0
-0
b/arch/arm/plat-samsung/samsung-time.cindex f899cbc..6ebb851 100644arch/arm/plat-samsung/samsung-time.c +0
-0@@ -355,7 +355,7 @@ static void __init samsung_timer_resources(void)
Quoted 8 lines
arch/arm/plat-samsung/samsung-time.c static void __init samsung_timer_resources(void)
Quoted 3 lines
arch/arm/plat-samsung/samsung-time.c +0
-0if (IS_ERR (timerclk))panic ("failed to get timers clock for timer" );Also how about calling the
clk_prepare_enable()only if theclk_get()call is a sucess? Though clk framework will take care of it. Just thinking even to avoid that call ifclk_get()fails since you are modifying the code.
I remember there was a discussion about panic vc error handling when this was introduced but I don't remember the specifics, but it seems they agreed to do it this way with letting the kernel panic when the clock is missing.
Also the current plan seems to replace the clocksource and pwm drivers that occupy the same register space with a driver handling both, making the pwm specific clocks obsolete and only the timers clock will remain. So this was merely meant as a fixup when using the clock changes with the current clocksource code.
Quoted 21 lines
arch/arm/plat-samsung/samsung-time.c static void __init samsung_timer_resources(void) · line 372
Quoted 11 lines
arch/arm/plat-samsung/samsung-time.c +1
-1-clk_enable (timerclk); +clk_prepare_enable (timerclk);sprintf (devname,"s3c24xx-pwm.%lu" , event_id);s3c_device_timer[event_id].id = event_id;arch/arm/plat-samsung/samsung-time.c +0
-0@@ -369,7 +369,7 @@ static void __init samsung_timer_resources(void)if (IS_ERR (tdiv_event))panic ("failed to get pwm-tdiv clock for event timer" );Same here...
arch/arm/plat-samsung/samsung-time.c static void __init samsung_timer_resources(void) · line 374
Quoted 4 lines
arch/arm/plat-samsung/samsung-time.c +1
-1-clk_enable (tin_event); +clk_prepare_enable (tin_event);sprintf (devname,"s3c24xx-pwm.%lu" , source_id);Regards,
Pankaj Jangra
PATCH 7/7 DO_NOT_APPLY: convert s3c2416 to use the common clock framework
In reply to Heiko StübnerSwitch the s3c2416 and smdk2416 from using the Samsung clocks to the common clock framework. This is not meant to be the final result, as it uses the temporary pwm clocks and the clock init itself also needs changes, especially as the _init_time function stolen from exynos is currently board specific due to the xtal frequency which needs to be set.
--- arch/arm/mach-s3c24xx/Kconfig | 2 +- arch/arm/mach-s3c24xx/Makefile | 2 +- arch/arm/mach-s3c24xx/clock-s3c2416.c | 173 -------------------------------- arch/arm/mach-s3c24xx/common-s3c2443.c | 10 ++ arch/arm/mach-s3c24xx/common.h | 9 ++ arch/arm/mach-s3c24xx/mach-smdk2416.c | 9 ++- 6 files changed, 28 insertions(+), 177 deletions(-) delete mode 100644 arch/arm/mach-s3c24xx/clock-s3c2416.c
arch/arm/mach-s3c24xx/Kconfig +1 -1
@@ -54,7 +54,7 @@ config CPU_S3C2416 select S3C2416_PM if PM select S3C2443_COMMON select S3C2443_DMA if S3C24XX_DMA - select SAMSUNG_CLKSRC + select COMMON_CLK select SAMSUNG_HRT help Support for the S3C2416 SoC from the S3C24XX line
arch/arm/mach-s3c24xx/Makefile +1 -1
@@ -28,7 +28,7 @@ obj-$(CONFIG_S3C2412_DMA) += dma-s3c2412.o obj-$(CONFIG_S3C2412_PM) += pm-s3c2412.o obj-$(CONFIG_S3C2412_PM_SLEEP) += sleep-s3c2412.o -obj-$(CONFIG_CPU_S3C2416) += s3c2416.o clock-s3c2416.o +obj-$(CONFIG_CPU_S3C2416) += s3c2416.o obj-$(CONFIG_S3C2416_PM) += pm-s3c2416.o obj-$(CONFIG_CPU_S3C2440) += s3c2440.o clock-s3c2440.o
arch/arm/mach-s3c24xx/clock-s3c2416.c deleted +0 -173
173 lines not on this page · raw message
arch/arm/mach-s3c24xx/common-s3c2443.c +10 -0
@@ -27,6 +27,7 @@#include <plat/cpu-freq.h> +#include "common.h" #ifdef CONFIG_SAMSUNG_CLOCK static int s3c2443_gate (void __iomem *reg,struct clk *clk,int enable)
@@ -675,3 +676,12 @@ void __init s3c2443_common_init_clocks(int xtal, pll_fn get_mpll, s3c2443_common_setup_clocks(get_mpll); }#endif + +#ifdef CONFIG_COMMON_CLK +void __init s3c2416_init_clocks (int xtal) +{ +s3c2443_clk_init (NULL ); +s3c2443_clk_register_fixed_ext (xtal,0 ,0 ,0 ); +samsung_pwm_clk_init (NULL ); +} +#endif
arch/arm/mach-s3c24xx/common.h +9 -0
@@ -107,4 +107,13 @@ extern void s3c2443_init_irq(void);extern struct syscore_ops s3c24xx_irq_syscore_ops; +#ifdef CONFIG_S3C2443_COMMON +extern void s3c2443_clk_register_fixed_ext (unsigned long xti_f, +unsigned long ext_f,unsigned long i2s_f, +unsigned long uart_f); +extern void __init s3c2443_clk_init (struct device_node *np); +#endif + +extern void __init samsung_pwm_clk_init (struct device_node *np); +#endif /* __ARCH_ARM_MACH_S3C24XX_COMMON_H */
arch/arm/mach-s3c24xx/mach-smdk2416.c +7 -2
@@ -217,10 +217,15 @@ static struct platform_device *smdk2416_devices[] __initdata = { &s3c_device_usb_hsudc, }; +static void __init smdk2416_init_time (void ) +{ +s3c24xx_init_clocks (12000000 ); +samsung_timer_init (); +} +static void __init smdk2416_map_io (void ) {s3c24xx_init_io (smdk2416_iodesc,ARRAY_SIZE (smdk2416_iodesc)); -s3c24xx_init_clocks (12000000 );s3c24xx_init_uarts (smdk2416_uartcfgs,ARRAY_SIZE (smdk2416_uartcfgs));samsung_set_timer_source (SAMSUNG_PWM3 ,SAMSUNG_PWM4 ); }
@@ -255,6 +260,6 @@ MACHINE_START(SMDK2416, "SMDK2416") .init_irq = s3c2416_init_irq, .map_io = smdk2416_map_io, .init_machine = smdk2416_machine_init, - .init_time = samsung_timer_init, + .init_time = smdk2416_init_time, .restart = s3c2416_restart,MACHINE_END
Signature · 1 line
1.7.2.3