2 * Copyright (C) 2016 Atmel Corporation
3 * Wenyou.Yang <wenyou.yang@atmel.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 #define PERIPHERAL_ID_MIN 2
16 #define PERIPHERAL_ID_MAX 31
17 #define PERIPHERAL_MASK(id) (1 << ((id) & PERIPHERAL_ID_MAX))
19 static int sam9x5_periph_clk_enable(struct clk *clk)
21 struct pmc_platdata *plat = dev_get_platdata(clk->dev);
22 struct at91_pmc *pmc = plat->reg_base;
24 if (clk->id < PERIPHERAL_ID_MIN)
27 writel(clk->id & AT91_PMC_PCR_PID_MASK, &pmc->pcr);
28 setbits_le32(&pmc->pcr, AT91_PMC_PCR_CMD_WRITE | AT91_PMC_PCR_EN);
33 static struct clk_ops sam9x5_periph_clk_ops = {
34 .enable = sam9x5_periph_clk_enable,
37 static int sam9x5_periph_clk_bind(struct udevice *dev)
39 return at91_pmc_clk_node_bind(dev);
42 static int sam9x5_periph_clk_probe(struct udevice *dev)
44 return at91_pmc_core_probe(dev);
47 static const struct udevice_id sam9x5_periph_clk_match[] = {
48 { .compatible = "atmel,at91sam9x5-clk-peripheral" },
52 U_BOOT_DRIVER(sam9x5_periph_clk) = {
53 .name = "sam9x5-periph-clk",
55 .of_match = sam9x5_periph_clk_match,
56 .bind = sam9x5_periph_clk_bind,
57 .probe = sam9x5_periph_clk_probe,
58 .platdata_auto_alloc_size = sizeof(struct pmc_platdata),
59 .ops = &sam9x5_periph_clk_ops,