1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Atmel Corporation
4 * Wenyou.Yang <wenyou.yang@atmel.com>
8 #include <clk-uclass.h>
12 #include <mach/at91_pmc.h>
13 #include <mach/at91_sfr.h>
17 * The purpose of this clock is to generate a 480 MHz signal. A different
18 * rate can't be configured.
20 #define UTMI_RATE 480000000
22 static int utmi_clk_enable(struct clk *clk)
24 struct pmc_platdata *plat = dev_get_platdata(clk->dev);
25 struct at91_pmc *pmc = plat->reg_base;
28 u32 utmi_ref_clk_freq;
31 int timeout = 2000000;
33 if (readl(&pmc->sr) & AT91_PMC_LOCKU)
37 * If mainck rate is different from 12 MHz, we have to configure the
38 * FREQ field of the SFR_UTMICKTRIM register to generate properly
41 err = clk_get_by_index(clk->dev, 0, &clk_dev);
45 clk_rate = clk_get_rate(&clk_dev);
48 utmi_ref_clk_freq = 0;
51 utmi_ref_clk_freq = 1;
54 utmi_ref_clk_freq = 2;
57 * Not supported on SAMA5D2 but it's not an issue since MAINCK
58 * maximum value is 24 MHz.
61 utmi_ref_clk_freq = 3;
64 printf("UTMICK: unsupported mainck rate\n");
68 if (plat->regmap_sfr) {
69 err = regmap_read(plat->regmap_sfr, AT91_SFR_UTMICKTRIM, &tmp);
73 tmp &= ~AT91_UTMICKTRIM_FREQ;
74 tmp |= utmi_ref_clk_freq;
75 err = regmap_write(plat->regmap_sfr, AT91_SFR_UTMICKTRIM, tmp);
78 } else if (utmi_ref_clk_freq) {
79 printf("UTMICK: sfr node required\n");
83 tmp = readl(&pmc->uckr);
84 tmp |= AT91_PMC_UPLLEN |
87 writel(tmp, &pmc->uckr);
89 while ((--timeout) && !(readl(&pmc->sr) & AT91_PMC_LOCKU))
92 printf("UTMICK: timeout waiting for UPLL lock\n");
99 static ulong utmi_clk_get_rate(struct clk *clk)
101 /* UTMI clk rate is fixed. */
105 static struct clk_ops utmi_clk_ops = {
106 .enable = utmi_clk_enable,
107 .get_rate = utmi_clk_get_rate,
110 static int utmi_clk_ofdata_to_platdata(struct udevice *dev)
112 struct pmc_platdata *plat = dev_get_platdata(dev);
113 struct udevice *syscon;
115 uclass_get_device_by_phandle(UCLASS_SYSCON, dev,
116 "regmap-sfr", &syscon);
119 plat->regmap_sfr = syscon_get_regmap(syscon);
124 static int utmi_clk_probe(struct udevice *dev)
126 return at91_pmc_core_probe(dev);
129 static const struct udevice_id utmi_clk_match[] = {
130 { .compatible = "atmel,at91sam9x5-clk-utmi" },
134 U_BOOT_DRIVER(at91sam9x5_utmi_clk) = {
135 .name = "at91sam9x5-utmi-clk",
137 .of_match = utmi_clk_match,
138 .probe = utmi_clk_probe,
139 .ofdata_to_platdata = utmi_clk_ofdata_to_platdata,
140 .platdata_auto_alloc_size = sizeof(struct pmc_platdata),
141 .ops = &utmi_clk_ops,