1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Atmel Corporation
4 * Wenyou.Yang <wenyou.yang@atmel.com>
8 #include <clk-uclass.h>
10 #include <linux/bitops.h>
12 #include <mach/at91_pmc.h>
15 #define SYSTEM_MAX_ID 31
18 * at91_system_clk_bind() - for the system clock driver
19 * Recursively bind its children as clk devices.
21 * @return: 0 on success, or negative error code on failure
23 static int at91_system_clk_bind(struct udevice *dev)
25 return at91_clk_sub_device_bind(dev, "system-clk");
28 static const struct udevice_id at91_system_clk_match[] = {
29 { .compatible = "atmel,at91rm9200-clk-system" },
33 U_BOOT_DRIVER(at91_system_clk) = {
34 .name = "at91-system-clk",
36 .of_match = at91_system_clk_match,
37 .bind = at91_system_clk_bind,
40 /*----------------------------------------------------------*/
42 static inline int is_pck(int id)
44 return (id >= 8) && (id <= 15);
47 static ulong system_clk_get_rate(struct clk *clk)
52 ret = clk_get_by_index(clk->dev, 0, &clk_dev);
56 return clk_get_rate(&clk_dev);
59 static ulong system_clk_set_rate(struct clk *clk, ulong rate)
64 ret = clk_get_by_index(clk->dev, 0, &clk_dev);
68 return clk_set_rate(&clk_dev, rate);
71 static int system_clk_enable(struct clk *clk)
73 struct pmc_platdata *plat = dev_get_platdata(clk->dev);
74 struct at91_pmc *pmc = plat->reg_base;
77 if (clk->id > SYSTEM_MAX_ID)
82 writel(mask, &pmc->scer);
85 * For the programmable clocks the Ready status in the PMC
86 * status register should be checked after enabling.
87 * For other clocks this is unnecessary.
92 while (!(readl(&pmc->sr) & mask))
98 static struct clk_ops system_clk_ops = {
99 .of_xlate = at91_clk_of_xlate,
100 .get_rate = system_clk_get_rate,
101 .set_rate = system_clk_set_rate,
102 .enable = system_clk_enable,
105 U_BOOT_DRIVER(system_clk) = {
106 .name = "system-clk",
108 .probe = at91_clk_probe,
109 .platdata_auto_alloc_size = sizeof(struct pmc_platdata),
110 .ops = &system_clk_ops,