2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2014-06-25 00:08:26 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 Samsung Electronics Co., Ltd.
|
|
|
|
* Author: Tomasz Figa <t.figa@samsung.com>
|
|
|
|
*
|
|
|
|
* Clock driver for Exynos clock output
|
|
|
|
*/
|
|
|
|
|
2015-06-20 06:00:46 +08:00
|
|
|
#include <linux/slab.h>
|
2014-06-25 00:08:26 +08:00
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/clk-provider.h>
|
2019-04-19 06:20:22 +08:00
|
|
|
#include <linux/io.h>
|
2014-06-25 00:08:26 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/syscore_ops.h>
|
|
|
|
|
|
|
|
#define EXYNOS_CLKOUT_NR_CLKS 1
|
|
|
|
#define EXYNOS_CLKOUT_PARENTS 32
|
|
|
|
|
|
|
|
#define EXYNOS_PMU_DEBUG_REG 0xa00
|
|
|
|
#define EXYNOS_CLKOUT_DISABLE_SHIFT 0
|
|
|
|
#define EXYNOS_CLKOUT_MUX_SHIFT 8
|
|
|
|
#define EXYNOS4_CLKOUT_MUX_MASK 0xf
|
|
|
|
#define EXYNOS5_CLKOUT_MUX_MASK 0x1f
|
|
|
|
|
|
|
|
struct exynos_clkout {
|
|
|
|
struct clk_gate gate;
|
|
|
|
struct clk_mux mux;
|
|
|
|
spinlock_t slock;
|
|
|
|
void __iomem *reg;
|
|
|
|
u32 pmu_debug_save;
|
2017-04-24 14:42:22 +08:00
|
|
|
struct clk_hw_onecell_data data;
|
2014-06-25 00:08:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct exynos_clkout *clkout;
|
|
|
|
|
|
|
|
static int exynos_clkout_suspend(void)
|
|
|
|
{
|
|
|
|
clkout->pmu_debug_save = readl(clkout->reg + EXYNOS_PMU_DEBUG_REG);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void exynos_clkout_resume(void)
|
|
|
|
{
|
|
|
|
writel(clkout->pmu_debug_save, clkout->reg + EXYNOS_PMU_DEBUG_REG);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct syscore_ops exynos_clkout_syscore_ops = {
|
|
|
|
.suspend = exynos_clkout_suspend,
|
|
|
|
.resume = exynos_clkout_resume,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void __init exynos_clkout_init(struct device_node *node, u32 mux_mask)
|
|
|
|
{
|
|
|
|
const char *parent_names[EXYNOS_CLKOUT_PARENTS];
|
|
|
|
struct clk *parents[EXYNOS_CLKOUT_PARENTS];
|
|
|
|
int parent_count;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
treewide: Use struct_size() for kmalloc()-family
One of the more common cases of allocation size calculations is finding
the size of a structure that has a zero-sized array at the end, along
with memory for some number of elements for that array. For example:
struct foo {
int stuff;
void *entry[];
};
instance = kmalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);
Instead of leaving these open-coded and prone to type mistakes, we can
now use the new struct_size() helper:
instance = kmalloc(struct_size(instance, entry, count), GFP_KERNEL);
This patch makes the changes for kmalloc()-family (and kvmalloc()-family)
uses. It was done via automatic conversion with manual review for the
"CHECKME" non-standard cases noted below, using the following Coccinelle
script:
// pkey_cache = kmalloc(sizeof *pkey_cache + tprops->pkey_tbl_len *
// sizeof *pkey_cache->table, GFP_KERNEL);
@@
identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
expression GFP;
identifier VAR, ELEMENT;
expression COUNT;
@@
- alloc(sizeof(*VAR) + COUNT * sizeof(*VAR->ELEMENT), GFP)
+ alloc(struct_size(VAR, ELEMENT, COUNT), GFP)
// mr = kzalloc(sizeof(*mr) + m * sizeof(mr->map[0]), GFP_KERNEL);
@@
identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
expression GFP;
identifier VAR, ELEMENT;
expression COUNT;
@@
- alloc(sizeof(*VAR) + COUNT * sizeof(VAR->ELEMENT[0]), GFP)
+ alloc(struct_size(VAR, ELEMENT, COUNT), GFP)
// Same pattern, but can't trivially locate the trailing element name,
// or variable name.
@@
identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
expression GFP;
expression SOMETHING, COUNT, ELEMENT;
@@
- alloc(sizeof(SOMETHING) + COUNT * sizeof(ELEMENT), GFP)
+ alloc(CHECKME_struct_size(&SOMETHING, ELEMENT, COUNT), GFP)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-05-09 04:45:50 +08:00
|
|
|
clkout = kzalloc(struct_size(clkout, data.hws, EXYNOS_CLKOUT_NR_CLKS),
|
2017-04-24 14:42:22 +08:00
|
|
|
GFP_KERNEL);
|
2014-06-25 00:08:26 +08:00
|
|
|
if (!clkout)
|
|
|
|
return;
|
|
|
|
|
|
|
|
spin_lock_init(&clkout->slock);
|
|
|
|
|
|
|
|
parent_count = 0;
|
|
|
|
for (i = 0; i < EXYNOS_CLKOUT_PARENTS; ++i) {
|
|
|
|
char name[] = "clkoutXX";
|
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "clkout%d", i);
|
|
|
|
parents[i] = of_clk_get_by_name(node, name);
|
|
|
|
if (IS_ERR(parents[i])) {
|
|
|
|
parent_names[i] = "none";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent_names[i] = __clk_get_name(parents[i]);
|
|
|
|
parent_count = i + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parent_count)
|
|
|
|
goto free_clkout;
|
|
|
|
|
|
|
|
clkout->reg = of_iomap(node, 0);
|
|
|
|
if (!clkout->reg)
|
|
|
|
goto clks_put;
|
|
|
|
|
|
|
|
clkout->gate.reg = clkout->reg + EXYNOS_PMU_DEBUG_REG;
|
|
|
|
clkout->gate.bit_idx = EXYNOS_CLKOUT_DISABLE_SHIFT;
|
|
|
|
clkout->gate.flags = CLK_GATE_SET_TO_DISABLE;
|
|
|
|
clkout->gate.lock = &clkout->slock;
|
|
|
|
|
|
|
|
clkout->mux.reg = clkout->reg + EXYNOS_PMU_DEBUG_REG;
|
|
|
|
clkout->mux.mask = mux_mask;
|
|
|
|
clkout->mux.shift = EXYNOS_CLKOUT_MUX_SHIFT;
|
|
|
|
clkout->mux.lock = &clkout->slock;
|
|
|
|
|
2017-04-24 14:42:22 +08:00
|
|
|
clkout->data.hws[0] = clk_hw_register_composite(NULL, "clkout",
|
2014-06-25 00:08:26 +08:00
|
|
|
parent_names, parent_count, &clkout->mux.hw,
|
|
|
|
&clk_mux_ops, NULL, NULL, &clkout->gate.hw,
|
|
|
|
&clk_gate_ops, CLK_SET_RATE_PARENT
|
|
|
|
| CLK_SET_RATE_NO_REPARENT);
|
2017-04-24 14:42:22 +08:00
|
|
|
if (IS_ERR(clkout->data.hws[0]))
|
2014-06-25 00:08:26 +08:00
|
|
|
goto err_unmap;
|
|
|
|
|
2017-04-24 14:42:22 +08:00
|
|
|
clkout->data.num = EXYNOS_CLKOUT_NR_CLKS;
|
|
|
|
ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, &clkout->data);
|
2014-06-25 00:08:26 +08:00
|
|
|
if (ret)
|
|
|
|
goto err_clk_unreg;
|
|
|
|
|
|
|
|
register_syscore_ops(&exynos_clkout_syscore_ops);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
err_clk_unreg:
|
2017-04-24 14:42:22 +08:00
|
|
|
clk_hw_unregister(clkout->data.hws[0]);
|
2014-06-25 00:08:26 +08:00
|
|
|
err_unmap:
|
|
|
|
iounmap(clkout->reg);
|
|
|
|
clks_put:
|
|
|
|
for (i = 0; i < EXYNOS_CLKOUT_PARENTS; ++i)
|
|
|
|
if (!IS_ERR(parents[i]))
|
|
|
|
clk_put(parents[i]);
|
|
|
|
free_clkout:
|
|
|
|
kfree(clkout);
|
|
|
|
|
|
|
|
pr_err("%s: failed to register clkout clock\n", __func__);
|
|
|
|
}
|
|
|
|
|
2016-10-26 14:12:20 +08:00
|
|
|
/*
|
|
|
|
* We use CLK_OF_DECLARE_DRIVER initialization method to avoid setting
|
|
|
|
* the OF_POPULATED flag on the pmu device tree node, so later the
|
|
|
|
* Exynos PMU platform device can be properly probed with PMU driver.
|
|
|
|
*/
|
|
|
|
|
2014-06-25 00:08:26 +08:00
|
|
|
static void __init exynos4_clkout_init(struct device_node *node)
|
|
|
|
{
|
|
|
|
exynos_clkout_init(node, EXYNOS4_CLKOUT_MUX_MASK);
|
|
|
|
}
|
2016-10-26 14:12:20 +08:00
|
|
|
CLK_OF_DECLARE_DRIVER(exynos4210_clkout, "samsung,exynos4210-pmu",
|
2014-06-25 00:08:26 +08:00
|
|
|
exynos4_clkout_init);
|
2016-10-26 14:12:20 +08:00
|
|
|
CLK_OF_DECLARE_DRIVER(exynos4412_clkout, "samsung,exynos4412-pmu",
|
2014-06-25 00:08:26 +08:00
|
|
|
exynos4_clkout_init);
|
2016-10-26 14:12:20 +08:00
|
|
|
CLK_OF_DECLARE_DRIVER(exynos3250_clkout, "samsung,exynos3250-pmu",
|
2015-03-02 10:15:00 +08:00
|
|
|
exynos4_clkout_init);
|
2014-06-25 00:08:26 +08:00
|
|
|
|
|
|
|
static void __init exynos5_clkout_init(struct device_node *node)
|
|
|
|
{
|
|
|
|
exynos_clkout_init(node, EXYNOS5_CLKOUT_MUX_MASK);
|
|
|
|
}
|
2016-10-26 14:12:20 +08:00
|
|
|
CLK_OF_DECLARE_DRIVER(exynos5250_clkout, "samsung,exynos5250-pmu",
|
2014-06-25 00:08:26 +08:00
|
|
|
exynos5_clkout_init);
|
2016-10-26 14:12:20 +08:00
|
|
|
CLK_OF_DECLARE_DRIVER(exynos5410_clkout, "samsung,exynos5410-pmu",
|
2016-05-16 16:26:47 +08:00
|
|
|
exynos5_clkout_init);
|
2016-10-26 14:12:20 +08:00
|
|
|
CLK_OF_DECLARE_DRIVER(exynos5420_clkout, "samsung,exynos5420-pmu",
|
2014-06-25 00:08:26 +08:00
|
|
|
exynos5_clkout_init);
|
2016-10-26 14:12:20 +08:00
|
|
|
CLK_OF_DECLARE_DRIVER(exynos5433_clkout, "samsung,exynos5433-pmu",
|
2015-02-03 08:13:57 +08:00
|
|
|
exynos5_clkout_init);
|