diff options
Diffstat (limited to 'drivers/clk')
-rw-r--r-- | drivers/clk/Kconfig | 19 | ||||
-rw-r--r-- | drivers/clk/Makefile | 9 | ||||
-rw-r--r-- | drivers/clk/clk-uclass.c | 58 | ||||
-rw-r--r-- | drivers/clk/clk_sandbox.c | 85 |
4 files changed, 171 insertions, 0 deletions
diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig new file mode 100644 index 0000000000..07eb54c597 --- /dev/null +++ b/drivers/clk/Kconfig @@ -0,0 +1,19 @@ +config CLK + bool "Enable clock driver support" + depends on DM + help + This allows drivers to be provided for clock generators, including + oscillators and PLLs. Devices can use a common clock API to request + a particular clock rate and check on available clocks. Clocks can + feed into other clocks in a tree structure, with multiplexers to + choose the source for each clock. + +config SPL_CLK_SUPPORT + bool "Enable clock support in SPL" + depends on CLK + help + The clock subsystem adds a small amount of overhead to the image. + If this is acceptable and you have a need to use clock drivers in + SPL, enable this option. It might provide a cleaner interface to + setting up clocks within SPL, and allows the same drivers to be + used as U-Boot proper. diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile new file mode 100644 index 0000000000..bb89fb918b --- /dev/null +++ b/drivers/clk/Makefile @@ -0,0 +1,9 @@ +# +# Copyright (c) 2015 Google, Inc +# Wolfgang Denk, DENX Software Engineering, wd@denx.de. +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-$(CONFIG_CLK) += clk-uclass.o +obj-$(CONFIG_SANDBOX) += clk_sandbox.o diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c new file mode 100644 index 0000000000..73dfd7d016 --- /dev/null +++ b/drivers/clk/clk-uclass.c @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2015 Google, Inc + * Written by Simon Glass <sjg@chromium.org> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <clk.h> +#include <dm.h> +#include <errno.h> +#include <dm/lists.h> +#include <dm/root.h> + +ulong clk_get_rate(struct udevice *dev) +{ + struct clk_ops *ops = clk_get_ops(dev); + + if (!ops->get_rate) + return -ENOSYS; + + return ops->get_rate(dev); +} + +ulong clk_set_rate(struct udevice *dev, ulong rate) +{ + struct clk_ops *ops = clk_get_ops(dev); + + if (!ops->set_rate) + return -ENOSYS; + + return ops->set_rate(dev, rate); +} + +ulong clk_get_periph_rate(struct udevice *dev, int periph) +{ + struct clk_ops *ops = clk_get_ops(dev); + + if (!ops->get_periph_rate) + return -ENOSYS; + + return ops->get_periph_rate(dev, periph); +} + +ulong clk_set_periph_rate(struct udevice *dev, int periph, ulong rate) +{ + struct clk_ops *ops = clk_get_ops(dev); + + if (!ops->set_periph_rate) + return -ENOSYS; + + return ops->set_periph_rate(dev, periph, rate); +} + +UCLASS_DRIVER(clk) = { + .id = UCLASS_CLK, + .name = "clk", +}; diff --git a/drivers/clk/clk_sandbox.c b/drivers/clk/clk_sandbox.c new file mode 100644 index 0000000000..058225a766 --- /dev/null +++ b/drivers/clk/clk_sandbox.c @@ -0,0 +1,85 @@ +/* + * (C) Copyright 2015 Google, Inc + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include <common.h> +#include <clk.h> +#include <dm.h> +#include <errno.h> +#include <asm/test.h> + +struct sandbox_clk_priv { + ulong rate; + ulong periph_rate[PERIPH_ID_COUNT]; +}; + +static ulong sandbox_clk_get_rate(struct udevice *dev) +{ + struct sandbox_clk_priv *priv = dev_get_priv(dev); + + return priv->rate; +} + +static ulong sandbox_clk_set_rate(struct udevice *dev, ulong rate) +{ + struct sandbox_clk_priv *priv = dev_get_priv(dev); + + if (!rate) + return -EINVAL; + priv->rate = rate; + return 0; +} + +ulong sandbox_get_periph_rate(struct udevice *dev, int periph) +{ + struct sandbox_clk_priv *priv = dev_get_priv(dev); + + if (periph < PERIPH_ID_FIRST || periph >= PERIPH_ID_COUNT) + return -EINVAL; + return priv->periph_rate[periph]; +} + +ulong sandbox_set_periph_rate(struct udevice *dev, int periph, ulong rate) +{ + struct sandbox_clk_priv *priv = dev_get_priv(dev); + ulong old_rate; + + if (periph < PERIPH_ID_FIRST || periph >= PERIPH_ID_COUNT) + return -EINVAL; + old_rate = priv->periph_rate[periph]; + priv->periph_rate[periph] = rate; + + return old_rate; +} + +static int sandbox_clk_probe(struct udevice *dev) +{ + struct sandbox_clk_priv *priv = dev_get_priv(dev); + + priv->rate = SANDBOX_CLK_RATE; + + return 0; +} + +static struct clk_ops sandbox_clk_ops = { + .get_rate = sandbox_clk_get_rate, + .set_rate = sandbox_clk_set_rate, + .get_periph_rate = sandbox_get_periph_rate, + .set_periph_rate = sandbox_set_periph_rate, +}; + +static const struct udevice_id sandbox_clk_ids[] = { + { .compatible = "sandbox,clk" }, + { } +}; + +U_BOOT_DRIVER(clk_sandbox) = { + .name = "clk_sandbox", + .id = UCLASS_CLK, + .of_match = sandbox_clk_ids, + .ops = &sandbox_clk_ops, + .priv_auto_alloc_size = sizeof(struct sandbox_clk_priv), + .probe = sandbox_clk_probe, +}; |