blob: 16688e90b417fc1ed9a3996f848f7be606eb822c [file] [log] [blame]
Wenyou Yang9e5935c2016-07-20 17:55:12 +08001/*
2 * Copyright (C) 2016 Atmel Corporation
3 * Wenyou.Yang <wenyou.yang@atmel.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <clk-uclass.h>
10#include <dm/device.h>
11#include <linux/io.h>
12#include <mach/at91_pmc.h>
13#include "pmc.h"
14
15#define PERIPHERAL_ID_MIN 2
16#define PERIPHERAL_ID_MAX 31
17#define PERIPHERAL_MASK(id) (1 << ((id) & PERIPHERAL_ID_MAX))
18
19static int sam9x5_periph_clk_enable(struct clk *clk)
20{
21 struct pmc_platdata *plat = dev_get_platdata(clk->dev);
22 struct at91_pmc *pmc = plat->reg_base;
23
24 if (clk->id < PERIPHERAL_ID_MIN)
25 return -1;
26
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);
29
30 return 0;
31}
32
33static struct clk_ops sam9x5_periph_clk_ops = {
34 .enable = sam9x5_periph_clk_enable,
35};
36
37static int sam9x5_periph_clk_bind(struct udevice *dev)
38{
39 return at91_pmc_clk_node_bind(dev);
40}
41
42static int sam9x5_periph_clk_probe(struct udevice *dev)
43{
44 return at91_pmc_core_probe(dev);
45}
46
47static const struct udevice_id sam9x5_periph_clk_match[] = {
48 { .compatible = "atmel,at91sam9x5-clk-peripheral" },
49 {}
50};
51
52U_BOOT_DRIVER(sam9x5_periph_clk) = {
53 .name = "sam9x5-periph-clk",
54 .id = UCLASS_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,
60};