2 * Copyright (C) 2018 Microhip / Atmel Corporation
3 * Wenyou.Yang <wenyou.yang@microchip.com>
5 * SPDX-License-Identifier: GPL-2.0+
9 #include <clk-uclass.h>
10 #include <dm/device.h>
12 #include <mach/at91_pmc.h>
15 DECLARE_GLOBAL_DATA_PTR;
17 static int at91_plladiv_clk_enable(struct clk *clk)
22 static ulong at91_plladiv_clk_get_rate(struct clk *clk)
24 struct pmc_platdata *plat = dev_get_platdata(clk->dev);
25 struct at91_pmc *pmc = plat->reg_base;
30 ret = clk_get_by_index(clk->dev, 0, &source);
34 clk_rate = clk_get_rate(&source);
35 if (readl(&pmc->mckr) & AT91_PMC_MCKR_PLLADIV_2)
41 static ulong at91_plladiv_clk_set_rate(struct clk *clk, ulong rate)
43 struct pmc_platdata *plat = dev_get_platdata(clk->dev);
44 struct at91_pmc *pmc = plat->reg_base;
49 ret = clk_get_by_index(clk->dev, 0, &source);
53 parent_rate = clk_get_rate(&source);
54 if ((parent_rate != rate) && ((parent_rate) / 2 != rate))
57 if (parent_rate != rate) {
58 writel((readl(&pmc->mckr) | AT91_PMC_MCKR_PLLADIV_2),
65 static struct clk_ops at91_plladiv_clk_ops = {
66 .enable = at91_plladiv_clk_enable,
67 .get_rate = at91_plladiv_clk_get_rate,
68 .set_rate = at91_plladiv_clk_set_rate,
71 static int at91_plladiv_clk_probe(struct udevice *dev)
73 return at91_pmc_core_probe(dev);
76 static const struct udevice_id at91_plladiv_clk_match[] = {
77 { .compatible = "atmel,at91sam9x5-clk-plldiv" },
81 U_BOOT_DRIVER(at91_plladiv_clk) = {
82 .name = "at91-plladiv-clk",
84 .of_match = at91_plladiv_clk_match,
85 .probe = at91_plladiv_clk_probe,
86 .platdata_auto_alloc_size = sizeof(struct pmc_platdata),
87 .ops = &at91_plladiv_clk_ops,