1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Atmel Corporation
4 * Wenyou.Yang <wenyou.yang@atmel.com>
9 #include <clk-uclass.h>
10 #include <linux/clk-provider.h>
13 static int at91_clk_of_xlate(struct clk *clk, struct ofnode_phandle_args *args)
15 if (args->args_count != 2) {
16 debug("AT91: clk: Invalid args_count: %d\n", args->args_count);
20 clk->id = AT91_TO_CLK_ID(args->args[0], args->args[1]);
25 const struct clk_ops at91_clk_ops = {
26 .of_xlate = at91_clk_of_xlate,
27 .set_rate = ccf_clk_set_rate,
28 .get_rate = ccf_clk_get_rate,
29 .enable = ccf_clk_enable,
30 .disable = ccf_clk_disable,
34 * pmc_read() - read content at address base + off into val
37 * @off: offset to read from
38 * @val: where the content of base + off is stored
42 void pmc_read(void __iomem *base, unsigned int off, unsigned int *val)
44 *val = readl(base + off);
48 * pmc_write() - write content of val at address base + off
51 * @off: offset to write to
52 * @val: content to be written at base + off
56 void pmc_write(void __iomem *base, unsigned int off, unsigned int val)
58 writel(val, base + off);
62 * pmc_update_bits() - update a set of bits at address base + off
65 * @off: offset to be updated
66 * @mask: mask of bits to be updated
67 * @bits: the new value to be updated
71 void pmc_update_bits(void __iomem *base, unsigned int off,
72 unsigned int mask, unsigned int bits)
76 tmp = readl(base + off);
78 writel(tmp | (bits & mask), base + off);
82 * at91_clk_mux_val_to_index() - get parent index in mux table
84 * @table: clock mux table
85 * @num_parents: clock number of parents
86 * @val: clock id who's mux index should be retrieved
88 * @return: clock index in mux table or a negative error number in case of
91 int at91_clk_mux_val_to_index(const u32 *table, u32 num_parents, u32 val)
95 if (!table || !num_parents)
98 for (i = 0; i < num_parents; i++) {
107 * at91_clk_mux_index_to_val() - get parent ID corresponding to an entry in
110 * @table: clock's mux table
111 * @num_parents: clock's number of parents
112 * @index: index in mux table which clock's ID should be retrieved
114 * @return: clock ID or a negative error number in case of failure
116 int at91_clk_mux_index_to_val(const u32 *table, u32 num_parents, u32 index)
118 if (!table || !num_parents || index < 0 || index > num_parents)
124 int at91_clk_setup(const struct pmc_clk_setup *setup, int size)
126 struct clk *c, *parent;
135 for (i = 0; i < size; i++) {
136 ret = clk_get_by_id(setup[i].cid, &c);
141 ret = clk_get_by_id(setup[i].pid, &parent);
145 ret = clk_set_parent(c, parent);
149 if (setup[i].prate) {
150 ret = clk_set_rate(parent, setup[i].prate);
157 ret = clk_set_rate(c, setup[i].rate);