clk: at91: Add new clock driver
v2 cover clk: at91: Add new clock driver
For CLK uclass add post binding support to recursively bind its children as clk devices.
Add the clock driver for AT91's SoCs.
Changes in v2:
- Remove the redundant log print.
Wenyou Yang (2):
clk: clk-uclass: Add post binding for CLK uclass
clk: at91: Add new clock driver
arch/arm/mach-at91/include/mach/at91_pmc.h | 11 ++- drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/at91/Kconfig | 14 +++ drivers/clk/at91/Makefile | 11 +++ drivers/clk/at91/clk-generated.c | 138 +++++++++++++++++++++++++++++ drivers/clk/at91/clk-h32mx.c | 56 ++++++++++++ drivers/clk/at91/clk-main.c | 55 ++++++++++++ drivers/clk/at91/clk-master.c | 33 +++++++ drivers/clk/at91/clk-peripheral.c | 68 ++++++++++++++ drivers/clk/at91/clk-plla.c | 55 ++++++++++++ drivers/clk/at91/clk-slow.c | 37 ++++++++ drivers/clk/at91/clk-system.c | 65 ++++++++++++++ drivers/clk/at91/clk-utmi.c | 67 ++++++++++++++ drivers/clk/at91/pmc.c | 49 ++++++++++ drivers/clk/at91/pmc.h | 17 ++++ drivers/clk/at91/sckc.c | 30 +++++++ drivers/clk/clk-uclass.c | 51 +++++++++++ 18 files changed, 756 insertions(+), 3 deletions(-) create mode 100644 drivers/clk/at91/Kconfig create mode 100644 drivers/clk/at91/Makefile create mode 100644 drivers/clk/at91/clk-generated.c create mode 100644 drivers/clk/at91/clk-h32mx.c create mode 100644 drivers/clk/at91/clk-main.c create mode 100644 drivers/clk/at91/clk-master.c create mode 100644 drivers/clk/at91/clk-peripheral.c create mode 100644 drivers/clk/at91/clk-plla.c create mode 100644 drivers/clk/at91/clk-slow.c create mode 100644 drivers/clk/at91/clk-system.c create mode 100644 drivers/clk/at91/clk-utmi.c create mode 100644 drivers/clk/at91/pmc.c create mode 100644 drivers/clk/at91/pmc.h create mode 100644 drivers/clk/at91/sckc.c
Signature · 1 line
2.7.4
PATCH v2 1/2 clk: clk-uclass: Add post binding for CLK uclass
Add post binding support for CLK uclass to recursively bind its children as clk devices.
---
Changes in v2: None
drivers/clk/clk-uclass.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
drivers/clk/clk-uclass.c +51 -0
@@ -106,7 +106,58 @@ int clk_get_by_index(struct udevice *dev, int index, struct udevice **clk_devp) }#endif +/** +* clk_post-bind() - post binding for CLK uclass +* Recursively bind its children as clk devices. +* +* @dev: clk device +* @return: 0 on success, or negative error code on failure +*/ +static int clk_post_bind (struct udevice *dev) +{ +const void *fdt = gd->fdt_blob; +int offset = dev->of_offset; +bool pre_reloc_only = !(gd->flags &GD_FLG_RELOC ); +const char *name; +int ret; + +for (offset =fdt_first_subnode (fdt, offset); + offset >0 ; + offset =fdt_next_subnode (fdt, offset)) { +if (pre_reloc_only && + !fdt_getprop (fdt, offset,"u-boot,dm-pre-reloc" ,NULL )) +continue ; +/* +* If this node has "compatible" property, this is not a clk +* node, but a normal device. skip. +*/ +fdt_get_property (fdt, offset,"compatible" , &ret); +if (ret >=0 ) +continue ; + +if (ret != -FDT_ERR_NOTFOUND ) +return ret; + + name =fdt_get_name (fdt, offset,NULL ); +if (!name) +return -EINVAL ; + + ret =device_bind_driver_to_node (dev,"clk" , name, + offset,NULL ); +if (ret) +return ret; + } + +return 0 ; +} +UCLASS_DRIVER (clk) = { .id =UCLASS_CLK , + .post_bind = clk_post_bind, .name ="clk" , }; + +U_BOOT_DRIVER (clk_generic) = { + .id =UCLASS_CLK , + .name ="clk" , +};
Signature · 1 line
2.7.4
PATCH v2 1/2 clk: clk-uclass: Add post binding for CLK uclass
Hi Wenyou,
Quoted 10 lines · Wenyou Yang
Add post binding support for CLK uclass to recursively bind its children as clk devices.
Signed-off-by Wenyou Yang <[email protected]>---
Changes in v2: None
drivers/clk/clk-uclass.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
Can you please explain what this is for? We would normally call dm_scan_fdt_node() for this, but it seems that you are specifically to create drivers for things with no compatible strings.
Quoted 65 lines
drivers/clk/clk-uclass.c +51
-1@@ -106,7 +106,58 @@ int clk_get_by_index(struct udevice *dev, int index, struct udevice **clk_devp) }#endif +/** +* clk_post-bind() - post binding for CLK uclass +* Recursively bind its children as clk devices. +* +* @dev: clk device +* @return: 0 on success, or negative error code on failure +*/ +static int clk_post_bind (struct udevice *dev) +{ +const void *fdt = gd->fdt_blob; +int offset = dev->of_offset; +bool pre_reloc_only = !(gd->flags &GD_FLG_RELOC ); +const char *name; +int ret; + +for (offset =fdt_first_subnode (fdt, offset); + offset >0 ; + offset =fdt_next_subnode (fdt, offset)) { +if (pre_reloc_only && + !fdt_getprop (fdt, offset,"u-boot,dm-pre-reloc" ,NULL )) +continue ; +/* +* If this node has "compatible" property, this is not a clk +* node, but a normal device. skip. +*/ +fdt_get_property (fdt, offset,"compatible" , &ret); +if (ret >=0 ) +continue ; + +if (ret != -FDT_ERR_NOTFOUND ) +return ret; + + name =fdt_get_name (fdt, offset,NULL ); +if (!name) +return -EINVAL ; + + ret =device_bind_driver_to_node (dev,"clk" , name, + offset,NULL ); +if (ret) +return ret; + } + +return 0 ; +} +UCLASS_DRIVER (clk) = { .id =UCLASS_CLK , + .post_bind = clk_post_bind, .name ="clk" , }; + +U_BOOT_DRIVER (clk_generic) = { + .id =UCLASS_CLK , + .name ="clk" , +}; --
Quoted 2 lines
2.7.4
Regards,
Simon
Yang
PATCH v2 1/2 clk: clk-uclass: Add post binding for CLK uclass
Quoted 21 lines
-----Original Message-----
From: sjg at google.com [mailto:sjg at google.com] On Behalf Of Simon Glass
Sent: 2016?6?10? 8:34
To: Yang, Wenyou <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Andreas Bie?mann <[email protected]>
Subject: Re: [PATCH v2 1/2] clk: clk-uclass: Add post binding for CLK uclassHi Wenyou,
Quoted 8 lines · Wenyou Yang
Add post binding support for CLK uclass to recursively bind its children as clk devices.
Signed-off-by Wenyou Yang <[email protected]>---
Changes in v2: None
Quoted 8 lines
Quoted 3 lines
drivers/clk/clk-uclass.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)Can you please explain what this is for? We would normally call
dm_scan_fdt_node()for this, but it seems that you are specifically to create drivers for things with no compatible strings.
Yes, for pheriph32ck node have a lot of child nodes with no compatible strings. This patch purpose is to bind these children nodes. Otherwise these nodes will not be bound.
For example,
---8<----
ahb {
apb {
pmc: pmc@f0014000 {
[snip]
periph32ck {
compatible = "atmel,at91sam9x5-clk-peripheral";
#address-cells = <1>;
#size-cells = <0>;
clocks = <&h32ck>;
macb0_clk: macb0_clk {
#clock-cells = <0>;
reg = <5>;
atmel,clk-output-range = <0 83000000>;
};
[snip]
pioA_clk: pioA_clk {
#clock-cells = <0>;
reg = <18>;
atmel,clk-output-range = <0 83000000>;
};
[snip]
spi0_clk: spi0_clk {
#clock-cells = <0>;
reg = <33>;
atmel,clk-output-range = <0 83000000>;
};
[snip]
};
};
spi0: spi at f8000000 {
compatible = "atmel,at91rm9200-spi";
reg = <0xf8000000 0x100>;
clocks = <&spi0_clk>;
clock-names = "spi_clk";
#address-cells = <1>;
#size-cells = <0>;
status = "disabled";
};
macb0: ethernet at f8008000 {
compatible = "cdns,macb";
reg = <0xf8008000 0x1000>;
#address-cells = <1>;
#size-cells = <0>;
clocks = <&macb0_clk>, <&macb0_clk>;
clock-names = "hclk", "pclk";
status = "disabled";
};
[snip]
pioA: gpio at fc038000 {
compatible = "atmel,sama5d2-gpio";
reg = <0xfc038000 0x600>;
clocks = <&pioA_clk>;
gpio-controller;
#gpio-cells = <2>;
pinctrl {
compatible = "atmel,sama5d2-pinctrl";
};
};
};
};---->8-----
Quoted 68 lines
Quoted 63 lines
drivers/clk/clk-uclass.c index renamed from drivers/clk/clk-uclass.c +0
-0b483c1e..ee568e4 100644
drivers/clk/clk-uclass.c +0
-0@@ -106,7 +106,58 @@ int clk_get_by_index(struct udevice *dev, intindex, struct udevice **clk_devp) } #endif
drivers/clk/clk-uclass.c +49
-1+/** +* clk_post-bind() - post binding for CLK uclass +* Recursively bind its children as clk devices. +* +* @dev: clk device +* @return: 0 on success, or negative error code on failure */ +static int clk_post_bind (struct udevice *dev) { +const void *fdt = gd->fdt_blob; +int offset = dev->of_offset; +bool pre_reloc_only = !(gd->flags &GD_FLG_RELOC ); +const char *name; +int ret; + +for (offset =fdt_first_subnode (fdt, offset); + offset >0 ; + offset =fdt_next_subnode (fdt, offset)) { +if (pre_reloc_only && + !fdt_getprop (fdt, offset,"u-boot,dm-pre-reloc" ,NULL )) +continue ; +/* +* If this node has "compatible" property, this is not a clk +* node, but a normal device. skip. +*/ +fdt_get_property (fdt, offset,"compatible" , &ret); +if (ret >=0 ) +continue ; + +if (ret != -FDT_ERR_NOTFOUND ) +return ret; + + name =fdt_get_name (fdt, offset,NULL ); +if (!name) +return -EINVAL ; + + ret =device_bind_driver_to_node (dev,"clk" , name, + offset,NULL ); +if (ret) +return ret; + } + +return 0 ; +} +UCLASS_DRIVER (clk) = { .id =UCLASS_CLK , + .post_bind = clk_post_bind, .name ="clk" , }; + +U_BOOT_DRIVER (clk_generic) = { + .id =UCLASS_CLK , + .name ="clk" , +}; --Quoted 2 lines
2.7.4
Regards,
Simon
PATCH v2 1/2 clk: clk-uclass: Add post binding for CLK uclass
Hi Wenyou,
Quoted 110 lines · Wenyou
Quoted 21 lines
-----Original Message-----
From: sjg at google.com [mailto:sjg at google.com] On Behalf Of Simon Glass
Sent: 2016?6?10? 8:34
To: Yang, Wenyou <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Andreas Bie?mann <[email protected]>
Subject: Re: [PATCH v2 1/2] clk: clk-uclass: Add post binding for CLK uclassHi Wenyou,
Quoted 8 lines · Wenyou Yang
Add post binding support for CLK uclass to recursively bind its children as clk devices.
Signed-off-by Wenyou Yang <[email protected]>---
Changes in v2: None
Quoted 8 lines
Quoted 3 lines
drivers/clk/clk-uclass.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)Can you please explain what this is for? We would normally call
dm_scan_fdt_node()for this, but it seems that you are specifically to create drivers for things with no compatible strings.Yes, for pheriph32ck node have a lot of child nodes with no compatible strings. This patch purpose is to bind these children nodes. Otherwise these nodes will not be bound.
For example,
---8<----
ahb { apb { pmc: pmc at f0014000 { [snip] periph32ck { compatible = "atmel,at91sam9x5-clk-peripheral"; #address-cells = <1>; #size-cells = <0>; clocks = <&h32ck>; macb0_clk: macb0_clk { #clock-cells = <0>; reg = <5>; atmel,clk-output-range = <0 83000000>; }; [snip] pioA_clk: pioA_clk { #clock-cells = <0>; reg = <18>; atmel,clk-output-range = <0 83000000>; }; [snip] spi0_clk: spi0_clk { #clock-cells = <0>; reg = <33>; atmel,clk-output-range = <0 83000000>; }; [snip] }; }; spi0: spi at f8000000 { compatible = "atmel,at91rm9200-spi"; reg = <0xf8000000 0x100>; clocks = <&spi0_clk>; clock-names = "spi_clk"; #address-cells = <1>; #size-cells = <0>; status = "disabled"; }; macb0: ethernet at f8008000 { compatible = "cdns,macb"; reg = <0xf8008000 0x1000>; #address-cells = <1>; #size-cells = <0>; clocks = <&macb0_clk>, <&macb0_clk>; clock-names = "hclk", "pclk"; status = "disabled"; }; [snip] pioA: gpio at fc038000 { compatible = "atmel,sama5d2-gpio"; reg = <0xfc038000 0x600>; clocks = <&pioA_clk>; gpio-controller; #gpio-cells = <2>; pinctrl { compatible = "atmel,sama5d2-pinctrl"; }; }; }; };
Quoted 2 lines
---->8-----
In that case I think your clock driver should handle this in its bind() method. It can scan the device tree and create the devices as needed. I don't think this feature should go into generic code, at least not yet.
Also please see Stephen Warren's clock patch, which supports multiple clock IDs per clock device. Assuming he respins this soon I will be applying it to dm/master.
http://patchwork.ozlabs.org/patch/625342/
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
drivers/clk/clk-uclass.c index renamed from drivers/clk/clk-uclass.c +0
-0b483c1e..ee568e4 100644
drivers/clk/clk-uclass.c +0
-0@@ -106,7 +106,58 @@ int clk_get_by_index(struct udevice *dev, intindex, struct udevice **clk_devp) } #endif
drivers/clk/clk-uclass.c +44
-0+/** +* clk_post-bind() - post binding for CLK uclass +* Recursively bind its children as clk devices. +* +* @dev: clk device +* @return: 0 on success, or negative error code on failure */ +static int clk_post_bind (struct udevice *dev) { +const void *fdt = gd->fdt_blob; +int offset = dev->of_offset; +bool pre_reloc_only = !(gd->flags &GD_FLG_RELOC ); +const char *name; +int ret; + +for (offset =fdt_first_subnode (fdt, offset); + offset >0 ; + offset =fdt_next_subnode (fdt, offset)) { +if (pre_reloc_only && + !fdt_getprop (fdt, offset,"u-boot,dm-pre-reloc" ,NULL )) +continue ; +/* +* If this node has "compatible" property, this is not a clk +* node, but a normal device. skip. +*/ +fdt_get_property (fdt, offset,"compatible" , &ret); +if (ret >=0 ) +continue ; + +if (ret != -FDT_ERR_NOTFOUND ) +return ret; + + name =fdt_get_name (fdt, offset,NULL ); +if (!name) +return -EINVAL ; + + ret =device_bind_driver_to_node (dev,"clk" , name, + offset,NULL ); +if (ret) +return ret; + } + +return 0 ; +} +UCLASS_DRIVER (clk) = { .id =UCLASS_CLK , + .post_bind = clk_post_bind, .name ="clk" , };
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/clk/clk-uclass.c +5
-1+ +U_BOOT_DRIVER (clk_generic) = { + .id =UCLASS_CLK , + .name ="clk" , +}; --2.7.4
Regards,
Simon
Yang
PATCH v2 1/2 clk: clk-uclass: Add post binding for CLK uclass
HI Simon,
Quoted 123 lines
-----Original Message-----
From: sjg at google.com [mailto:sjg at google.com] On Behalf Of Simon Glass
Sent: 2016?6?16? 10:44
To: Yang, Wenyou <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Andreas Bie?mann <[email protected]>
Subject: Re: [PATCH v2 1/2] clk: clk-uclass: Add post binding for CLK uclassHi Wenyou,
Quoted 27 lines · Wenyou
Quoted 27 lines
-----Original Message-----
From: sjg at google.com [mailto:sjg at google.com] On Behalf Of Simon Glass
Sent: 2016?6?10? 8:34
To: Yang, Wenyou <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Andreas Bie?mann <[email protected]>
Subject: Re: [PATCH v2 1/2] clk: clk-uclass: Add post binding for CLK uclassHi Wenyou,
Quoted 11 lines · Wenyou Yang
Add post binding support for CLK uclass to recursively bind its children as clk devices.
Signed-off-by Wenyou Yang <[email protected]>---
Changes in v2: None
drivers/clk/clk-uclass.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)Quoted 6 lines
Quoted 3 lines
Can you please explain what this is for? We would normally call
dm_scan_fdt_node()for this, but it seems that you are specifically to create drivers for things with no compatible strings.Yes, for pheriph32ck node have a lot of child nodes with no compatible strings. This patch purpose is to bind these children nodes. Otherwise these nodes will
not be bound.
Quoted 78 lines
For example,
---8<----
ahb { apb { pmc: pmc at f0014000 { [snip] periph32ck { compatible = "atmel,at91sam9x5-clk-peripheral"; #address-cells = <1>; #size-cells = <0>; clocks = <&h32ck>; macb0_clk: macb0_clk { #clock-cells = <0>; reg = <5>; atmel,clk-output-range = <0 83000000>; }; [snip] pioA_clk: pioA_clk { #clock-cells = <0>; reg = <18>; atmel,clk-output-range = <0 83000000>; }; [snip] spi0_clk: spi0_clk { #clock-cells = <0>; reg = <33>; atmel,clk-output-range = <0 83000000>; }; [snip] }; }; spi0: spi at f8000000 { compatible = "atmel,at91rm9200-spi"; reg = <0xf8000000 0x100>; clocks = <&spi0_clk>; clock-names = "spi_clk"; #address-cells = <1>; #size-cells = <0>; status = "disabled"; }; macb0: ethernet at f8008000 { compatible = "cdns,macb"; reg = <0xf8008000 0x1000>; #address-cells = <1>; #size-cells = <0>; clocks = <&macb0_clk>, <&macb0_clk>; clock-names = "hclk", "pclk"; status = "disabled"; }; [snip] pioA: gpio at fc038000 { compatible = "atmel,sama5d2-gpio"; reg = <0xfc038000 0x600>; clocks = <&pioA_clk>; gpio-controller; #gpio-cells = <2>; pinctrl { compatible = "atmel,sama5d2-pinctrl"; }; }; }; };
Quoted 6 lines
Quoted 2 lines
---->8-----
In that case I think your clock driver should handle this in its
bind()method. It can scan the device tree and create the devices as needed. I don't think this feature should go into generic code, at least not yet.
Okay, I will move it to our clock driver.
Quoted 5 lines
Also please see Stephen Warren's clock patch, which supports multiple clock IDs per clock device. Assuming he respins this soon I will be applying it to dm/master.
Thank you for your reminder.
Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
drivers/clk/clk-uclass.c +0
-0index
b483c1e..ee568e4 100644drivers/clk/clk-uclass.c +0
-0@@ -106,7 +106,58 @@ int clk_get_by_index(struct udevice *dev, intindex, struct udevice **clk_devp) } #endif
drivers/clk/clk-uclass.c +47
-0+/** +* clk_post-bind() - post binding for CLK uclass +* Recursively bind its children as clk devices. +* +* @dev: clk device +* @return: 0 on success, or negative error code on failure */ +static int clk_post_bind (struct udevice *dev) { +const void *fdt = gd->fdt_blob; +int offset = dev->of_offset; +bool pre_reloc_only = !(gd->flags &GD_FLG_RELOC ); +const char *name; +int ret; + +for (offset =fdt_first_subnode (fdt, offset); + offset >0 ; + offset =fdt_next_subnode (fdt, offset)) { +if (pre_reloc_only && + !fdt_getprop (fdt, offset,"u-boot,dm-pre-reloc" ,NULL )) +continue ; +/* +* If this node has "compatible" property, this is not a clk +* node, but a normal device. skip. +*/ +fdt_get_property (fdt, offset,"compatible" , &ret); +if (ret >=0 ) +continue ; + +if (ret != -FDT_ERR_NOTFOUND ) +return ret; + + name =fdt_get_name (fdt, offset,NULL ); +if (!name) +return -EINVAL ; + + ret =device_bind_driver_to_node (dev,"clk" , name, + offset,NULL ); +if (ret) +return ret; + } + +return 0 ; +} +UCLASS_DRIVER (clk) = { .id =UCLASS_CLK , + .post_bind = clk_post_bind, .name ="clk" , }; + +U_BOOT_DRIVER (clk_generic) = { + .id =UCLASS_CLK ,
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/clk/clk-uclass.c +2
-1+ .name = "clk", +}; --2.7.4
Regards,
Simon
Best Regards,
Wenyou Yang
PATCH v2 2/2 clk: at91: Add new clock driver
In reply to Wenyou YangThe patch is referred to at91 clock driver of Linux, to make the clock node descriptions in dt are aligned with the Linux.
---
Changes in v2:
- Remove the redundant log print.
arch/arm/mach-at91/include/mach/at91_pmc.h | 11 ++- drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/at91/Kconfig | 14 +++ drivers/clk/at91/Makefile | 11 +++ drivers/clk/at91/clk-generated.c | 138 +++++++++++++++++++++++++++++ drivers/clk/at91/clk-h32mx.c | 56 ++++++++++++ drivers/clk/at91/clk-main.c | 55 ++++++++++++ drivers/clk/at91/clk-master.c | 33 +++++++ drivers/clk/at91/clk-peripheral.c | 68 ++++++++++++++ drivers/clk/at91/clk-plla.c | 55 ++++++++++++ drivers/clk/at91/clk-slow.c | 37 ++++++++ drivers/clk/at91/clk-system.c | 65 ++++++++++++++ drivers/clk/at91/clk-utmi.c | 67 ++++++++++++++ drivers/clk/at91/pmc.c | 49 ++++++++++ drivers/clk/at91/pmc.h | 17 ++++ drivers/clk/at91/sckc.c | 30 +++++++ 17 files changed, 705 insertions(+), 3 deletions(-) create mode 100644 drivers/clk/at91/Kconfig create mode 100644 drivers/clk/at91/Makefile create mode 100644 drivers/clk/at91/clk-generated.c create mode 100644 drivers/clk/at91/clk-h32mx.c create mode 100644 drivers/clk/at91/clk-main.c create mode 100644 drivers/clk/at91/clk-master.c create mode 100644 drivers/clk/at91/clk-peripheral.c create mode 100644 drivers/clk/at91/clk-plla.c create mode 100644 drivers/clk/at91/clk-slow.c create mode 100644 drivers/clk/at91/clk-system.c create mode 100644 drivers/clk/at91/clk-utmi.c create mode 100644 drivers/clk/at91/pmc.c create mode 100644 drivers/clk/at91/pmc.h create mode 100644 drivers/clk/at91/sckc.c
arch/arm/mach-at91/include/mach/at91_pmc.h +8 -3
@@ -149,6 +149,9 @@ typedef struct at91_pmc {#define AT91_PMC_PCR_PID_MASK (0x3f)#define AT91_PMC_PCR_GCKCSS (0x7 << 8) +#define AT91_PMC_PCR_GCKCSS_MASK 0x07 +#define AT91_PMC_PCR_GCKCSS_OFFSET 8 +#define AT91_PMC_PCR_GCKCSS_ (x) ((x & 0x07) << 8)#define AT91_PMC_PCR_GCKCSS_SLOW_CLK (0x0 << 8)#define AT91_PMC_PCR_GCKCSS_MAIN_CLK (0x1 << 8)#define AT91_PMC_PCR_GCKCSS_PLLA_CLK (0x2 << 8)
@@ -158,8 +161,9 @@ typedef struct at91_pmc {#define AT91_PMC_PCR_CMD_WRITE (0x1 << 12)#define AT91_PMC_PCR_DIV (0x3 << 16)#define AT91_PMC_PCR_GCKDIV (0xff << 20) -#define AT91_PMC_PCR_GCKDIV_ (x) ((x & 0xff) << 20) -#define AT91_PMC_PCR_GCKDIV_OFFSET 20 +#define AT91_PMC_PCR_GCKDIV_MASK 0xff +#define AT91_PMC_PCR_GCKDIV_OFFSET 20 +#define AT91_PMC_PCR_GCKDIV_ (x) ((x & 0xff) << 20)#define AT91_PMC_PCR_EN (0x1 << 28)#define AT91_PMC_PCR_GCKEN (0x1 << 29)
@@ -243,8 +247,9 @@ typedef struct at91_pmc {#define AT91_PMC_PCK1RDY (1 << 9)/* Programmable Clock 1 */ #define AT91_PMC_PCK2RDY (1 << 10)/* Programmable Clock 2 */ #define AT91_PMC_PCK3RDY (1 << 11)/* Programmable Clock 3 */ +#define AT91_PMC_MOSCSELS BIT(16)/* Main Oscillator Selection Status */ +#define AT91_PMC_MOSCRCS BIT(17)/* 12 MHz RC Oscillator Status */ #define AT91_PMC_GCKRDY (1 << 24) -#define AT91_PMC_PROTKEY 0x504d4301/* Activation Code */ /* PLL Charge Pump Current Register (PMC_PLLICPR) */
drivers/clk/Kconfig +1 -0
@@ -21,5 +21,6 @@ config SPL_CLK used as U-Boot proper. source "drivers/clk/uniphier/Kconfig" +source "drivers/clk/at91/Kconfig" endmenu
drivers/clk/Makefile +1 -0
@@ -11,3 +11,4 @@ obj-$(CONFIG_ROCKCHIP_RK3288) += clk_rk3288.o obj-$(CONFIG_SANDBOX) += clk_sandbox.o obj-$(CONFIG_MACH_PIC32) += clk_pic32.o obj-$(CONFIG_CLK_UNIPHIER) += uniphier/ +obj-$(CONFIG_CLK_AT91) += at91/
drivers/clk/at91/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +config CLK_AT91 + bool "AT91 clock drivers" + depends on CLK + help + This option is used to enable the AT91 clock driver. + +config HAVE_AT91_UTMI + bool + +config HAVE_AT91_H32MX + bool + +config HAVE_AT91_GENERATED_CLK + bool
drivers/clk/at91/Makefile new file +11 -0
@@ -0,0 +1,11 @@ +# +# Makefile for at91 specific clk +# + +obj-y += pmc.o sckc.o +obj-y += clk-slow.o clk-main.o clk-plla.o clk-master.o +obj-y += clk-system.o clk-peripheral.o + +obj-$(CONFIG_HAVE_AT91_UTMI) += clk-utmi.o +obj-$(CONFIG_HAVE_AT91_H32MX) += clk-h32mx.o +obj-$(CONFIG_HAVE_AT91_GENERATED_CLK) += clk-generated.o
drivers/clk/at91/clk-generated.c new file +138 -0
138 lines not on this page · raw message
drivers/clk/at91/clk-h32mx.c new file +56 -0
56 lines not on this page · raw message
drivers/clk/at91/clk-main.c new file +55 -0
55 lines not on this page · raw message
drivers/clk/at91/clk-master.c new file +33 -0
@@ -0,0 +1,33 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> + +DECLARE_GLOBAL_DATA_PTR ; + +static ulong at91_master_clk_get_rate (struct udevice *dev) +{ +return gd->arch.mck_rate_hz; +} + +static struct clk_ops at91_master_clk_ops = { + .get_rate = at91_master_clk_get_rate, +}; + +static const struct udevice_id at91_master_clk_match[] = { + { .compatible ="atmel,at91sam9x5-clk-master" }, + {} +}; + +U_BOOT_DRIVER (at91_master_clk) = { + .name ="at91-master-clk" , + .id =UCLASS_CLK , + .of_match = at91_master_clk_match, + .ops = &at91_master_clk_ops, +};
drivers/clk/at91/clk-peripheral.c new file +68 -0
68 lines not on this page · raw message
drivers/clk/at91/clk-plla.c new file +55 -0
55 lines not on this page · raw message
drivers/clk/at91/clk-slow.c new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> + +static int at91_slow_clk_enable (struct udevice *dev,int periph) +{ +return 0 ; +} + +static ulong at91_slow_clk_get_rate (struct udevice *dev) +{ +return CONFIG_SYS_AT91_SLOW_CLOCK ; +} + +static struct clk_ops at91_slow_clk_ops = { + .enable = at91_slow_clk_enable, + .get_rate = at91_slow_clk_get_rate, +}; + +static const struct udevice_id at91_slow_clk_match[] = { + { .compatible ="atmel,at91sam9x5-clk-slow" }, + {} +}; + +U_BOOT_DRIVER (at91_slow_clk) = { + .name ="at91-slow-clk" , + .id =UCLASS_CLK , + .of_match = at91_slow_clk_match, + .ops = &at91_slow_clk_ops, +};
drivers/clk/at91/clk-system.c new file +65 -0
65 lines not on this page · raw message
drivers/clk/at91/clk-utmi.c new file +67 -0
67 lines not on this page · raw message
drivers/clk/at91/pmc.c new file +49 -0
49 lines not on this page · raw message
drivers/clk/at91/pmc.h new file +17 -0
@@ -0,0 +1,17 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __AT91_PMC_H__ +#define __AT91_PMC_H__ + +struct pmc_platdata { +struct at91_pmc *reg_base; +}; + +int at91_pmc_core_probe (struct udevice *dev); + +#endif
drivers/clk/at91/sckc.c new file +30 -0
@@ -0,0 +1,30 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <dm/root.h> + +DECLARE_GLOBAL_DATA_PTR ; + +static int at91_sckc_clk_bind (struct udevice *dev) +{ +return dm_scan_fdt_node (dev, gd->fdt_blob, dev->of_offset, false); +} + +static const struct udevice_id at91_sckc_clk_match[] = { + { .compatible ="atmel,at91sam9x5-sckc" }, + {} +}; + +U_BOOT_DRIVER (at91_sckc_clk) = { + .name ="at91_sckc_clk" , + .id =UCLASS_CLK , + .of_match = at91_sckc_clk_match, + .bind = at91_sckc_clk_bind, +};
Signature · 1 line
2.7.4
PATCH v2 2/2 clk: at91: Add new clock driver
+Stephen
Hi Wenyou,
Quoted 109 lines · Wenyou Yang
The patch is referred to at91 clock driver of Linux, to make the clock node descriptions in dt are aligned with the Linux.
Signed-off-by Wenyou Yang <[email protected]>---
Changes in v2:
- Remove the redundant log print.arch/arm/mach-at91/include/mach/at91_pmc.h | 11 ++- drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/at91/Kconfig | 14 +++ drivers/clk/at91/Makefile | 11 +++ drivers/clk/at91/clk-generated.c | 138 +++++++++++++++++++++++++++++ drivers/clk/at91/clk-h32mx.c | 56 ++++++++++++ drivers/clk/at91/clk-main.c | 55 ++++++++++++ drivers/clk/at91/clk-master.c | 33 +++++++ drivers/clk/at91/clk-peripheral.c | 68 ++++++++++++++ drivers/clk/at91/clk-plla.c | 55 ++++++++++++ drivers/clk/at91/clk-slow.c | 37 ++++++++ drivers/clk/at91/clk-system.c | 65 ++++++++++++++ drivers/clk/at91/clk-utmi.c | 67 ++++++++++++++ drivers/clk/at91/pmc.c | 49 ++++++++++ drivers/clk/at91/pmc.h | 17 ++++ drivers/clk/at91/sckc.c | 30 +++++++ 17 files changed, 705 insertions(+), 3 deletions(-) create mode 100644 drivers/clk/at91/Kconfig create mode 100644 drivers/clk/at91/Makefile create mode 100644 drivers/clk/at91/clk-generated.c create mode 100644 drivers/clk/at91/clk-h32mx.c create mode 100644 drivers/clk/at91/clk-main.c create mode 100644 drivers/clk/at91/clk-master.c create mode 100644 drivers/clk/at91/clk-peripheral.c create mode 100644 drivers/clk/at91/clk-plla.c create mode 100644 drivers/clk/at91/clk-slow.c create mode 100644 drivers/clk/at91/clk-system.c create mode 100644 drivers/clk/at91/clk-utmi.c create mode 100644 drivers/clk/at91/pmc.c create mode 100644 drivers/clk/at91/pmc.h create mode 100644 drivers/clk/at91/sckc.carch/arm/mach-at91/include/mach/at91_pmc.h +8
-3@@ -149,6 +149,9 @@ typedef struct at91_pmc {#define AT91_PMC_PCR_PID_MASK (0x3f)#define AT91_PMC_PCR_GCKCSS (0x7 << 8) +#define AT91_PMC_PCR_GCKCSS_MASK 0x07 +#define AT91_PMC_PCR_GCKCSS_OFFSET 8 +#define AT91_PMC_PCR_GCKCSS_ (x) ((x & 0x07) << 8)#define AT91_PMC_PCR_GCKCSS_SLOW_CLK (0x0 << 8)#define AT91_PMC_PCR_GCKCSS_MAIN_CLK (0x1 << 8)#define AT91_PMC_PCR_GCKCSS_PLLA_CLK (0x2 << 8)@@ -158,8 +161,9 @@ typedef struct at91_pmc {#define AT91_PMC_PCR_CMD_WRITE (0x1 << 12)#define AT91_PMC_PCR_DIV (0x3 << 16)#define AT91_PMC_PCR_GCKDIV (0xff << 20) -#define AT91_PMC_PCR_GCKDIV_ (x) ((x & 0xff) << 20) -#define AT91_PMC_PCR_GCKDIV_OFFSET 20 +#define AT91_PMC_PCR_GCKDIV_MASK 0xff +#define AT91_PMC_PCR_GCKDIV_OFFSET 20 +#define AT91_PMC_PCR_GCKDIV_ (x) ((x & 0xff) << 20)#define AT91_PMC_PCR_EN (0x1 << 28)#define AT91_PMC_PCR_GCKEN (0x1 << 29)@@ -243,8 +247,9 @@ typedef struct at91_pmc {#define AT91_PMC_PCK1RDY (1 << 9)/* Programmable Clock 1 */ #define AT91_PMC_PCK2RDY (1 << 10)/* Programmable Clock 2 */ #define AT91_PMC_PCK3RDY (1 << 11)/* Programmable Clock 3 */ +#define AT91_PMC_MOSCSELS BIT(16)/* Main Oscillator Selection Status */ +#define AT91_PMC_MOSCRCS BIT(17)/* 12 MHz RC Oscillator Status */ #define AT91_PMC_GCKRDY (1 << 24) -#define AT91_PMC_PROTKEY 0x504d4301/* Activation Code */ /* PLL Charge Pump Current Register (PMC_PLLICPR) */ drivers/clk/Kconfig +1
-0@@ -21,5 +21,6 @@ config SPL_CLK used as U-Boot proper. source "drivers/clk/uniphier/Kconfig" +source "drivers/clk/at91/Kconfig" endmenudrivers/clk/Makefile +1
-0@@ -11,3 +11,4 @@ obj-$(CONFIG_ROCKCHIP_RK3288) += clk_rk3288.o obj-$(CONFIG_SANDBOX) += clk_sandbox.o obj-$(CONFIG_MACH_PIC32) += clk_pic32.o obj-$(CONFIG_CLK_UNIPHIER) += uniphier/ +obj-$(CONFIG_CLK_AT91) += at91/drivers/clk/at91/Kconfig new file +4
-0@@ -0,0 +1,14 @@ +config CLK_AT91 + bool "AT91 clock drivers" + depends on CLK + help
drivers/clk/at91/Kconfig line 14
Quoted 10 lines
drivers/clk/at91/Kconfig new file +10
-0+ This option is used to enable the AT91 clock driver. + +config HAVE_AT91_UTMI + bool + +config HAVE_AT91_H32MX + bool + +config HAVE_AT91_GENERATED_CLK + bool
Please can you add help?
Also we are changing the clock interface - please see this patch:
http://patchwork.ozlabs.org/patch/625342/
I'm hoping to bring it in next week.
Quoted 73 lines
drivers/clk/at91/Makefile new file +11
-0@@ -0,0 +1,11 @@ +# +# Makefile for at91 specific clk +# + +obj-y += pmc.o sckc.o +obj-y += clk-slow.o clk-main.o clk-plla.o clk-master.o +obj-y += clk-system.o clk-peripheral.o + +obj-$(CONFIG_HAVE_AT91_UTMI) += clk-utmi.o +obj-$(CONFIG_HAVE_AT91_H32MX) += clk-h32mx.o +obj-$(CONFIG_HAVE_AT91_GENERATED_CLK) += clk-generated.odrivers/clk/at91/clk-generated.c new file +50
-0@@ -0,0 +1,138 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <linux/io.h> +#include <mach/at91_pmc.h> +#include "pmc.h" + +DECLARE_GLOBAL_DATA_PTR ; + +#define GENERATED_SOURCE_MAX 6 +#define GENERATED_MAX_DIV 255 + +static ulong generated_clk_get_periph_rate (struct udevice *dev,int periph) +{ +struct pmc_platdata *plat =dev_get_platdata (dev); +struct at91_pmc *pmc = plat->reg_base; +struct udevice *parent; +u32 tmp, gckdiv; +u8 parent_id; +int ret; + +writel (periph &AT91_PMC_PCR_PID_MASK , &pmc->pcr); + tmp =readl (&pmc->pcr); + parent_id = (tmp >>AT91_PMC_PCR_GCKCSS_OFFSET ) & +AT91_PMC_PCR_GCKCSS_MASK ; + gckdiv = (tmp >>AT91_PMC_PCR_GCKDIV_OFFSET ) &AT91_PMC_PCR_GCKDIV_MASK ; + + ret =clk_get_by_index (dev, parent_id, &parent); +if (ret) +return 0 ; + +return clk_get_rate (parent) / (gckdiv +1 ); +} + +static ulong generated_clk_set_periph_rate (struct udevice *dev, +int periph, +ulong rate) +{ +struct pmc_platdata *plat =dev_get_platdata (dev); +struct at91_pmc *pmc = plat->reg_base; +struct udevice *parent, *best_parent =NULL ; +ulong tmp_rate, best_rate = rate, parent_rate; +int tmp_diff, best_diff =-1 ;
drivers/clk/at91/clk-generated.c line 60
Quoted 10 lines
drivers/clk/at91/clk-generated.c new file +10
-0+u8 num_parents, i; +u32 cells[GENERATED_SOURCE_MAX ]; +u32 div, best_div =0 ; +u8 best_parent_id =0 ; +u32 tmp; +int ret; + + num_parents =fdtdec_get_int_array_count (gd->fdt_blob, dev->of_offset, +"clocks" , cells, +GENERATED_SOURCE_MAX );
Are you able to store this value in your priv data in your of_to_platdata() method? We should not be looking at the device tree outside that method.
Quoted 161 lines
drivers/clk/at91/clk-generated.c new file +78
-0+ +for (i =0 ; i < num_parents; i++) { + ret =clk_get_by_index (dev, i, &parent); +if (ret) +return ret; + + parent_rate =clk_get_rate (parent); +if (!parent_rate) +return -ENODEV ; + +for (div =1 ; div <GENERATED_MAX_DIV +2 ; div++) { + tmp_rate =DIV_ROUND_CLOSEST (parent_rate, div); +if (rate < tmp_rate) +continue ; + tmp_diff = rate - tmp_rate; + +if (best_diff <0 || best_diff > tmp_diff) { + best_rate = tmp_rate; + best_diff = tmp_diff; + + best_div = div -1 ; + best_parent = parent; + best_parent_id = i; + } + +if (!best_diff || tmp_rate < rate) +break ; + } + +if (!best_diff) +break ; + } + +dev_dbg (dev,"GCK: best parent: %s, best_rate = %ld, best_div = %d\n" , + best_parent->name, best_rate, best_div); + + ret =clk_enable (best_parent,0 ); +if (ret) +return -ENODEV ; + +writel (periph &AT91_PMC_PCR_PID_MASK , &pmc->pcr); + tmp =readl (&pmc->pcr); + tmp &= ~(AT91_PMC_PCR_GCKDIV |AT91_PMC_PCR_GCKCSS ); + tmp |=AT91_PMC_PCR_GCKCSS_ (best_parent_id) | +AT91_PMC_PCR_CMD_WRITE | +AT91_PMC_PCR_GCKDIV_ (best_div) | +AT91_PMC_PCR_GCKEN ; +writel (tmp, &pmc->pcr); + +while (!(readl (&pmc->sr) &AT91_PMC_GCKRDY )) + ; + +return 0 ; +} + +static struct clk_ops generated_clk_ops = { + .get_periph_rate = generated_clk_get_periph_rate, + .set_periph_rate = generated_clk_set_periph_rate, +}; + +static int generated_clk_probe (struct udevice *dev) +{ +return at91_pmc_core_probe (dev); +} + +static const struct udevice_id generated_clk_match[] = { + { .compatible ="atmel,sama5d2-clk-generated" }, + {} +}; + +U_BOOT_DRIVER (generated_clk) = { + .name ="generated-clk" , + .id =UCLASS_CLK , + .of_match = generated_clk_match, + .probe = generated_clk_probe, + .platdata_auto_alloc_size =sizeof (struct pmc_platdata ), + .ops = &generated_clk_ops, +};drivers/clk/at91/clk-h32mx.c new file +56
-0@@ -0,0 +1,56 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <dm/util.h> +#include <linux/io.h> +#include <mach/at91_pmc.h> +#include "pmc.h" + +DECLARE_GLOBAL_DATA_PTR ; + +#define H32MX_MAX_FREQ 90000000 + +static ulong sama5d4_h32mx_clk_get_rate (struct udevice *dev) +{ +struct pmc_platdata *plat =dev_get_platdata (dev); +struct at91_pmc *pmc = plat->reg_base; +ulong rate = gd->arch.mck_rate_hz; + +if (readl (&pmc->mckr) &AT91_PMC_MCKR_H32MXDIV ) + rate /=2 ; + +if (rate >H32MX_MAX_FREQ ) +dm_warn ("H32MX clock is too fast\n" ); + +return rate; +} + +static struct clk_ops sama5d4_h32mx_clk_ops = { + .get_rate = sama5d4_h32mx_clk_get_rate, +}; + +static int sama5d4_h32mx_clk_probe (struct udevice *dev) +{ +return at91_pmc_core_probe (dev); +} + +static const struct udevice_id sama5d4_h32mx_clk_match[] = { + { .compatible ="atmel,sama5d4-clk-h32mx" }, + {} +}; + +U_BOOT_DRIVER (sama5d4_h32mx_clk) = { + .name ="sama5d4-h32mx-clk" , + .id =UCLASS_CLK , + .of_match = sama5d4_h32mx_clk_match, + .probe = sama5d4_h32mx_clk_probe, + .platdata_auto_alloc_size =sizeof (struct pmc_platdata ), + .ops = &sama5d4_h32mx_clk_ops, +};drivers/clk/at91/clk-main.c new file +15
-0@@ -0,0 +1,55 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <linux/io.h> +#include <mach/at91_pmc.h> +#include "pmc.h" + +DECLARE_GLOBAL_DATA_PTR ;
drivers/clk/at91/clk-main.c line 25
Quoted 10 lines
drivers/clk/at91/clk-main.c new file +10
-0+ +static int main_osc_clk_enable (struct udevice *dev,int periph) +{ +struct pmc_platdata *plat =dev_get_platdata (dev); +struct at91_pmc *pmc = plat->reg_base; + +if (readl (&pmc->sr) &AT91_PMC_MOSCSELS ) +return 0 ; + +return -ENODEV ;
This error indicates that there is no device. But it looks like there is. What are you trying to represent here?
Quoted 107 lines
drivers/clk/at91/clk-main.c new file +30
-0+} + +static ulong main_osc_clk_get_rate (struct udevice *dev) +{ +return gd->arch.main_clk_rate_hz; +} + +static struct clk_ops main_osc_clk_ops = { + .enable = main_osc_clk_enable, + .get_rate = main_osc_clk_get_rate, +}; + +static int main_osc_clk_probe (struct udevice *dev) +{ +return at91_pmc_core_probe (dev); +} + +static const struct udevice_id main_osc_clk_match[] = { + { .compatible ="atmel,at91sam9x5-clk-main" }, + {} +}; + +U_BOOT_DRIVER (at91sam9x5_main_osc_clk) = { + .name ="at91sam9x5-main-osc-clk" , + .id =UCLASS_CLK , + .of_match = main_osc_clk_match, + .probe = main_osc_clk_probe, + .platdata_auto_alloc_size =sizeof (struct pmc_platdata ), + .ops = &main_osc_clk_ops, +};drivers/clk/at91/clk-master.c new file +33
-0@@ -0,0 +1,33 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> + +DECLARE_GLOBAL_DATA_PTR ; + +static ulong at91_master_clk_get_rate (struct udevice *dev) +{ +return gd->arch.mck_rate_hz; +} + +static struct clk_ops at91_master_clk_ops = { + .get_rate = at91_master_clk_get_rate, +}; + +static const struct udevice_id at91_master_clk_match[] = { + { .compatible ="atmel,at91sam9x5-clk-master" }, + {} +}; + +U_BOOT_DRIVER (at91_master_clk) = { + .name ="at91-master-clk" , + .id =UCLASS_CLK , + .of_match = at91_master_clk_match, + .ops = &at91_master_clk_ops, +};drivers/clk/at91/clk-peripheral.c new file +32
-0@@ -0,0 +1,68 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <linux/io.h> +#include <mach/at91_pmc.h> +#include "pmc.h" + +#define PERIPHERAL_MAX 64 + +#define PERIPHERAL_AT91RM9200 0 +#define PERIPHERAL_AT91SAM9X5 1 + +#define PERIPHERAL_ID_MIN 2 +#define PERIPHERAL_ID_MAX 31 +#define PERIPHERAL_MASK (id) (1 << ((id) & PERIPHERAL_ID_MAX)) + +#define PERIPHERAL_RSHIFT_MASK 0x3 +#define PERIPHERAL_RSHIFT (val) (((val) >> 16) & PERIPHERAL_RSHIFT_MASK) + +#define PERIPHERAL_MAX_SHIFT 3 + +static int sam9x5_periph_clk_enable (struct udevice *dev,int periph) +{ +struct pmc_platdata *plat =dev_get_platdata (dev); +struct at91_pmc *pmc = plat->reg_base;
drivers/clk/at91/clk-peripheral.c line 42
Quoted 10 lines
drivers/clk/at91/clk-peripheral.c new file +10
-0+u32 tmp; + +if (periph <PERIPHERAL_ID_MIN ) +return -1 ; + +writel (periph &AT91_PMC_PCR_PID_MASK , &pmc->pcr); + tmp =readl (&pmc->pcr); +writel (tmp | +AT91_PMC_PCR_CMD_WRITE | +AT91_PMC_PCR_EN , &pmc->pcr);
Or use setbits_le32(&pmc->pcr, AT91_PMC_PCR_CMD_WRITE | AT91_PMC_PCR_EN)
Quoted 47 lines
drivers/clk/at91/clk-peripheral.c new file +26
-0+ +return 0 ; +} + +static struct clk_ops sam9x5_periph_clk_ops = { + .enable = sam9x5_periph_clk_enable, +}; + +static int sam9x5_periph_clk_probe (struct udevice *dev) +{ +return at91_pmc_core_probe (dev); +} + +static const struct udevice_id sam9x5_periph_clk_match[] = { + { .compatible ="atmel,at91sam9x5-clk-peripheral" }, + {} +}; + +U_BOOT_DRIVER (sam9x5_periph_clk) = { + .name ="sam9x5-periph-clk" , + .id =UCLASS_CLK , + .of_match = sam9x5_periph_clk_match, + .probe = sam9x5_periph_clk_probe, + .platdata_auto_alloc_size =sizeof (struct pmc_platdata ), + .ops = &sam9x5_periph_clk_ops, +};drivers/clk/at91/clk-plla.c new file +15
-0@@ -0,0 +1,55 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <linux/io.h> +#include <mach/at91_pmc.h> +#include "pmc.h" + +DECLARE_GLOBAL_DATA_PTR ;
drivers/clk/at91/clk-plla.c line 25
Quoted 10 lines
drivers/clk/at91/clk-plla.c new file +10
-0+ +static int plla_clk_enable (struct udevice *dev,int periph) +{ +struct pmc_platdata *plat =dev_get_platdata (dev); +struct at91_pmc *pmc = plat->reg_base; + +if (readl (&pmc->sr) &AT91_PMC_LOCKA ) +return 0 ; + +return -ENODEV ;
Same error question here.
Quoted 105 lines
drivers/clk/at91/clk-plla.c new file +30
-0+} + +static ulong plla_clk_get_rate (struct udevice *dev) +{ +return gd->arch.plla_rate_hz; +} + +static struct clk_ops plla_clk_ops = { + .enable = plla_clk_enable, + .get_rate = plla_clk_get_rate, +}; + +static int plla_clk_probe (struct udevice *dev) +{ +return at91_pmc_core_probe (dev); +} + +static const struct udevice_id plla_clk_match[] = { + { .compatible ="atmel,sama5d3-clk-pll" }, + {} +}; + +U_BOOT_DRIVER (at91_plla_clk) = { + .name ="at91-plla-clk" , + .id =UCLASS_CLK , + .of_match = plla_clk_match, + .probe = plla_clk_probe, + .platdata_auto_alloc_size =sizeof (struct pmc_platdata ), + .ops = &plla_clk_ops, +};drivers/clk/at91/clk-slow.c new file +37
-0@@ -0,0 +1,37 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> + +static int at91_slow_clk_enable (struct udevice *dev,int periph) +{ +return 0 ; +} + +static ulong at91_slow_clk_get_rate (struct udevice *dev) +{ +return CONFIG_SYS_AT91_SLOW_CLOCK ; +} + +static struct clk_ops at91_slow_clk_ops = { + .enable = at91_slow_clk_enable, + .get_rate = at91_slow_clk_get_rate, +}; + +static const struct udevice_id at91_slow_clk_match[] = { + { .compatible ="atmel,at91sam9x5-clk-slow" }, + {} +}; + +U_BOOT_DRIVER (at91_slow_clk) = { + .name ="at91-slow-clk" , + .id =UCLASS_CLK , + .of_match = at91_slow_clk_match, + .ops = &at91_slow_clk_ops, +};drivers/clk/at91/clk-system.c new file +26
-0@@ -0,0 +1,65 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <linux/io.h> +#include <mach/at91_pmc.h> +#include "pmc.h" + +#define SYSTEM_MAX_ID 31 + +static inline int is_pck (int id) +{ +return (id >=8 ) && (id <=15 ); +} + +static int at91_system_clk_enable (struct udevice *dev,int id) +{ +struct pmc_platdata *plat =dev_get_platdata (dev); +struct at91_pmc *pmc = plat->reg_base; +u32 mask;
drivers/clk/at91/clk-system.c line 36
Quoted 10 lines
drivers/clk/at91/clk-system.c new file +10
-0+ +if (id >SYSTEM_MAX_ID ) +return -EINVAL ; + + mask =BIT (id); + +writel (mask, &pmc->scer); + +if (!is_pck (id)) +return 0 ;
Please can you add a comment to explain the above two lines?
Quoted 138 lines
drivers/clk/at91/clk-system.c new file +29
-0+ +while (!(readl (&pmc->sr) & mask)) + ; + +return 0 ; +} + +static struct clk_ops at91_system_clk_ops = { + .enable = at91_system_clk_enable, +}; + +static int at91_system_clk_probe (struct udevice *dev) +{ +return at91_pmc_core_probe (dev); +} + +static const struct udevice_id at91_system_clk_match[] = { + { .compatible ="atmel,at91rm9200-clk-system" }, + {} +}; + +U_BOOT_DRIVER (at91_system_clk) = { + .name ="at91-system-clk" , + .id =UCLASS_CLK , + .of_match = at91_system_clk_match, + .probe = at91_system_clk_probe, + .platdata_auto_alloc_size =sizeof (struct pmc_platdata ), + .ops = &at91_system_clk_ops, +};drivers/clk/at91/clk-utmi.c new file +67
-0@@ -0,0 +1,67 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <linux/io.h> +#include <mach/at91_pmc.h> +#include "pmc.h" + +DECLARE_GLOBAL_DATA_PTR ; + +#define UTMI_FIXED_MUL 40 + +static int utmi_clk_enable (struct udevice *dev,int periph) +{ +struct pmc_platdata *plat =dev_get_platdata (dev); +struct at91_pmc *pmc = plat->reg_base; +u32 tmp; + +if (readl (&pmc->sr) &AT91_PMC_LOCKU ) +return 0 ; + + tmp =readl (&pmc->uckr); + tmp |=AT91_PMC_UPLLEN | +AT91_PMC_UPLLCOUNT | +AT91_PMC_BIASEN ; +writel (tmp, &pmc->uckr); + +while (!(readl (&pmc->sr) &AT91_PMC_LOCKU )) + ; + +return 0 ; +} + +static ulong utmi_clk_get_rate (struct udevice *dev) +{ +return gd->arch.main_clk_rate_hz *UTMI_FIXED_MUL ; +} + +static struct clk_ops utmi_clk_ops = { + .enable = utmi_clk_enable, + .get_rate = utmi_clk_get_rate, +}; + +static int utmi_clk_probe (struct udevice *dev) +{ +return at91_pmc_core_probe (dev); +} + +static const struct udevice_id utmi_clk_match[] = { + { .compatible ="atmel,at91sam9x5-clk-utmi" }, + {} +}; + +U_BOOT_DRIVER (at91sam9x5_utmi_clk) = { + .name ="at91sam9x5-utmi-clk" , + .id =UCLASS_CLK , + .of_match = utmi_clk_match, + .probe = utmi_clk_probe, + .platdata_auto_alloc_size =sizeof (struct pmc_platdata ), + .ops = &utmi_clk_ops, +};drivers/clk/at91/pmc.c new file +30
-0@@ -0,0 +1,49 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <dm/root.h> +#include "pmc.h" + +DECLARE_GLOBAL_DATA_PTR ; + +static int at91_pmc_core_bind (struct udevice *dev) +{ +return dm_scan_fdt_node (dev, gd->fdt_blob, dev->of_offset, false); +} + +static const struct udevice_id at91_pmc_core_match[] = { + { .compatible ="atmel,sama5d2-pmc" }, + {} +}; + +U_BOOT_DRIVER (at91_pmc_core) = { + .name ="at91_pmc_core" , + .id =UCLASS_CLK , + .of_match = at91_pmc_core_match, + .bind = at91_pmc_core_bind,
drivers/clk/at91/pmc.c line 40
Quoted 10 lines
drivers/clk/at91/pmc.c new file +10
-0+}; + +int at91_pmc_core_probe (struct udevice *dev) +{ +struct pmc_platdata *plat =dev_get_platdata (dev); +fdt_addr_t addr; + + dev =dev_get_parent (dev); +if (!dev) +return -EINVAL ;
There will always be a parent, so this test is redundant.
drivers/clk/at91/pmc.c line 44
Quoted 4 lines
drivers/clk/at91/pmc.c new file +4
-0+ + addr =dev_get_addr (dev); +if (addr ==FDT_ADDR_T_NONE ) +return -EINVAL ;
You can use dev_get_addr_ptr() here.
Quoted 65 lines
drivers/clk/at91/pmc.c new file +5
-0+ + plat->reg_base = (struct at91_pmc *)addr; + +return 0 ; +}drivers/clk/at91/pmc.h new file +17
-0@@ -0,0 +1,17 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __AT91_PMC_H__ +#define __AT91_PMC_H__ + +struct pmc_platdata { +struct at91_pmc *reg_base; +}; + +int at91_pmc_core_probe (struct udevice *dev); + +#endif drivers/clk/at91/sckc.c new file +30
-1@@ -0,0 +1,30 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <dm/root.h> + +DECLARE_GLOBAL_DATA_PTR ; + +static int at91_sckc_clk_bind (struct udevice *dev) +{ +return dm_scan_fdt_node (dev, gd->fdt_blob, dev->of_offset, false); +} + +static const struct udevice_id at91_sckc_clk_match[] = { + { .compatible ="atmel,at91sam9x5-sckc" }, + {} +}; + +U_BOOT_DRIVER (at91_sckc_clk) = { + .name ="at91_sckc_clk" , + .id =UCLASS_CLK , + .of_match = at91_sckc_clk_match, + .bind = at91_sckc_clk_bind, +}; --
Quoted 2 lines
2.7.4
Regards,
Simon
Yang
PATCH v2 2/2 clk: at91: Add new clock driver
Hi Simon,
Quoted 132 lines
-----Original Message-----
From: sjg at google.com [mailto:sjg at google.com] On Behalf Of Simon Glass
Sent: 2016?6?10? 8:34
To: Yang, Wenyou <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Andreas Bie?mann <[email protected]>; Stephen Warren <[email protected]>
Subject: Re: [PATCH v2 2/2] clk: at91: Add new clock driver+Stephen
Hi Wenyou,
Quoted 9 lines · Wenyou Yang
The patch is referred to at91 clock driver of Linux, to make the clock node descriptions in dt are aligned with the Linux.
Signed-off-by Wenyou Yang <[email protected]>---
Changes in v2:
- Remove the redundant log print.Quoted 6 lines
arch/arm/mach-at91/include/mach/at91_pmc.h | 11 ++- drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/at91/Kconfig | 14 +++ drivers/clk/at91/Makefile | 11 +++ drivers/clk/at91/clk-generated.c | 138+++++++++++++++++++++++++++++
Quoted 54 lines
drivers/clk/at91/clk-h32mx.c | 56 ++++++++++++ drivers/clk/at91/clk-main.c | 55 ++++++++++++ drivers/clk/at91/clk-master.c | 33 +++++++ drivers/clk/at91/clk-peripheral.c | 68 ++++++++++++++ drivers/clk/at91/clk-plla.c | 55 ++++++++++++ drivers/clk/at91/clk-slow.c | 37 ++++++++ drivers/clk/at91/clk-system.c | 65 ++++++++++++++ drivers/clk/at91/clk-utmi.c | 67 ++++++++++++++ drivers/clk/at91/pmc.c | 49 ++++++++++ drivers/clk/at91/pmc.h | 17 ++++ drivers/clk/at91/sckc.c | 30 +++++++ 17 files changed, 705 insertions(+), 3 deletions(-) create mode100644
drivers/clk/at91/Kconfigcreate mode 100644drivers/clk/at91/Makefilecreate mode 100644drivers/clk/at91/clk-generated.ccreate mode 100644drivers/clk/at91/clk-h32mx.ccreate mode 100644drivers/clk/at91/clk-main.ccreate mode 100644drivers/clk/at91/clk-master.ccreate mode 100644drivers/clk/at91/clk-peripheral.ccreate mode 100644drivers/clk/at91/clk-plla.ccreate mode 100644drivers/clk/at91/clk-slow.ccreate mode 100644drivers/clk/at91/clk-system.ccreate mode 100644drivers/clk/at91/clk-utmi.ccreate mode 100644drivers/clk/at91/pmc.ccreate mode 100644drivers/clk/at91/pmc.hcreate mode 100644drivers/clk/at91/sckc.carch/arm/mach-at91/include/mach/at91_pmc.h +6
-2@@ -149,6 +149,9 @@ typedef struct at91_pmc {#define AT91_PMC_PCR_PID_MASK (0x3f)#define AT91_PMC_PCR_GCKCSS (0x7 << 8) +#define AT91_PMC_PCR_GCKCSS_MASK 0x07 +#define AT91_PMC_PCR_GCKCSS_OFFSET 8 +#define AT91_PMC_PCR_GCKCSS_ (x) ((x & 0x07) << 8)#define AT91_PMC_PCR_GCKCSS_SLOW_CLK (0x0 << 8)#define AT91_PMC_PCR_GCKCSS_MAIN_CLK (0x1 << 8)#define AT91_PMC_PCR_GCKCSS_PLLA_CLK (0x2 << 8)@@ -158,8 +161,9 @@ typedef struct at91_pmc {#define AT91_PMC_PCR_CMD_WRITE (0x1 << 12)#define AT91_PMC_PCR_DIV (0x3 << 16)#define AT91_PMC_PCR_GCKDIV (0xff << 20) -#define AT91_PMC_PCR_GCKDIV_ (x) ((x & 0xff) << 20) -#define AT91_PMC_PCR_GCKDIV_OFFSET 20 +#define AT91_PMC_PCR_GCKDIV_MASK 0xff +#define AT91_PMC_PCR_GCKDIV_OFFSET 20 +#define AT91_PMC_PCR_GCKDIV_ (x) ((x & 0xff) << 20)#define AT91_PMC_PCR_EN (0x1 << 28)#define AT91_PMC_PCR_GCKEN (0x1 << 29)arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc { · line 247
Quoted 1 line
arch/arm/mach-at91/include/mach/at91_pmc.h +0
-0@@ -243,8 +247,9 @@ typedef struct at91_pmc {#define AT91_PMC_PCK1RDY (1 << 9)/* Programmable Clock 1 */
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc { · line 248
Quoted 1 line
arch/arm/mach-at91/include/mach/at91_pmc.h +0
-0#define AT91_PMC_PCK2RDY (1 << 10)/* Programmable Clock 2 */
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc { · line 249
Quoted 1 line
arch/arm/mach-at91/include/mach/at91_pmc.h +0
-0#define AT91_PMC_PCK3RDY (1 << 11)/* Programmable Clock 3 */
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc { · line 250
Quoted 1 line
arch/arm/mach-at91/include/mach/at91_pmc.h +1
-0+#define AT91_PMC_MOSCSELS BIT(16)/* Main Oscillator Selection Status */
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc { · line 251
Quoted 1 line
arch/arm/mach-at91/include/mach/at91_pmc.h +1
-0+#define AT91_PMC_MOSCRCS BIT(17)/* 12 MHz RC Oscillator Status */
arch/arm/mach-at91/include/mach/at91_pmc.h typedef struct at91_pmc {
Quoted 3 lines
arch/arm/mach-at91/include/mach/at91_pmc.h +0
-1#define AT91_PMC_GCKRDY (1 << 24) -#define AT91_PMC_PROTKEY 0x504d4301/* Activation Code */
Quoted 35 lines
arch/arm/mach-at91/include/mach/at91_pmc.h +0
-0/* PLL Charge Pump Current Register (PMC_PLLICPR) */ diff --gita/drivers/clk/Kconfig b/drivers/clk/Kconfig index a98b74b..1fd1074 100644
drivers/clk/Kconfig +1
-0@@ -21,5 +21,6 @@ config SPL_CLK used as U-Boot proper. source "drivers/clk/uniphier/Kconfig" +source "drivers/clk/at91/Kconfig" endmenudrivers/clk/Makefile index renamed from drivers/clk/Makefile +0
-0c51db15..2bb0f35 100644
drivers/clk/Makefile +1
-0@@ -11,3 +11,4 @@ obj-$(CONFIG_ROCKCHIP_RK3288) += clk_rk3288.o obj-$(CONFIG_SANDBOX) += clk_sandbox.o obj-$(CONFIG_MACH_PIC32) += clk_pic32.o obj-$(CONFIG_CLK_UNIPHIER) += uniphier/ +obj-$(CONFIG_CLK_AT91) += at91/drivers/clk/at91/Kconfig new renamed from drivers/clk/at91/Kconfig +0
-0file mode 100644 index 0000000..f9cb937
drivers/clk/at91/Kconfig new file +8
-0@@ -0,0 +1,14 @@ +config CLK_AT91 + bool "AT91 clock drivers" + depends on CLK + help + This option is used to enable the AT91 clock driver. + +config HAVE_AT91_UTMI + bool
Quoted 8 lines
drivers/clk/at91/Kconfig line 14
Quoted 6 lines
drivers/clk/at91/Kconfig new file +6
-0+ +config HAVE_AT91_H32MX + bool + +config HAVE_AT91_GENERATED_CLK + boolPlease can you add help?
Accepted.
Quoted 86 lines
Also we are changing the clock interface - please see this patch:
http://patchwork.ozlabs.org/patch/625342/
I'm hoping to bring it in next week.
Quoted 79 lines
drivers/clk/at91/Makefile new renamed from drivers/clk/at91/Makefile +0
-0file mode 100644 index 0000000..eb1326b
drivers/clk/at91/Makefile new file +11
-0@@ -0,0 +1,11 @@ +# +# Makefile for at91 specific clk +# + +obj-y += pmc.o sckc.o +obj-y += clk-slow.o clk-main.o clk-plla.o clk-master.o obj-y += +clk-system.o clk-peripheral.o + +obj-$(CONFIG_HAVE_AT91_UTMI) += clk-utmi.o +obj-$(CONFIG_HAVE_AT91_H32MX) += clk-h32mx.o +obj-$(CONFIG_HAVE_AT91_GENERATED_CLK) += clk-generated.odrivers/clk/at91/clk-generated.c new file +56
-0@@ -0,0 +1,138 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <linux/io.h> +#include <mach/at91_pmc.h> +#include "pmc.h" + +DECLARE_GLOBAL_DATA_PTR ; + +#define GENERATED_SOURCE_MAX 6 +#define GENERATED_MAX_DIV 255 + +static ulong generated_clk_get_periph_rate (struct udevice *dev,int +periph) { +struct pmc_platdata *plat =dev_get_platdata (dev); +struct at91_pmc *pmc = plat->reg_base; +struct udevice *parent; +u32 tmp, gckdiv; +u8 parent_id; +int ret; + +writel (periph &AT91_PMC_PCR_PID_MASK , &pmc->pcr); + tmp =readl (&pmc->pcr); + parent_id = (tmp >>AT91_PMC_PCR_GCKCSS_OFFSET ) & +AT91_PMC_PCR_GCKCSS_MASK ; + gckdiv = (tmp >>AT91_PMC_PCR_GCKDIV_OFFSET ) & +AT91_PMC_PCR_GCKDIV_MASK ; + + ret =clk_get_by_index (dev, parent_id, &parent); +if (ret) +return 0 ; + +return clk_get_rate (parent) / (gckdiv +1 ); } + +static ulong generated_clk_set_periph_rate (struct udevice *dev, +int periph, +ulong rate) { +struct pmc_platdata *plat =dev_get_platdata (dev); +struct at91_pmc *pmc = plat->reg_base; +struct udevice *parent, *best_parent =NULL ; +ulong tmp_rate, best_rate = rate, parent_rate; +int tmp_diff, best_diff =-1 ; +u8 num_parents, i; +u32 cells[GENERATED_SOURCE_MAX ]; +u32 div, best_div =0 ; +u8 best_parent_id =0 ; +u32 tmp; +int ret; +
Quoted 8 lines
drivers/clk/at91/clk-generated.c
Quoted 4 lines
drivers/clk/at91/clk-generated.c new file +4
-0+ num_parents =fdtdec_get_int_array_count (gd->fdt_blob, dev->of_offset, +"clocks" , cells, + +GENERATED_SOURCE_MAX );Are you able to store this value in your priv data in your
of_to_platdata()method? We should not be looking at the device tree outside that method.
Okay, move it to ofdata_to_platdata().
Quoted 157 lines
Quoted 157 lines
drivers/clk/at91/clk-generated.c new file +75
-0+ +for (i =0 ; i < num_parents; i++) { + ret =clk_get_by_index (dev, i, &parent); +if (ret) +return ret; + + parent_rate =clk_get_rate (parent); +if (!parent_rate) +return -ENODEV ; + +for (div =1 ; div <GENERATED_MAX_DIV +2 ; div++) { + tmp_rate =DIV_ROUND_CLOSEST (parent_rate, div); +if (rate < tmp_rate) +continue ; + tmp_diff = rate - tmp_rate; + +if (best_diff <0 || best_diff > tmp_diff) { + best_rate = tmp_rate; + best_diff = tmp_diff; + + best_div = div -1 ; + best_parent = parent; + best_parent_id = i; + } + +if (!best_diff || tmp_rate < rate) +break ; + } + +if (!best_diff) +break ; + } + +dev_dbg (dev,"GCK: best parent: %s, best_rate = %ld, best_div = %d\n" , + best_parent->name, best_rate, best_div); + + ret =clk_enable (best_parent,0 ); +if (ret) +return -ENODEV ; + +writel (periph &AT91_PMC_PCR_PID_MASK , &pmc->pcr); + tmp =readl (&pmc->pcr); + tmp &= ~(AT91_PMC_PCR_GCKDIV |AT91_PMC_PCR_GCKCSS ); + tmp |=AT91_PMC_PCR_GCKCSS_ (best_parent_id) | +AT91_PMC_PCR_CMD_WRITE | +AT91_PMC_PCR_GCKDIV_ (best_div) | +AT91_PMC_PCR_GCKEN ; +writel (tmp, &pmc->pcr); + +while (!(readl (&pmc->sr) &AT91_PMC_GCKRDY )) + ; + +return 0 ; +} + +static struct clk_ops generated_clk_ops = { + .get_periph_rate = generated_clk_get_periph_rate, + .set_periph_rate = generated_clk_set_periph_rate, }; + +static int generated_clk_probe (struct udevice *dev) { +return at91_pmc_core_probe (dev); } + +static const struct udevice_id generated_clk_match[] = { + { .compatible ="atmel,sama5d2-clk-generated" }, + {} +}; + +U_BOOT_DRIVER (generated_clk) = { + .name ="generated-clk" , + .id =UCLASS_CLK , + .of_match = generated_clk_match, + .probe = generated_clk_probe, + .platdata_auto_alloc_size =sizeof (struct pmc_platdata ), + .ops = &generated_clk_ops, +};(quoted diff) +0
-0
b/drivers/clk/at91/clk-h32mx.cnew file mode 100644 index 0000000..035562adrivers/clk/at91/clk-h32mx.c new file +51
-0@@ -0,0 +1,56 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <dm/util.h> +#include <linux/io.h> +#include <mach/at91_pmc.h> +#include "pmc.h" + +DECLARE_GLOBAL_DATA_PTR ; + +#define H32MX_MAX_FREQ 90000000 + +static ulong sama5d4_h32mx_clk_get_rate (struct udevice *dev) { +struct pmc_platdata *plat =dev_get_platdata (dev); +struct at91_pmc *pmc = plat->reg_base; +ulong rate = gd->arch.mck_rate_hz; + +if (readl (&pmc->mckr) &AT91_PMC_MCKR_H32MXDIV ) + rate /=2 ; + +if (rate >H32MX_MAX_FREQ ) +dm_warn ("H32MX clock is too fast\n" ); + +return rate; +} + +static struct clk_ops sama5d4_h32mx_clk_ops = { + .get_rate = sama5d4_h32mx_clk_get_rate, }; + +static int sama5d4_h32mx_clk_probe (struct udevice *dev) { +return at91_pmc_core_probe (dev); } + +static const struct udevice_id sama5d4_h32mx_clk_match[] = { + { .compatible ="atmel,sama5d4-clk-h32mx" }, + {} +}; + +U_BOOT_DRIVER (sama5d4_h32mx_clk) = { + .name ="sama5d4-h32mx-clk" , + .id =UCLASS_CLK , + .of_match = sama5d4_h32mx_clk_match, + .probe = sama5d4_h32mx_clk_probe, + .platdata_auto_alloc_size =sizeof (struct pmc_platdata ), + .ops = &sama5d4_h32mx_clk_ops, };drivers/clk/at91/clk-main.c new file +19
-0@@ -0,0 +1,55 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <linux/io.h> +#include <mach/at91_pmc.h> +#include "pmc.h" + +DECLARE_GLOBAL_DATA_PTR ; + +static int main_osc_clk_enable (struct udevice *dev,int periph) { +struct pmc_platdata *plat =dev_get_platdata (dev); +struct at91_pmc *pmc = plat->reg_base;
Quoted 8 lines
drivers/clk/at91/clk-main.c line 25
Quoted 5 lines
drivers/clk/at91/clk-main.c new file +5
-0+ +if (readl (&pmc->sr) &AT91_PMC_MOSCSELS ) +return 0 ; + +return -ENODEV ;This error indicates that there is no device. But it looks like there is. What are you trying to represent here?
It is supposed that the main oscillator clock should be enabled, if it is not enabled, it is an error, return -EINVAL?
Quoted 108 lines
Quoted 108 lines
drivers/clk/at91/clk-main.c new file +25
-0+} + +static ulong main_osc_clk_get_rate (struct udevice *dev) { +return gd->arch.main_clk_rate_hz; } + +static struct clk_ops main_osc_clk_ops = { + .enable = main_osc_clk_enable, + .get_rate = main_osc_clk_get_rate, }; + +static int main_osc_clk_probe (struct udevice *dev) { +return at91_pmc_core_probe (dev); } + +static const struct udevice_id main_osc_clk_match[] = { + { .compatible ="atmel,at91sam9x5-clk-main" }, + {} +}; + +U_BOOT_DRIVER (at91sam9x5_main_osc_clk) = { + .name ="at91sam9x5-main-osc-clk" , + .id =UCLASS_CLK , + .of_match = main_osc_clk_match, + .probe = main_osc_clk_probe, + .platdata_auto_alloc_size =sizeof (struct pmc_platdata ), + .ops = &main_osc_clk_ops, +};(quoted diff) +0
-0
b/drivers/clk/at91/clk-master.cnew file mode 100644 index 0000000..6d844d0drivers/clk/at91/clk-master.c new file +31
-0@@ -0,0 +1,33 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> + +DECLARE_GLOBAL_DATA_PTR ; + +static ulong at91_master_clk_get_rate (struct udevice *dev) { +return gd->arch.mck_rate_hz; +} + +static struct clk_ops at91_master_clk_ops = { + .get_rate = at91_master_clk_get_rate, }; + +static const struct udevice_id at91_master_clk_match[] = { + { .compatible ="atmel,at91sam9x5-clk-master" }, + {} +}; + +U_BOOT_DRIVER (at91_master_clk) = { + .name ="at91-master-clk" , + .id =UCLASS_CLK , + .of_match = at91_master_clk_match, + .ops = &at91_master_clk_ops, +};drivers/clk/at91/clk-peripheral.c new file +38
-0@@ -0,0 +1,68 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <linux/io.h> +#include <mach/at91_pmc.h> +#include "pmc.h" + +#define PERIPHERAL_MAX 64 + +#define PERIPHERAL_AT91RM9200 0 +#define PERIPHERAL_AT91SAM9X5 1 + +#define PERIPHERAL_ID_MIN 2 +#define PERIPHERAL_ID_MAX 31 +#define PERIPHERAL_MASK (id) (1 << ((id) & PERIPHERAL_ID_MAX)) + +#define PERIPHERAL_RSHIFT_MASK 0x3 +#define PERIPHERAL_RSHIFT (val) (((val) >> 16) & +PERIPHERAL_RSHIFT_MASK) + +#define PERIPHERAL_MAX_SHIFT 3 + +static int sam9x5_periph_clk_enable (struct udevice *dev,int periph) +{ +struct pmc_platdata *plat =dev_get_platdata (dev); +struct at91_pmc *pmc = plat->reg_base; +u32 tmp; + +if (periph <PERIPHERAL_ID_MIN ) +return -1 ; +
Quoted 8 lines
drivers/clk/at91/clk-peripheral.c line 42
Quoted 5 lines
drivers/clk/at91/clk-peripheral.c new file +5
-0+writel (periph &AT91_PMC_PCR_PID_MASK , &pmc->pcr); + tmp =readl (&pmc->pcr); +writel (tmp | +AT91_PMC_PCR_CMD_WRITE | +AT91_PMC_PCR_EN , &pmc->pcr);Or use
setbits_le32(&pmc->pcr, AT91_PMC_PCR_CMD_WRITE | AT91_PMC_PCR_EN)
Accepted.
Quoted 153 lines
Quoted 42 lines
drivers/clk/at91/clk-peripheral.c new file +22
-0+ +return 0 ; +} + +static struct clk_ops sam9x5_periph_clk_ops = { + .enable = sam9x5_periph_clk_enable, }; + +static int sam9x5_periph_clk_probe (struct udevice *dev) { +return at91_pmc_core_probe (dev); } + +static const struct udevice_id sam9x5_periph_clk_match[] = { + { .compatible ="atmel,at91sam9x5-clk-peripheral" }, + {} +}; + +U_BOOT_DRIVER (sam9x5_periph_clk) = { + .name ="sam9x5-periph-clk" , + .id =UCLASS_CLK , + .of_match = sam9x5_periph_clk_match, + .probe = sam9x5_periph_clk_probe, + .platdata_auto_alloc_size =sizeof (struct pmc_platdata ), + .ops = &sam9x5_periph_clk_ops, };drivers/clk/at91/clk-plla.c new file +14
-0@@ -0,0 +1,55 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <linux/io.h> +#include <mach/at91_pmc.h> +#include "pmc.h" +drivers/clk/at91/clk-plla.c line 24
Quoted 10 lines
drivers/clk/at91/clk-plla.c new file +10
-0+DECLARE_GLOBAL_DATA_PTR ; + +static int plla_clk_enable (struct udevice *dev,int periph) { +struct pmc_platdata *plat =dev_get_platdata (dev); +struct at91_pmc *pmc = plat->reg_base; + +if (readl (&pmc->sr) &AT91_PMC_LOCKA ) +return 0 ; + +return -ENODEV ;Same error question here.
Quoted 98 lines
drivers/clk/at91/clk-plla.c new file +26
-0+} + +static ulong plla_clk_get_rate (struct udevice *dev) { +return gd->arch.plla_rate_hz; +} + +static struct clk_ops plla_clk_ops = { + .enable = plla_clk_enable, + .get_rate = plla_clk_get_rate, }; + +static int plla_clk_probe (struct udevice *dev) { +return at91_pmc_core_probe (dev); } + +static const struct udevice_id plla_clk_match[] = { + { .compatible ="atmel,sama5d3-clk-pll" }, + {} +}; + +U_BOOT_DRIVER (at91_plla_clk) = { + .name ="at91-plla-clk" , + .id =UCLASS_CLK , + .of_match = plla_clk_match, + .probe = plla_clk_probe, + .platdata_auto_alloc_size =sizeof (struct pmc_platdata ), + .ops = &plla_clk_ops, +};drivers/clk/at91/clk-slow.c new file +33
-0@@ -0,0 +1,37 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> + +static int at91_slow_clk_enable (struct udevice *dev,int periph) { +return 0 ; +} + +static ulong at91_slow_clk_get_rate (struct udevice *dev) { +return CONFIG_SYS_AT91_SLOW_CLOCK ; } + +static struct clk_ops at91_slow_clk_ops = { + .enable = at91_slow_clk_enable, + .get_rate = at91_slow_clk_get_rate, }; + +static const struct udevice_id at91_slow_clk_match[] = { + { .compatible ="atmel,at91sam9x5-clk-slow" }, + {} +}; + +U_BOOT_DRIVER (at91_slow_clk) = { + .name ="at91-slow-clk" , + .id =UCLASS_CLK , + .of_match = at91_slow_clk_match, + .ops = &at91_slow_clk_ops, +};(quoted diff) +0
-0
b/drivers/clk/at91/clk-system.cnew file mode 100644 index 0000000..5e50af6drivers/clk/at91/clk-system.c new file +28
-0@@ -0,0 +1,65 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <linux/io.h> +#include <mach/at91_pmc.h> +#include "pmc.h" + +#define SYSTEM_MAX_ID 31 + +static inline int is_pck (int id) +{ +return (id >=8 ) && (id <=15 ); } + +static int at91_system_clk_enable (struct udevice *dev,int id) { +struct pmc_platdata *plat =dev_get_platdata (dev); +struct at91_pmc *pmc = plat->reg_base; +u32 mask; + +if (id >SYSTEM_MAX_ID ) +return -EINVAL ; +
Quoted 8 lines
drivers/clk/at91/clk-system.c line 36
Quoted 6 lines
drivers/clk/at91/clk-system.c new file +6
-0+ mask =BIT (id); + +writel (mask, &pmc->scer); + +if (!is_pck (id)) +return 0 ;Please can you add a comment to explain the above two lines?
Accepted.
Quoted 130 lines
Quoted 130 lines
drivers/clk/at91/clk-system.c new file +26
-0+ +while (!(readl (&pmc->sr) & mask)) + ; + +return 0 ; +} + +static struct clk_ops at91_system_clk_ops = { + .enable = at91_system_clk_enable, }; + +static int at91_system_clk_probe (struct udevice *dev) { +return at91_pmc_core_probe (dev); } + +static const struct udevice_id at91_system_clk_match[] = { + { .compatible ="atmel,at91rm9200-clk-system" }, + {} +}; + +U_BOOT_DRIVER (at91_system_clk) = { + .name ="at91-system-clk" , + .id =UCLASS_CLK , + .of_match = at91_system_clk_match, + .probe = at91_system_clk_probe, + .platdata_auto_alloc_size =sizeof (struct pmc_platdata ), + .ops = &at91_system_clk_ops, +};drivers/clk/at91/clk-utmi.c new file +61
-0@@ -0,0 +1,67 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <linux/io.h> +#include <mach/at91_pmc.h> +#include "pmc.h" + +DECLARE_GLOBAL_DATA_PTR ; + +#define UTMI_FIXED_MUL 40 + +static int utmi_clk_enable (struct udevice *dev,int periph) { +struct pmc_platdata *plat =dev_get_platdata (dev); +struct at91_pmc *pmc = plat->reg_base; +u32 tmp; + +if (readl (&pmc->sr) &AT91_PMC_LOCKU ) +return 0 ; + + tmp =readl (&pmc->uckr); + tmp |=AT91_PMC_UPLLEN | +AT91_PMC_UPLLCOUNT | +AT91_PMC_BIASEN ; +writel (tmp, &pmc->uckr); + +while (!(readl (&pmc->sr) &AT91_PMC_LOCKU )) + ; + +return 0 ; +} + +static ulong utmi_clk_get_rate (struct udevice *dev) { +return gd->arch.main_clk_rate_hz *UTMI_FIXED_MUL ; } + +static struct clk_ops utmi_clk_ops = { + .enable = utmi_clk_enable, + .get_rate = utmi_clk_get_rate, }; + +static int utmi_clk_probe (struct udevice *dev) { +return at91_pmc_core_probe (dev); } + +static const struct udevice_id utmi_clk_match[] = { + { .compatible ="atmel,at91sam9x5-clk-utmi" }, + {} +}; + +U_BOOT_DRIVER (at91sam9x5_utmi_clk) = { + .name ="at91sam9x5-utmi-clk" , + .id =UCLASS_CLK , + .of_match = utmi_clk_match, + .probe = utmi_clk_probe, + .platdata_auto_alloc_size =sizeof (struct pmc_platdata ), + .ops = &utmi_clk_ops, +};drivers/clk/at91/pmc.c new file renamed from drivers/clk/at91/pmc.c +0
-0mode 100644 index 0000000..de802e8
drivers/clk/at91/pmc.c new file +32
-0@@ -0,0 +1,49 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <dm/root.h> +#include "pmc.h" + +DECLARE_GLOBAL_DATA_PTR ; + +static int at91_pmc_core_bind (struct udevice *dev) { +return dm_scan_fdt_node (dev, gd->fdt_blob, dev->of_offset, +false); } + +static const struct udevice_id at91_pmc_core_match[] = { + { .compatible ="atmel,sama5d2-pmc" }, + {} +}; + +U_BOOT_DRIVER (at91_pmc_core) = { + .name ="at91_pmc_core" , + .id =UCLASS_CLK , + .of_match = at91_pmc_core_match, + .bind = at91_pmc_core_bind, +}; + +int at91_pmc_core_probe (struct udevice *dev) {
Quoted 8 lines
drivers/clk/at91/pmc.c line 40
Quoted 6 lines
drivers/clk/at91/pmc.c new file +6
-0+struct pmc_platdata *plat =dev_get_platdata (dev); +fdt_addr_t addr; + + dev =dev_get_parent (dev); +if (!dev) +return -EINVAL ;There will always be a parent, so this test is redundant.
Accepted.
Quoted 7 lines
drivers/clk/at91/pmc.c line 44
Quoted 5 lines
drivers/clk/at91/pmc.c new file +4
-0+ + addr =dev_get_addr (dev); +if (addr ==FDT_ADDR_T_NONE ) +return -EINVAL ;You can use
dev_get_addr_ptr()here.
Accepted.
Quoted 68 lines
Quoted 63 lines
drivers/clk/at91/pmc.c new file +5
-0+ + plat->reg_base = (struct at91_pmc *)addr; + +return 0 ; +}drivers/clk/at91/pmc.h new file renamed from drivers/clk/at91/pmc.h +0
-0mode 100644 index 0000000..201dad8
drivers/clk/at91/pmc.h new file +17
-0@@ -0,0 +1,17 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __AT91_PMC_H__ +#define __AT91_PMC_H__ + +struct pmc_platdata { +struct at91_pmc *reg_base; +}; + +int at91_pmc_core_probe (struct udevice *dev); + +#endif drivers/clk/at91/sckc.c new renamed from drivers/clk/at91/sckc.c +0
-0file mode 100644 index 0000000..69ec636
drivers/clk/at91/sckc.c new file +29
-1@@ -0,0 +1,30 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk.h> +#include <dm/device.h> +#include <dm/root.h> + +DECLARE_GLOBAL_DATA_PTR ; + +static int at91_sckc_clk_bind (struct udevice *dev) { +return dm_scan_fdt_node (dev, gd->fdt_blob, dev->of_offset, +false); } + +static const struct udevice_id at91_sckc_clk_match[] = { + { .compatible ="atmel,at91sam9x5-sckc" }, + {} +}; + +U_BOOT_DRIVER (at91_sckc_clk) = { + .name ="at91_sckc_clk" , + .id =UCLASS_CLK , + .of_match = at91_sckc_clk_match, + .bind = at91_sckc_clk_bind, +}; --Quoted 2 lines
2.7.4
Regards,
Simon