blob: 5b59a0c85204fda795ca6877732bbf66a0e43f39 [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 SYSTEM_MAX_ID 31
16
Wenyou Yang6cadaa02016-09-27 11:00:29 +080017/**
18 * at91_system_clk_bind() - for the system clock driver
19 * Recursively bind its children as clk devices.
20 *
21 * @return: 0 on success, or negative error code on failure
22 */
23static int at91_system_clk_bind(struct udevice *dev)
24{
25 return at91_clk_sub_device_bind(dev, "system-clk");
26}
27
28static const struct udevice_id at91_system_clk_match[] = {
29 { .compatible = "atmel,at91rm9200-clk-system" },
30 {}
31};
32
33U_BOOT_DRIVER(at91_system_clk) = {
34 .name = "at91-system-clk",
35 .id = UCLASS_MISC,
36 .of_match = at91_system_clk_match,
37 .bind = at91_system_clk_bind,
38};
39
40/*----------------------------------------------------------*/
41
Wenyou Yang9e5935c2016-07-20 17:55:12 +080042static inline int is_pck(int id)
43{
44 return (id >= 8) && (id <= 15);
45}
46
Wenyou Yang6cadaa02016-09-27 11:00:29 +080047static int system_clk_enable(struct clk *clk)
Wenyou Yang9e5935c2016-07-20 17:55:12 +080048{
49 struct pmc_platdata *plat = dev_get_platdata(clk->dev);
50 struct at91_pmc *pmc = plat->reg_base;
51 u32 mask;
52
53 if (clk->id > SYSTEM_MAX_ID)
54 return -EINVAL;
55
56 mask = BIT(clk->id);
57
58 writel(mask, &pmc->scer);
59
60 /**
61 * For the programmable clocks the Ready status in the PMC
62 * status register should be checked after enabling.
63 * For other clocks this is unnecessary.
64 */
65 if (!is_pck(clk->id))
66 return 0;
67
68 while (!(readl(&pmc->sr) & mask))
69 ;
70
71 return 0;
72}
73
Wenyou Yang6cadaa02016-09-27 11:00:29 +080074static struct clk_ops system_clk_ops = {
75 .of_xlate = at91_clk_of_xlate,
76 .enable = system_clk_enable,
Wenyou Yang9e5935c2016-07-20 17:55:12 +080077};
78
Wenyou Yang6cadaa02016-09-27 11:00:29 +080079U_BOOT_DRIVER(system_clk) = {
80 .name = "system-clk",
Wenyou Yang9e5935c2016-07-20 17:55:12 +080081 .id = UCLASS_CLK,
Wenyou Yang6cadaa02016-09-27 11:00:29 +080082 .probe = at91_clk_probe,
Wenyou Yang9e5935c2016-07-20 17:55:12 +080083 .platdata_auto_alloc_size = sizeof(struct pmc_platdata),
Wenyou Yang6cadaa02016-09-27 11:00:29 +080084 .ops = &system_clk_ops,
Wenyou Yang9e5935c2016-07-20 17:55:12 +080085};