blob: f674778fb3ac5912e05fb7448c6b1fb21eefa3d8 [file] [log] [blame]
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +02001/*
2 * Copyright (C) 2013 Pengutronix
3 * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License version 2 as published by the
7 * Free Software Foundation.
8 */
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +02009#include <linux/io.h>
10#include <linux/clk-provider.h>
11#include <linux/of.h>
12#include <linux/of_address.h>
Stephen Boyd93376312016-06-01 16:15:14 -070013#include <linux/slab.h>
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020014
15#include <dt-bindings/clock/efm32-cmu.h>
16
17#define CMU_HFPERCLKEN0 0x44
Stephen Boyd93376312016-06-01 16:15:14 -070018#define CMU_MAX_CLKS 37
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020019
Stephen Boyd93376312016-06-01 16:15:14 -070020static struct clk_hw_onecell_data *clk_data;
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020021
Uwe Kleine-König8ce8ebe2014-07-28 16:38:21 +020022static void __init efm32gg_cmu_init(struct device_node *np)
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020023{
24 int i;
25 void __iomem *base;
Stephen Boyd93376312016-06-01 16:15:14 -070026 struct clk_hw **hws;
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020027
Stephen Boyd93376312016-06-01 16:15:14 -070028 clk_data = kzalloc(sizeof(*clk_data) +
29 sizeof(*clk_data->hws) * CMU_MAX_CLKS, GFP_KERNEL);
30
31 if (!clk_data)
32 return;
33
34 hws = clk_data->hws;
35
36 for (i = 0; i < CMU_MAX_CLKS; ++i)
37 hws[i] = ERR_PTR(-ENOENT);
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020038
39 base = of_iomap(np, 0);
40 if (!base) {
41 pr_warn("Failed to map address range for efm32gg,cmu node\n");
Uwe Kleine-König8ce8ebe2014-07-28 16:38:21 +020042 return;
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020043 }
44
Stephen Boyd93376312016-06-01 16:15:14 -070045 hws[clk_HFXO] = clk_hw_register_fixed_rate(NULL, "HFXO", NULL, 0,
46 48000000);
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020047
Stephen Boyd93376312016-06-01 16:15:14 -070048 hws[clk_HFPERCLKUSART0] = clk_hw_register_gate(NULL, "HFPERCLK.USART0",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020049 "HFXO", 0, base + CMU_HFPERCLKEN0, 0, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070050 hws[clk_HFPERCLKUSART1] = clk_hw_register_gate(NULL, "HFPERCLK.USART1",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020051 "HFXO", 0, base + CMU_HFPERCLKEN0, 1, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070052 hws[clk_HFPERCLKUSART2] = clk_hw_register_gate(NULL, "HFPERCLK.USART2",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020053 "HFXO", 0, base + CMU_HFPERCLKEN0, 2, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070054 hws[clk_HFPERCLKUART0] = clk_hw_register_gate(NULL, "HFPERCLK.UART0",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020055 "HFXO", 0, base + CMU_HFPERCLKEN0, 3, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070056 hws[clk_HFPERCLKUART1] = clk_hw_register_gate(NULL, "HFPERCLK.UART1",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020057 "HFXO", 0, base + CMU_HFPERCLKEN0, 4, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070058 hws[clk_HFPERCLKTIMER0] = clk_hw_register_gate(NULL, "HFPERCLK.TIMER0",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020059 "HFXO", 0, base + CMU_HFPERCLKEN0, 5, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070060 hws[clk_HFPERCLKTIMER1] = clk_hw_register_gate(NULL, "HFPERCLK.TIMER1",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020061 "HFXO", 0, base + CMU_HFPERCLKEN0, 6, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070062 hws[clk_HFPERCLKTIMER2] = clk_hw_register_gate(NULL, "HFPERCLK.TIMER2",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020063 "HFXO", 0, base + CMU_HFPERCLKEN0, 7, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070064 hws[clk_HFPERCLKTIMER3] = clk_hw_register_gate(NULL, "HFPERCLK.TIMER3",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020065 "HFXO", 0, base + CMU_HFPERCLKEN0, 8, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070066 hws[clk_HFPERCLKACMP0] = clk_hw_register_gate(NULL, "HFPERCLK.ACMP0",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020067 "HFXO", 0, base + CMU_HFPERCLKEN0, 9, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070068 hws[clk_HFPERCLKACMP1] = clk_hw_register_gate(NULL, "HFPERCLK.ACMP1",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020069 "HFXO", 0, base + CMU_HFPERCLKEN0, 10, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070070 hws[clk_HFPERCLKI2C0] = clk_hw_register_gate(NULL, "HFPERCLK.I2C0",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020071 "HFXO", 0, base + CMU_HFPERCLKEN0, 11, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070072 hws[clk_HFPERCLKI2C1] = clk_hw_register_gate(NULL, "HFPERCLK.I2C1",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020073 "HFXO", 0, base + CMU_HFPERCLKEN0, 12, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070074 hws[clk_HFPERCLKGPIO] = clk_hw_register_gate(NULL, "HFPERCLK.GPIO",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020075 "HFXO", 0, base + CMU_HFPERCLKEN0, 13, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070076 hws[clk_HFPERCLKVCMP] = clk_hw_register_gate(NULL, "HFPERCLK.VCMP",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020077 "HFXO", 0, base + CMU_HFPERCLKEN0, 14, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070078 hws[clk_HFPERCLKPRS] = clk_hw_register_gate(NULL, "HFPERCLK.PRS",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020079 "HFXO", 0, base + CMU_HFPERCLKEN0, 15, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070080 hws[clk_HFPERCLKADC0] = clk_hw_register_gate(NULL, "HFPERCLK.ADC0",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020081 "HFXO", 0, base + CMU_HFPERCLKEN0, 16, 0, NULL);
Stephen Boyd93376312016-06-01 16:15:14 -070082 hws[clk_HFPERCLKDAC0] = clk_hw_register_gate(NULL, "HFPERCLK.DAC0",
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020083 "HFXO", 0, base + CMU_HFPERCLKEN0, 17, 0, NULL);
84
Stephen Boydbdfdabf2016-11-16 11:02:00 -080085 of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
Uwe Kleine-König9ed9c072013-10-08 09:57:20 +020086}
87CLK_OF_DECLARE(efm32ggcmu, "efm32gg,cmu", efm32gg_cmu_init);