2013-10-08 15:57:20 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Pengutronix
|
|
|
|
* Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License version 2 as published by the
|
|
|
|
* Free Software Foundation.
|
|
|
|
*/
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/clk-provider.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_address.h>
|
2016-06-02 07:15:14 +08:00
|
|
|
#include <linux/slab.h>
|
2013-10-08 15:57:20 +08:00
|
|
|
|
|
|
|
#include <dt-bindings/clock/efm32-cmu.h>
|
|
|
|
|
|
|
|
#define CMU_HFPERCLKEN0 0x44
|
2016-06-02 07:15:14 +08:00
|
|
|
#define CMU_MAX_CLKS 37
|
2013-10-08 15:57:20 +08:00
|
|
|
|
2016-06-02 07:15:14 +08:00
|
|
|
static struct clk_hw_onecell_data *clk_data;
|
2013-10-08 15:57:20 +08:00
|
|
|
|
clk/efm32gg: fix dt init prototype
Since commit 54196ccbe0ba (of: consolidate linker section OF match table
declarations) which went into 3.16-rc1 the following compiler warning is
generated:
In file included from drivers/clk/clk-efm32gg.c:12:0: include/linux/of.h:772:20:
warning: comparison of distinct pointer types lacks a cast [enabled by default]
.data = (fn == (fn_type)NULL) ? fn : fn }
^
include/linux/of.h:785:3: note: in expansion of macro '_OF_DECLARE'
_OF_DECLARE(table, name, compat, fn, of_init_fn_1)
^
include/linux/clk-provider.h:545:42: note: in expansion of macro 'OF_DECLARE_1'
#define CLK_OF_DECLARE(name, compat, fn) OF_DECLARE_1(clk, name, compat, fn)
^
drivers/clk/clk-efm32gg.c:81:1: note: in expansion of macro 'CLK_OF_DECLARE'
CLK_OF_DECLARE(efm32ggcmu, "efm32gg,cmu", efm32gg_cmu_init);
^
Fix it by making efm32gg_cmu_init return void.
Cc: Rob Herring <robh@kernel.org>
Reported-by: Bryan Hundven <bryanhundven@gmail.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
2014-07-28 22:38:21 +08:00
|
|
|
static void __init efm32gg_cmu_init(struct device_node *np)
|
2013-10-08 15:57:20 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
void __iomem *base;
|
2016-06-02 07:15:14 +08:00
|
|
|
struct clk_hw **hws;
|
2013-10-08 15:57:20 +08:00
|
|
|
|
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
|
|
|
clk_data = kzalloc(struct_size(clk_data, hws, CMU_MAX_CLKS),
|
|
|
|
GFP_KERNEL);
|
2016-06-02 07:15:14 +08:00
|
|
|
|
|
|
|
if (!clk_data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
hws = clk_data->hws;
|
|
|
|
|
|
|
|
for (i = 0; i < CMU_MAX_CLKS; ++i)
|
|
|
|
hws[i] = ERR_PTR(-ENOENT);
|
2013-10-08 15:57:20 +08:00
|
|
|
|
|
|
|
base = of_iomap(np, 0);
|
|
|
|
if (!base) {
|
|
|
|
pr_warn("Failed to map address range for efm32gg,cmu node\n");
|
clk/efm32gg: fix dt init prototype
Since commit 54196ccbe0ba (of: consolidate linker section OF match table
declarations) which went into 3.16-rc1 the following compiler warning is
generated:
In file included from drivers/clk/clk-efm32gg.c:12:0: include/linux/of.h:772:20:
warning: comparison of distinct pointer types lacks a cast [enabled by default]
.data = (fn == (fn_type)NULL) ? fn : fn }
^
include/linux/of.h:785:3: note: in expansion of macro '_OF_DECLARE'
_OF_DECLARE(table, name, compat, fn, of_init_fn_1)
^
include/linux/clk-provider.h:545:42: note: in expansion of macro 'OF_DECLARE_1'
#define CLK_OF_DECLARE(name, compat, fn) OF_DECLARE_1(clk, name, compat, fn)
^
drivers/clk/clk-efm32gg.c:81:1: note: in expansion of macro 'CLK_OF_DECLARE'
CLK_OF_DECLARE(efm32ggcmu, "efm32gg,cmu", efm32gg_cmu_init);
^
Fix it by making efm32gg_cmu_init return void.
Cc: Rob Herring <robh@kernel.org>
Reported-by: Bryan Hundven <bryanhundven@gmail.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
2014-07-28 22:38:21 +08:00
|
|
|
return;
|
2013-10-08 15:57:20 +08:00
|
|
|
}
|
|
|
|
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFXO] = clk_hw_register_fixed_rate(NULL, "HFXO", NULL, 0,
|
|
|
|
48000000);
|
2013-10-08 15:57:20 +08:00
|
|
|
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFPERCLKUSART0] = clk_hw_register_gate(NULL, "HFPERCLK.USART0",
|
2013-10-08 15:57:20 +08:00
|
|
|
"HFXO", 0, base + CMU_HFPERCLKEN0, 0, 0, NULL);
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFPERCLKUSART1] = clk_hw_register_gate(NULL, "HFPERCLK.USART1",
|
2013-10-08 15:57:20 +08:00
|
|
|
"HFXO", 0, base + CMU_HFPERCLKEN0, 1, 0, NULL);
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFPERCLKUSART2] = clk_hw_register_gate(NULL, "HFPERCLK.USART2",
|
2013-10-08 15:57:20 +08:00
|
|
|
"HFXO", 0, base + CMU_HFPERCLKEN0, 2, 0, NULL);
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFPERCLKUART0] = clk_hw_register_gate(NULL, "HFPERCLK.UART0",
|
2013-10-08 15:57:20 +08:00
|
|
|
"HFXO", 0, base + CMU_HFPERCLKEN0, 3, 0, NULL);
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFPERCLKUART1] = clk_hw_register_gate(NULL, "HFPERCLK.UART1",
|
2013-10-08 15:57:20 +08:00
|
|
|
"HFXO", 0, base + CMU_HFPERCLKEN0, 4, 0, NULL);
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFPERCLKTIMER0] = clk_hw_register_gate(NULL, "HFPERCLK.TIMER0",
|
2013-10-08 15:57:20 +08:00
|
|
|
"HFXO", 0, base + CMU_HFPERCLKEN0, 5, 0, NULL);
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFPERCLKTIMER1] = clk_hw_register_gate(NULL, "HFPERCLK.TIMER1",
|
2013-10-08 15:57:20 +08:00
|
|
|
"HFXO", 0, base + CMU_HFPERCLKEN0, 6, 0, NULL);
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFPERCLKTIMER2] = clk_hw_register_gate(NULL, "HFPERCLK.TIMER2",
|
2013-10-08 15:57:20 +08:00
|
|
|
"HFXO", 0, base + CMU_HFPERCLKEN0, 7, 0, NULL);
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFPERCLKTIMER3] = clk_hw_register_gate(NULL, "HFPERCLK.TIMER3",
|
2013-10-08 15:57:20 +08:00
|
|
|
"HFXO", 0, base + CMU_HFPERCLKEN0, 8, 0, NULL);
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFPERCLKACMP0] = clk_hw_register_gate(NULL, "HFPERCLK.ACMP0",
|
2013-10-08 15:57:20 +08:00
|
|
|
"HFXO", 0, base + CMU_HFPERCLKEN0, 9, 0, NULL);
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFPERCLKACMP1] = clk_hw_register_gate(NULL, "HFPERCLK.ACMP1",
|
2013-10-08 15:57:20 +08:00
|
|
|
"HFXO", 0, base + CMU_HFPERCLKEN0, 10, 0, NULL);
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFPERCLKI2C0] = clk_hw_register_gate(NULL, "HFPERCLK.I2C0",
|
2013-10-08 15:57:20 +08:00
|
|
|
"HFXO", 0, base + CMU_HFPERCLKEN0, 11, 0, NULL);
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFPERCLKI2C1] = clk_hw_register_gate(NULL, "HFPERCLK.I2C1",
|
2013-10-08 15:57:20 +08:00
|
|
|
"HFXO", 0, base + CMU_HFPERCLKEN0, 12, 0, NULL);
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFPERCLKGPIO] = clk_hw_register_gate(NULL, "HFPERCLK.GPIO",
|
2013-10-08 15:57:20 +08:00
|
|
|
"HFXO", 0, base + CMU_HFPERCLKEN0, 13, 0, NULL);
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFPERCLKVCMP] = clk_hw_register_gate(NULL, "HFPERCLK.VCMP",
|
2013-10-08 15:57:20 +08:00
|
|
|
"HFXO", 0, base + CMU_HFPERCLKEN0, 14, 0, NULL);
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFPERCLKPRS] = clk_hw_register_gate(NULL, "HFPERCLK.PRS",
|
2013-10-08 15:57:20 +08:00
|
|
|
"HFXO", 0, base + CMU_HFPERCLKEN0, 15, 0, NULL);
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFPERCLKADC0] = clk_hw_register_gate(NULL, "HFPERCLK.ADC0",
|
2013-10-08 15:57:20 +08:00
|
|
|
"HFXO", 0, base + CMU_HFPERCLKEN0, 16, 0, NULL);
|
2016-06-02 07:15:14 +08:00
|
|
|
hws[clk_HFPERCLKDAC0] = clk_hw_register_gate(NULL, "HFPERCLK.DAC0",
|
2013-10-08 15:57:20 +08:00
|
|
|
"HFXO", 0, base + CMU_HFPERCLKEN0, 17, 0, NULL);
|
|
|
|
|
2016-11-17 03:02:00 +08:00
|
|
|
of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
|
2013-10-08 15:57:20 +08:00
|
|
|
}
|
|
|
|
CLK_OF_DECLARE(efm32ggcmu, "efm32gg,cmu", efm32gg_cmu_init);
|