diff mbox series

[2/2] clk: ti: get register address from device tree

Message ID 20210402192054.7934-3-dariobin@libero.it (mailing list archive)
State New
Headers show
Series fdt: translate address if #size-cells = <0> | expand

Commit Message

Dario Binacchi April 2, 2021, 7:20 p.m. UTC
Until now, only the register offset was retrieved from the device tree
to be added, during access, to a common base address for the clocks.
If possible, we try to retrieve the physical address of the register
directly from the device tree.

Signed-off-by: Dario Binacchi <dariobin@libero.it>

---

 drivers/clk/ti/clk.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Comments

Tero Kristo April 6, 2021, 6:02 a.m. UTC | #1
On 02/04/2021 22:20, Dario Binacchi wrote:
> Until now, only the register offset was retrieved from the device tree
> to be added, during access, to a common base address for the clocks.
> If possible, we try to retrieve the physical address of the register
> directly from the device tree.

The physical address is derived from the base address of the clock 
provider, it is not derived from the clock node itself.

Doing what this patch does may actually break things, as you end up 
creating an individual ioremap for every single clock register, and they 
are typically a word apart from each other. In the TI clock driver case, 
the ioremap is done only once for the whole clock register space.

-Tero

> 
> Signed-off-by: Dario Binacchi <dariobin@libero.it>
> 
> ---
> 
>   drivers/clk/ti/clk.c | 13 ++++++++++++-
>   1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/ti/clk.c b/drivers/clk/ti/clk.c
> index 3da33c786d77..938f5a2cb425 100644
> --- a/drivers/clk/ti/clk.c
> +++ b/drivers/clk/ti/clk.c
> @@ -265,9 +265,21 @@ int __init ti_clk_retry_init(struct device_node *node, void *user,
>   int ti_clk_get_reg_addr(struct device_node *node, int index,
>   			struct clk_omap_reg *reg)
>   {
> +	const __be32 *addrp;
> +	u64 size, addr = OF_BAD_ADDR;
> +	unsigned int flags;
>   	u32 val;
>   	int i;
>   
> +	addrp = of_get_address(node, index, &size, &flags);
> +	if (addrp)
> +		addr = of_translate_address(node, addrp);
> +
> +	if (addr != OF_BAD_ADDR) {
> +		reg->ptr = ioremap(addr, sizeof(u32));
> +		return 0;
> +	}
> +
>   	for (i = 0; i < CLK_MAX_MEMMAPS; i++) {
>   		if (clocks_node_ptr[i] == node->parent)
>   			break;
> @@ -287,7 +299,6 @@ int ti_clk_get_reg_addr(struct device_node *node, int index,
>   
>   	reg->offset = val;
>   	reg->ptr = NULL;
> -
>   	return 0;
>   }
>   
>
diff mbox series

Patch

diff --git a/drivers/clk/ti/clk.c b/drivers/clk/ti/clk.c
index 3da33c786d77..938f5a2cb425 100644
--- a/drivers/clk/ti/clk.c
+++ b/drivers/clk/ti/clk.c
@@ -265,9 +265,21 @@  int __init ti_clk_retry_init(struct device_node *node, void *user,
 int ti_clk_get_reg_addr(struct device_node *node, int index,
 			struct clk_omap_reg *reg)
 {
+	const __be32 *addrp;
+	u64 size, addr = OF_BAD_ADDR;
+	unsigned int flags;
 	u32 val;
 	int i;
 
+	addrp = of_get_address(node, index, &size, &flags);
+	if (addrp)
+		addr = of_translate_address(node, addrp);
+
+	if (addr != OF_BAD_ADDR) {
+		reg->ptr = ioremap(addr, sizeof(u32));
+		return 0;
+	}
+
 	for (i = 0; i < CLK_MAX_MEMMAPS; i++) {
 		if (clocks_node_ptr[i] == node->parent)
 			break;
@@ -287,7 +299,6 @@  int ti_clk_get_reg_addr(struct device_node *node, int index,
 
 	reg->offset = val;
 	reg->ptr = NULL;
-
 	return 0;
 }