blob: a12aaa2f4cd95c8644d1b5e312b0ae52f4fc7f2b [file] [log] [blame]
Jim Liu25688562022-04-19 13:32:20 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (c) 2021 Nuvoton Technology Corp.
4 */
5
6#include <dm.h>
7#include <dt-bindings/clock/nuvoton,npcm7xx-clock.h>
8#include "clk_npcm.h"
9
10/* Parent clock map */
11static const struct parent_data pll_parents[] = {
12 {NPCM7XX_CLK_PLL0, 0},
13 {NPCM7XX_CLK_PLL1, 1},
14 {NPCM7XX_CLK_REFCLK, 2},
15 {NPCM7XX_CLK_PLL2DIV2, 3}
16};
17
18static const struct parent_data cpuck_parents[] = {
19 {NPCM7XX_CLK_PLL0, 0},
20 {NPCM7XX_CLK_PLL1, 1},
21 {NPCM7XX_CLK_REFCLK, 2},
22};
23
24static const struct parent_data apb_parent[] = {{NPCM7XX_CLK_AHB, 0}};
25
26static struct npcm_clk_pll npcm7xx_clk_plls[] = {
27 {NPCM7XX_CLK_PLL0, NPCM7XX_CLK_REFCLK, PLLCON0, 0},
28 {NPCM7XX_CLK_PLL1, NPCM7XX_CLK_REFCLK, PLLCON1, 0},
29 {NPCM7XX_CLK_PLL2, NPCM7XX_CLK_REFCLK, PLLCON2, 0},
30 {NPCM7XX_CLK_PLL2DIV2, NPCM7XX_CLK_REFCLK, PLLCON2, POST_DIV2}
31};
32
33static struct npcm_clk_select npcm7xx_clk_selectors[] = {
34 {NPCM7XX_CLK_AHB, cpuck_parents, CLKSEL, NPCM7XX_CPUCKSEL, 3, 0},
35 {NPCM7XX_CLK_APB2, apb_parent, 0, 0, 1, FIXED_PARENT},
36 {NPCM7XX_CLK_APB5, apb_parent, 0, 0, 1, FIXED_PARENT},
37 {NPCM7XX_CLK_SPI0, apb_parent, 0, 0, 1, FIXED_PARENT},
38 {NPCM7XX_CLK_SPI3, apb_parent, 0, 0, 1, FIXED_PARENT},
39 {NPCM7XX_CLK_SPIX, apb_parent, 0, 0, 1, FIXED_PARENT},
40 {NPCM7XX_CLK_UART, pll_parents, CLKSEL, UARTCKSEL, 4, 0},
41 {NPCM7XX_CLK_TIMER, pll_parents, CLKSEL, TIMCKSEL, 4, 0},
42 {NPCM7XX_CLK_SDHC, pll_parents, CLKSEL, SDCKSEL, 4, 0}
43};
44
45static struct npcm_clk_div npcm7xx_clk_dividers[] = {
46 {NPCM7XX_CLK_AHB, CLKDIV1, CLK4DIV, DIV_TYPE1 | PRE_DIV2},
47 {NPCM7XX_CLK_APB2, CLKDIV2, APB2CKDIV, DIV_TYPE2},
48 {NPCM7XX_CLK_APB5, CLKDIV2, APB5CKDIV, DIV_TYPE2},
49 {NPCM7XX_CLK_SPI0, CLKDIV3, SPI0CKDIV, DIV_TYPE1},
50 {NPCM7XX_CLK_SPI3, CLKDIV1, SPI3CKDIV, DIV_TYPE1},
51 {NPCM7XX_CLK_SPIX, CLKDIV3, SPIXCKDIV, DIV_TYPE1},
52 {NPCM7XX_CLK_UART, CLKDIV1, UARTDIV1, DIV_TYPE1},
53 {NPCM7XX_CLK_TIMER, CLKDIV1, TIMCKDIV, DIV_TYPE2},
54 {NPCM7XX_CLK_SDHC, CLKDIV1, MMCCKDIV, DIV_TYPE1}
55};
56
57static struct npcm_clk_data npcm7xx_clk_data = {
58 .clk_plls = npcm7xx_clk_plls,
59 .num_plls = ARRAY_SIZE(npcm7xx_clk_plls),
60 .clk_selectors = npcm7xx_clk_selectors,
61 .num_selectors = ARRAY_SIZE(npcm7xx_clk_selectors),
62 .clk_dividers = npcm7xx_clk_dividers,
63 .num_dividers = ARRAY_SIZE(npcm7xx_clk_dividers),
64 .refclk_id = NPCM7XX_CLK_REFCLK,
65 .pll0_id = NPCM7XX_CLK_PLL0,
66};
67
68static int npcm7xx_clk_probe(struct udevice *dev)
69{
70 struct npcm_clk_priv *priv = dev_get_priv(dev);
71
72 priv->base = dev_read_addr_ptr(dev);
73 if (!priv->base)
74 return -EINVAL;
75
76 priv->clk_data = &npcm7xx_clk_data;
77 priv->num_clks = NPCM7XX_NUM_CLOCKS;
78
79 return 0;
80}
81
82static const struct udevice_id npcm7xx_clk_ids[] = {
83 { .compatible = "nuvoton,npcm750-clk" },
84 { }
85};
86
87U_BOOT_DRIVER(clk_npcm) = {
88 .name = "clk_npcm",
89 .id = UCLASS_CLK,
90 .of_match = npcm7xx_clk_ids,
91 .ops = &npcm_clk_ops,
92 .priv_auto = sizeof(struct npcm_clk_priv),
93 .probe = npcm7xx_clk_probe,
94 .flags = DM_FLAG_PRE_RELOC,
95};