1 // SPDX-License-Identifier: GPL-2.0+
3 * Texas Instruments sysc interconnect target driver
5 * Copyright (C) 2020 Dario Binacchi <dariobin@libero.it>
11 #include <dm/device_compat.h>
19 static const char *const clock_names[] = {"fck", "ick"};
23 struct clk clocks[TI_SYSC_MAX_CLOCKS];
26 static const struct udevice_id ti_sysc_ids[] = {
27 {.compatible = "ti,sysc-omap2"},
28 {.compatible = "ti,sysc-omap4"},
29 {.compatible = "ti,sysc-omap4-simple"},
30 {.compatible = "ti,sysc-omap3430-sr"},
31 {.compatible = "ti,sysc-omap3630-sr"},
32 {.compatible = "ti,sysc-omap4-sr"},
33 {.compatible = "ti,sysc-omap3-sham"},
34 {.compatible = "ti,sysc-omap-aes"},
35 {.compatible = "ti,sysc-mcasp"},
36 {.compatible = "ti,sysc-usb-host-fs"},
40 static int ti_sysc_get_one_clock(struct udevice *dev, enum ti_sysc_clocks index)
42 struct ti_sysc_priv *priv = dev_get_priv(dev);
55 name = clock_names[index];
57 err = clk_get_by_name(dev, name, &priv->clocks[index]);
62 dev_err(dev, "failed to get %s clock\n", name);
69 static int ti_sysc_put_clocks(struct udevice *dev)
71 struct ti_sysc_priv *priv = dev_get_priv(dev);
74 err = clk_release_all(priv->clocks, priv->clocks_count);
76 dev_err(dev, "failed to release all clocks\n");
81 static int ti_sysc_get_clocks(struct udevice *dev)
83 struct ti_sysc_priv *priv = dev_get_priv(dev);
86 for (i = 0; i < TI_SYSC_MAX_CLOCKS; i++) {
87 err = ti_sysc_get_one_clock(dev, i);
90 else if (err != -ENOENT)
97 static int ti_sysc_child_post_remove(struct udevice *dev)
99 struct ti_sysc_priv *priv = dev_get_priv(dev->parent);
102 for (i = 0; i < priv->clocks_count; i++) {
103 err = clk_disable(&priv->clocks[i]);
105 dev_err(dev->parent, "failed to disable %s clock\n",
114 static int ti_sysc_child_pre_probe(struct udevice *dev)
116 struct ti_sysc_priv *priv = dev_get_priv(dev->parent);
119 for (i = 0; i < priv->clocks_count; i++) {
120 err = clk_enable(&priv->clocks[i]);
122 dev_err(dev->parent, "failed to enable %s clock\n",
131 static int ti_sysc_remove(struct udevice *dev)
133 return ti_sysc_put_clocks(dev);
136 static int ti_sysc_probe(struct udevice *dev)
140 err = ti_sysc_get_clocks(dev);
147 ti_sysc_put_clocks(dev);
151 U_BOOT_DRIVER(ti_sysc) = {
153 .id = UCLASS_SIMPLE_BUS,
154 .of_match = ti_sysc_ids,
155 .probe = ti_sysc_probe,
156 .remove = ti_sysc_remove,
157 .child_pre_probe = ti_sysc_child_pre_probe,
158 .child_post_remove = ti_sysc_child_post_remove,
159 .priv_auto = sizeof(struct ti_sysc_priv)