From 477b665671ef0a0004f91587367bbcba2b3baaa9 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 29 Sep 2012 01:21:41 +0200 Subject: clk: Add clk gate support Signed-off-by: Sascha Hauer --- drivers/clk/Makefile | 3 +- drivers/clk/clk-gate.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 drivers/clk/clk-gate.c (limited to 'drivers/clk') diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index 39a75a4e4a..3cc7163829 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile @@ -1,2 +1,3 @@ -obj-$(CONFIG_COMMON_CLK) += clk.o clk-fixed.o clk-divider.o clk-fixed-factor.o clk-mux.o +obj-$(CONFIG_COMMON_CLK) += clk.o clk-fixed.o clk-divider.o clk-fixed-factor.o \ + clk-mux.o clk-gate.o obj-$(CONFIG_CLKDEV_LOOKUP) += clkdev.o diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c new file mode 100644 index 0000000000..cf1bb1af62 --- /dev/null +++ b/drivers/clk/clk-gate.c @@ -0,0 +1,78 @@ +/* + * clk-gate.c - generic barebox clock support. Based on Linux clk support + * + * Copyright (c) 2012 Sascha Hauer , Pengutronix + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ +#include +#include +#include +#include +#include + +struct clk_gate { + struct clk clk; + void __iomem *reg; + int shift; + const char *parent; +}; + +static int clk_gate_enable(struct clk *clk) +{ + struct clk_gate *g = container_of(clk, struct clk_gate, clk); + u32 val; + + val = readl(g->reg); + val |= 1 << g->shift; + writel(val, g->reg); + + return 0; +} + +static void clk_gate_disable(struct clk *clk) +{ + struct clk_gate *g = container_of(clk, struct clk_gate, clk); + u32 val; + + val = readl(g->reg); + val &= ~(1 << g->shift); + writel(val, g->reg); +} + +struct clk_ops clk_gate_ops = { + .enable = clk_gate_enable, + .disable = clk_gate_disable, +}; + +struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg, + u8 shift) +{ + struct clk_gate *g = xzalloc(sizeof(*g)); + int ret; + + g->parent = parent; + g->reg = reg; + g->shift = shift; + g->clk.ops = &clk_gate_ops; + g->clk.name = name; + g->clk.parent_names = &g->parent; + g->clk.num_parents = 1; + + ret = clk_register(&g->clk); + if (ret) { + free(g); + return ERR_PTR(ret); + } + + return &g->clk; +} -- cgit v1.2.3