blob: 85beaacb40885fe92776f9ce43aa0ed95d58a6c9 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +02002/*
3 * Copyright (C) 2013 Pengutronix
4 * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +02005 */
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +02006#include <linux/io.h>
7#include <linux/clk-provider.h>
8#include <linux/of.h>
9#include <linux/of_address.h>
Stephen Boyd93376312016-06-01 16:15:14 -070010#include <linux/slab.h>
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020011
12#include <dt-bindings/clock/efm32-cmu.h>
13
14#define CMU_HFPERCLKEN0 0x44
Stephen Boyd93376312016-06-01 16:15:14 -070015#define CMU_MAX_CLKS 37
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020016
Stephen Boyd93376312016-06-01 16:15:14 -070017static struct clk_hw_onecell_data *clk_data;
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020018
Uwe Kleine-König8ce8ebe2014-07-28 16:38:21 +020019static void __init efm32gg_cmu_init(struct device_node *np)
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020020{
21 int i;
22 void __iomem *base;
Stephen Boyd93376312016-06-01 16:15:14 -070023 struct clk_hw **hws;
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020024
Kees Cookacafe7e2018-05-08 13:45:50 -070025 clk_data = kzalloc(struct_size(clk_data, hws, CMU_MAX_CLKS),
26 GFP_KERNEL);
Stephen Boyd93376312016-06-01 16:15:14 -070027
28 if (!clk_data)
29 return;
30
31 hws = clk_data->hws;
32
33 for (i = 0; i < CMU_MAX_CLKS; ++i)
34 hws[i] = ERR_PTR(-ENOENT);
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020035
36 base = of_iomap(np, 0);
37 if (!base) {
38 pr_warn("Failed to map address range for efm32gg,cmu node\n");
Uwe Kleine-König8ce8ebe2014-07-28 16:38:21 +020039 return;
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020040 }
41
Stephen Boyd93376312016-06-01 16:15:14 -070042 hws[clk_HFXO] = clk_hw_register_fixed_rate(NULL, "HFXO", NULL, 0,
43 48000000);
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020044
Stephen Boyd93376312016-06-01 16:15:14 -070045 hws[clk_HFPERCLKUSART0] = clk_hw_register_gate(NULL, "HFPERCLK.USART0",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020046 "HFXO", 0, base + CMU_HFPERCLKEN0, 0, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070047 hws[clk_HFPERCLKUSART1] = clk_hw_register_gate(NULL, "HFPERCLK.USART1",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020048 "HFXO", 0, base + CMU_HFPERCLKEN0, 1, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070049 hws[clk_HFPERCLKUSART2] = clk_hw_register_gate(NULL, "HFPERCLK.USART2",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020050 "HFXO", 0, base + CMU_HFPERCLKEN0, 2, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070051 hws[clk_HFPERCLKUART0] = clk_hw_register_gate(NULL, "HFPERCLK.UART0",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020052 "HFXO", 0, base + CMU_HFPERCLKEN0, 3, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070053 hws[clk_HFPERCLKUART1] = clk_hw_register_gate(NULL, "HFPERCLK.UART1",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020054 "HFXO", 0, base + CMU_HFPERCLKEN0, 4, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070055 hws[clk_HFPERCLKTIMER0] = clk_hw_register_gate(NULL, "HFPERCLK.TIMER0",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020056 "HFXO", 0, base + CMU_HFPERCLKEN0, 5, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070057 hws[clk_HFPERCLKTIMER1] = clk_hw_register_gate(NULL, "HFPERCLK.TIMER1",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020058 "HFXO", 0, base + CMU_HFPERCLKEN0, 6, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070059 hws[clk_HFPERCLKTIMER2] = clk_hw_register_gate(NULL, "HFPERCLK.TIMER2",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020060 "HFXO", 0, base + CMU_HFPERCLKEN0, 7, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070061 hws[clk_HFPERCLKTIMER3] = clk_hw_register_gate(NULL, "HFPERCLK.TIMER3",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020062 "HFXO", 0, base + CMU_HFPERCLKEN0, 8, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070063 hws[clk_HFPERCLKACMP0] = clk_hw_register_gate(NULL, "HFPERCLK.ACMP0",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020064 "HFXO", 0, base + CMU_HFPERCLKEN0, 9, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070065 hws[clk_HFPERCLKACMP1] = clk_hw_register_gate(NULL, "HFPERCLK.ACMP1",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020066 "HFXO", 0, base + CMU_HFPERCLKEN0, 10, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070067 hws[clk_HFPERCLKI2C0] = clk_hw_register_gate(NULL, "HFPERCLK.I2C0",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020068 "HFXO", 0, base + CMU_HFPERCLKEN0, 11, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070069 hws[clk_HFPERCLKI2C1] = clk_hw_register_gate(NULL, "HFPERCLK.I2C1",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020070 "HFXO", 0, base + CMU_HFPERCLKEN0, 12, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070071 hws[clk_HFPERCLKGPIO] = clk_hw_register_gate(NULL, "HFPERCLK.GPIO",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020072 "HFXO", 0, base + CMU_HFPERCLKEN0, 13, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070073 hws[clk_HFPERCLKVCMP] = clk_hw_register_gate(NULL, "HFPERCLK.VCMP",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020074 "HFXO", 0, base + CMU_HFPERCLKEN0, 14, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070075 hws[clk_HFPERCLKPRS] = clk_hw_register_gate(NULL, "HFPERCLK.PRS",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020076 "HFXO", 0, base + CMU_HFPERCLKEN0, 15, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070077 hws[clk_HFPERCLKADC0] = clk_hw_register_gate(NULL, "HFPERCLK.ADC0",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020078 "HFXO", 0, base + CMU_HFPERCLKEN0, 16, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070079 hws[clk_HFPERCLKDAC0] = clk_hw_register_gate(NULL, "HFPERCLK.DAC0",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020080 "HFXO", 0, base + CMU_HFPERCLKEN0, 17, 0, NULL);
81
Stephen Boydbdfdabf2016-11-16 11:02:00 -080082 of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020083}
84CLK_OF_DECLARE(efm32ggcmu, "efm32gg,cmu", efm32gg_cmu_init);