DW SPI: Get clock value from Device Tree
Subsystems (4)
v8 cover DW SPI: Get clock value from Device Tree
As discussed with Marek during the LINUX-PITER here is v* patch:
Add option to set spi controller clock frequency via device tree using standard clock bindings.
Define dw_spi_get_clk function as 'weak' as some targets (like SOCFPGA_GEN5 and SOCFPGA_ARRIA10) don't use standard clock API and implement dw_spi_get_clk their own way in their clock manager.
Get rid of clock_manager.h include in designware_spi.c as we don't use cm_get_spi_controller_clk_hz function anymore - we use redefined dw_spi_get_clk in SOCFPGA clock managers (clock_manager_gen5.c and clock_manager_arria10.c) instead.
Changes v7->v8:
* Fix typo in comments.
Changes v6->v7:
* Cleanup error handling.
* Don't free clock after we successfully requeste it.
Changes v5->v6:
* Put the clock handle into the private data
Changes v4->v5:
* Get rid of usless ifdef in dw_spi_get_clk function
Eugeniy Paltsev (2):
SOCFPGA: clock manager: implement dw_spi_get_clk function DW SPI: Get clock value from Device Tree
arch/arm/mach-socfpga/clock_manager_arria10.c | 9 +++++ arch/arm/mach-socfpga/clock_manager_gen5.c | 9 +++++ drivers/spi/designware_spi.c | 47 +++++++++++++++++++++++++-- 3 files changed, 63 insertions(+), 2 deletions(-)
Signature · 1 line
2.9.3
PATCH v8 1/2 SOCFPGA: clock manager: implement dw_spi_get_clk function
Implement dw_spi_get_clk function to override its weak implementation in designware_spi.c driver.
We need this change to get rid of cm_get_spi_controller_clk_hz function and clock_manager.h include in designware_spi.c driver.
--- arch/arm/mach-socfpga/clock_manager_arria10.c | 9 +++++++++ arch/arm/mach-socfpga/clock_manager_gen5.c | 9 +++++++++ 2 files changed, 18 insertions(+)
arch/arm/mach-socfpga/clock_manager_arria10.c +9 -0
@@ -7,6 +7,7 @@#include <common.h> #include <fdtdec.h> #include <asm/io.h> +#include <dm.h> #include <asm/arch/clock_manager.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -1076,6 +1077,14 @@ unsigned int cm_get_qspi_controller_clk_hz(void)return cm_get_l4_noc_hz (CLKMGR_MAINPLL_NOCDIV_L4MAINCLK_LSB ); } +/* Override weak dw_spi_get_clk implementation in designware_spi.c driver */ +int dw_spi_get_clk (struct udevice *bus,ulong *rate) +{ + *rate =cm_get_spi_controller_clk_hz (); + +return 0 ; +} +void cm_print_clock_quick_summary (void ) {printf ("MPU %10ld kHz\n" ,cm_get_mpu_clk_hz () /1000 );
arch/arm/mach-socfpga/clock_manager_gen5.c +9 -0
@@ -6,6 +6,7 @@#include <common.h> #include <asm/io.h> +#include <dm.h> #include <asm/arch/clock_manager.h> #include <wait_bit.h>
@@ -509,6 +510,14 @@ unsigned int cm_get_spi_controller_clk_hz(void)return clock; } +/* Override weak dw_spi_get_clk implementation in designware_spi.c driver */ +int dw_spi_get_clk (struct udevice *bus,ulong *rate) +{ + *rate =cm_get_spi_controller_clk_hz (); + +return 0 ; +} +void cm_print_clock_quick_summary (void ) {printf ("MPU %10ld kHz\n" ,cm_get_mpu_clk_hz () /1000 );
Signature · 1 line
2.9.3
PATCH v8 2/2 DW SPI: Get clock value from Device Tree
In reply to Eugeniy PaltsevAdd option to set spi controller clock frequency via device tree using standard clock bindings.
Define dw_spi_get_clk function as 'weak' as some targets (like SOCFPGA_GEN5 and SOCFPGA_ARRIA10) don't use standard clock API and implement dw_spi_get_clk their own way in their clock manager.
Get rid of clock_manager.h include as we don't use cm_get_spi_controller_clk_hz function anymore. (we use redefined dw_spi_get_clk in SOCFPGA clock managers instead)
--- drivers/spi/designware_spi.c | 45 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-)
drivers/spi/designware_spi.c +43 -2
@@ -11,6 +11,7 @@*/ #include <common.h> +#include <clk.h> #include <dm.h> #include <errno.h> #include <malloc.h>
@@ -18,7 +19,6 @@#include <fdtdec.h> #include <linux/compat.h> #include <asm/io.h> -#include <asm/arch/clock_manager.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -94,6 +94,8 @@ struct dw_spi_priv {void __iomem *regs;unsigned int freq;/* Default frequency */ unsigned int mode; +struct clk clk; +unsigned long bus_clk_rate;int bits_per_word;u8 cs;/* chip select pin */
@@ -176,14 +178,53 @@ static void spi_hw_init(struct dw_spi_priv *priv)debug ("%s: fifo_len=%d\n" , __func__, priv->fifo_len); } +/* +* We define dw_spi_get_clk function as 'weak' as some targets +* (like SOCFPGA_GEN5 and SOCFPGA_ARRIA10) don't use standard clock API +* and implement dw_spi_get_clk their own way in their clock manager. +*/ +__weak int dw_spi_get_clk (struct udevice *bus,ulong *rate) +{ +struct dw_spi_priv *priv =dev_get_priv (bus); +int ret; + + ret =clk_get_by_index (bus,0 , &priv->clk); +if (ret) +return ret; + + ret =clk_enable (&priv->clk); +if (ret && ret != -ENOSYS && ret != -ENOTSUPP ) +return ret; + + *rate =clk_get_rate (&priv->clk); +if (!*rate) + goto err_rate; + +debug ("%s: get spi controller clk via device tree: %lu Hz\n" , + __func__, *rate); + +return 0 ; + +err_rate: +clk_disable (&priv->clk); +clk_free (&priv->clk); + +return -EINVAL ; +} +static int dw_spi_probe (struct udevice *bus) {struct dw_spi_platdata *plat =dev_get_platdata (bus);struct dw_spi_priv *priv =dev_get_priv (bus); +int ret; priv->regs = plat->regs; priv->freq = plat->frequency; + ret =dw_spi_get_clk (bus, &priv->bus_clk_rate); +if (ret) +return ret; +/* Currently only bits_per_word == 8 supported */ priv->bits_per_word =8 ;
@@ -369,7 +410,7 @@ static int dw_spi_set_speed(struct udevice *bus, uint speed)spi_enable_chip (priv,0 );/* clk_div doesn't support odd number */ - clk_div =cm_get_spi_controller_clk_hz () / speed; + clk_div = priv->bus_clk_rate / speed; clk_div = (clk_div +1 ) &0xfffe ;dw_writel (priv,DW_SPI_BAUDR , clk_div);
Signature · 1 line
2.9.3
PATCH v8 2/2 DW SPI: Get clock value from Device Tree
Hi Jagan,
Could you please pull these patches to your tree?
It would be really nice to see this patch in the nearest release.
Thanks.
Quoted 109 lines · Eugeniy Paltsev
Add option to set spi controller clock frequency via device tree using standard clock bindings.
Define
dw_spi_get_clkfunction as 'weak' as some targets (likeSOCFPGA_GEN5andSOCFPGA_ARRIA10) don't use standard clock API and implementdw_spi_get_clktheir own way in their clock manager.Get rid of
clock_manager.hinclude as we don't usecm_get_spi_controller_clk_hzfunction anymore. (we use redefineddw_spi_get_clkin SOCFPGA clock managers instead)Reviewed-by Marek Vasut <[email protected]>Signed-off-by Eugeniy Paltsev <[email protected]>---
drivers/spi/designware_spi.c | 45 ++++++++++++++++++++++++++++++++++++++++++--1 file changed, 43 insertions(+), 2 deletions(-)drivers/spi/designware_spi.c +0
-0@@ -11,6 +11,7 @@*/
#include <common.h>
+#include <clk.h>
#include <dm.h>
#include <errno.h>
#include <malloc.h>drivers/spi/designware_spi.c +0
-1@@ -18,7 +19,6 @@ #include <fdtdec.h> #include <linux/compat.h> #include <asm/io.h> -#include <asm/arch/clock_manager.h>
DECLARE_GLOBAL_DATA_PTR;drivers/spi/designware_spi.c +0
-0@@ -94,6 +94,8 @@ struct dw_spi_priv { void __iomem *regs;unsigned int freq; /* Default frequency */
unsigned int mode;drivers/spi/designware_spi.c +2
-0+struct clk clk; +unsigned long bus_clk_rate;
intbits_per_word;
u8 cs; /* chip select pin */drivers/spi/designware_spi.c +0
-0@@ -176,14 +178,53 @@ static void spi_hw_init(struct dw_spi_priv *priv) debug("%s: fifo_len=%d\n", __func__, priv->fifo_len); }drivers/spi/designware_spi.c +34
-0+/* +* We define dw_spi_get_clk function as 'weak' as some targets +* (like SOCFPGA_GEN5 and SOCFPGA_ARRIA10) don't use standard clock API +* and implement dw_spi_get_clk their own way in their clock manager. +*/ +__weak int dw_spi_get_clk (struct udevice *bus,ulong *rate) +{ +struct dw_spi_priv *priv =dev_get_priv (bus); +int ret; + + ret =clk_get_by_index (bus,0 , &priv->clk); +if (ret) +return ret; + + ret =clk_enable (&priv->clk); +if (ret && ret != -ENOSYS && ret != -ENOTSUPP ) +return ret; + + *rate =clk_get_rate (&priv->clk); +if (!*rate) + goto err_rate; + +debug ("%s: get spi controller clk via device tree: %lu Hz\n" , + __func__, *rate); + +return 0 ; + +err_rate: +clk_disable (&priv->clk); +clk_free (&priv->clk); + +return -EINVAL ; +} +static int
dw_spi_probe(struct udevice *bus)
{
structdw_spi_platdata*plat =dev_get_platdata(bus); structdw_spi_priv*priv =dev_get_priv(bus);drivers/spi/designware_spi.c +1
-0+int ret;
priv->regs=plat->regs;
priv->freq=plat->frequency;drivers/spi/designware_spi.c +4
-0+ ret =dw_spi_get_clk (bus, &priv->bus_clk_rate); +if (ret) +return ret; +/* Currently only
bits_per_word== 8 supported */priv->bits_per_word= 8;drivers/spi/designware_spi.c +0
-0@@ -369,7 +410,7 @@ static int dw_spi_set_speed(struct udevice *bus, uint speed) spi_enable_chip(priv, 0);
/*clk_divdoesn't support odd number */drivers/spi/designware_spi.c +1
-1- clk_div =cm_get_spi_controller_clk_hz () / speed; + clk_div = priv->bus_clk_rate / speed;
clk_div= (clk_div+ 1) &0xfffe;
dw_writel(priv, DW_SPI_BAUDR, clk_div);
Signature · 1 line
Eugeniy Paltsev
PATCH v8 2/2 DW SPI: Get clock value from Device Tree
Hi Jagan,
Quoted 22 lines · Eugeniy Paltsev
Hi Jagan,
Could you please pull these patches to your tree?
It would be really nice to see this patch in the nearest release.Thanks.
Quoted 14 lines · Eugeniy Paltsev
Add option to set spi controller clock frequency via device tree using standard clock bindings.
Define
dw_spi_get_clkfunction as 'weak' as some targets (likeSOCFPGA_GEN5andSOCFPGA_ARRIA10) don't use standard clock API and implementdw_spi_get_clktheir own way in their clock manager.Get rid of
clock_manager.hinclude as we don't usecm_get_spi_controller_clk_hzfunction anymore. (we use redefineddw_spi_get_clkin SOCFPGA clock managers instead)Reviewed-by Marek Vasut <[email protected]>Signed-off-by Eugeniy Paltsev <[email protected]>---
Any chance for this one to be applied sometime soon?
Note this is a prerequisite for our further work and it's been floating and discussed on the mailing list for a couple of months now, that said we'd really like to get this as a part of U-Boot 2018.03.
-Alexey
PATCH v8 2/2 DW SPI: Get clock value from Device Tree
Quoted 22 lines · Alexey Brodkin
Hi Jagan,
Quoted 19 lines · Eugeniy Paltsev
Hi Jagan,
Could you please pull these patches to your tree?
It would be really nice to see this patch in the nearest release.Thanks.
Quoted 11 lines · Eugeniy Paltsev
Add option to set spi controller clock frequency via device tree using standard clock bindings.
Define
dw_spi_get_clkfunction as 'weak' as some targets (likeSOCFPGA_GEN5andSOCFPGA_ARRIA10) don't use standard clock API and implementdw_spi_get_clktheir own way in their clock manager.Get rid of
clock_manager.hinclude as we don't usecm_get_spi_controller_clk_hzfunction anymore. (we use redefineddw_spi_get_clkin SOCFPGA clock managers instead)
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Reviewed-by Marek Vasut <[email protected]>Signed-off-by Eugeniy Paltsev <[email protected]>---
Any chance for this one to be applied sometime soon?
Note this is a prerequisite for our further work and it's been floating and discussed on the mailing list for a couple of months now, that said we'd really like to get this as a part of U-Boot 2018.03.
Since delegate has marked to 'marek' it wasn't showed with me, yes will take this.
PATCH v8 2/2 DW SPI: Get clock value from Device Tree
Quoted 28 lines · Jagan Teki
Quoted 26 lines · Alexey Brodkin
Hi Jagan,
Quoted 22 lines · Eugeniy Paltsev
Hi Jagan,
Could you please pull these patches to your tree?
It would be really nice to see this patch in the nearest release.Thanks.
Quoted 14 lines · Eugeniy Paltsev
Add option to set spi controller clock frequency via device tree using standard clock bindings.
Define
dw_spi_get_clkfunction as 'weak' as some targets (likeSOCFPGA_GEN5andSOCFPGA_ARRIA10) don't use standard clock API and implementdw_spi_get_clktheir own way in their clock manager.Get rid of
clock_manager.hinclude as we don't usecm_get_spi_controller_clk_hzfunction anymore. (we use redefineddw_spi_get_clkin SOCFPGA clock managers instead)Reviewed-by Marek Vasut <[email protected]>Signed-off-by Eugeniy Paltsev <[email protected]>---
Quoted 7 lines
Quoted 4 lines
Any chance for this one to be applied sometime soon?
Note this is a prerequisite for our further work and it's been floating and discussed on the mailing list for a couple of months now, that said we'd really like to get this as a part of U-Boot 2018.03.Since delegate has marked to 'marek' it wasn't showed with me, yes will take this.
As always, oops, my bad. I think I saw Marek commenting at one point and kept delegating to him. And I missed that it now has his Reviewed-by, so yes, please pick this up in patchwork, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180125/321dd0c0/attachment.sig>
PATCH v8 2/2 DW SPI: Get clock value from Device Tree
Quoted 34 lines · Tom Rini
Quoted 33 lines · Jagan Teki
Quoted 30 lines · Alexey Brodkin
Hi Jagan,
Quoted 22 lines · Eugeniy Paltsev
Hi Jagan,
Could you please pull these patches to your tree?
It would be really nice to see this patch in the nearest release.Thanks.
Quoted 14 lines · Eugeniy Paltsev
Add option to set spi controller clock frequency via device tree using standard clock bindings.
Define
dw_spi_get_clkfunction as 'weak' as some targets (likeSOCFPGA_GEN5andSOCFPGA_ARRIA10) don't use standard clock API and implementdw_spi_get_clktheir own way in their clock manager.Get rid of
clock_manager.hinclude as we don't usecm_get_spi_controller_clk_hzfunction anymore. (we use redefineddw_spi_get_clkin SOCFPGA clock managers instead)Reviewed-by Marek Vasut <[email protected]>Signed-off-by Eugeniy Paltsev <[email protected]>---
Any chance for this one to be applied sometime soon?
Note this is a prerequisite for our further work and it's been floating and discussed on the mailing list for a couple of months now, that said we'd really like to get this as a part of U-Boot 2018.03.
Quoted 6 lines
Quoted 2 lines
Since delegate has marked to 'marek' it wasn't showed with me, yes will take this.
As always, oops, my bad. I think I saw Marek commenting at one point and kept delegating to him. And I missed that it now has his Reviewed-by, so yes, please pick this up in patchwork, thanks!
Applied to u-boot-spi/master, thanks!
v8 cover DW SPI: Get clock value from Device Tree
In reply to Eugeniy PaltsevQuoted 27 lines · Eugeniy Paltsev
As discussed with Marek during the LINUX-PITER here is v* patch:
Add option to set spi controller clock frequency via device tree using standard clock bindings.
Define
dw_spi_get_clkfunction as 'weak' as some targets (likeSOCFPGA_GEN5andSOCFPGA_ARRIA10) don't use standard clock API and implementdw_spi_get_clktheir own way in their clock manager.Get rid of
clock_manager.hinclude indesignware_spi.cas we don't usecm_get_spi_controller_clk_hzfunction anymore - we use redefineddw_spi_get_clkin SOCFPGA clock managers (clock_manager_gen5.candclock_manager_arria10.c) instead.Changes
v7->v8:
* Fix typo in comments.Changes
v6->v7:
* Cleanup error handling.
* Don't free clock after we successfully requeste it.Changes
v5->v6:
* Put the clock handle into the private dataChanges
v4->v5:
* Get rid of usless ifdef indw_spi_get_clkfunction
Quoted 9 lines
Eugeniy Paltsev (2):
SOCFPGA: clock manager: implementdw_spi_get_clkfunction DW SPI: Get clock value from Device Treearch/arm/mach-socfpga/clock_manager_arria10.c | 9 +++++ arch/arm/mach-socfpga/clock_manager_gen5.c | 9 +++++ drivers/spi/designware_spi.c | 47 +++++++++++++++++++++++++-- 3 files changed, 63 insertions(+), 2 deletions(-)
Thanks for keeping it up ! And I hope this ends up in after 2018.01 :-) Please keep an eye on these patches and poke in case these patches aren't in after 2018.01 is out ...
btw it was nice talking during Piter, I hope to come back next year too!
Signature · 2 lines
Best regards, Marek Vasut