1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Microhip / Atmel Corporation
4 * Wenyou.Yang <wenyou.yang@microchip.com>
8 #include <clk-uclass.h>
11 #include <mach/at91_pmc.h>
14 static int at91_plladiv_clk_enable(struct clk *clk)
19 static ulong at91_plladiv_clk_get_rate(struct clk *clk)
21 struct pmc_platdata *plat = dev_get_platdata(clk->dev);
22 struct at91_pmc *pmc = plat->reg_base;
27 ret = clk_get_by_index(clk->dev, 0, &source);
31 clk_rate = clk_get_rate(&source);
32 if (readl(&pmc->mckr) & AT91_PMC_MCKR_PLLADIV_2)
38 static ulong at91_plladiv_clk_set_rate(struct clk *clk, ulong rate)
40 struct pmc_platdata *plat = dev_get_platdata(clk->dev);
41 struct at91_pmc *pmc = plat->reg_base;
46 ret = clk_get_by_index(clk->dev, 0, &source);
50 parent_rate = clk_get_rate(&source);
51 if ((parent_rate != rate) && ((parent_rate) / 2 != rate))
54 if (parent_rate != rate) {
55 writel((readl(&pmc->mckr) | AT91_PMC_MCKR_PLLADIV_2),
62 static struct clk_ops at91_plladiv_clk_ops = {
63 .enable = at91_plladiv_clk_enable,
64 .get_rate = at91_plladiv_clk_get_rate,
65 .set_rate = at91_plladiv_clk_set_rate,
68 static int at91_plladiv_clk_probe(struct udevice *dev)
70 return at91_pmc_core_probe(dev);
73 static const struct udevice_id at91_plladiv_clk_match[] = {
74 { .compatible = "atmel,at91sam9x5-clk-plldiv" },
78 U_BOOT_DRIVER(at91_plladiv_clk) = {
79 .name = "at91-plladiv-clk",
81 .of_match = at91_plladiv_clk_match,
82 .probe = at91_plladiv_clk_probe,
83 .platdata_auto_alloc_size = sizeof(struct pmc_platdata),
84 .ops = &at91_plladiv_clk_ops,