Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2013 Pengutronix |
| 4 | * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de> |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 5 | */ |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 6 | #include <linux/io.h> |
| 7 | #include <linux/clk-provider.h> |
| 8 | #include <linux/of.h> |
| 9 | #include <linux/of_address.h> |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 10 | #include <linux/slab.h> |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 11 | |
| 12 | #include <dt-bindings/clock/efm32-cmu.h> |
| 13 | |
| 14 | #define CMU_HFPERCLKEN0 0x44 |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 15 | #define CMU_MAX_CLKS 37 |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 16 | |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 17 | static struct clk_hw_onecell_data *clk_data; |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 18 | |
Uwe Kleine-König | 8ce8ebe | 2014-07-28 16:38:21 +0200 | [diff] [blame] | 19 | static void __init efm32gg_cmu_init(struct device_node *np) |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 20 | { |
| 21 | int i; |
| 22 | void __iomem *base; |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 23 | struct clk_hw **hws; |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 24 | |
Kees Cook | acafe7e | 2018-05-08 13:45:50 -0700 | [diff] [blame] | 25 | clk_data = kzalloc(struct_size(clk_data, hws, CMU_MAX_CLKS), |
| 26 | GFP_KERNEL); |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 27 | |
| 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önig | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 35 | |
| 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önig | 8ce8ebe | 2014-07-28 16:38:21 +0200 | [diff] [blame] | 39 | return; |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 40 | } |
| 41 | |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 42 | hws[clk_HFXO] = clk_hw_register_fixed_rate(NULL, "HFXO", NULL, 0, |
| 43 | 48000000); |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 44 | |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 45 | hws[clk_HFPERCLKUSART0] = clk_hw_register_gate(NULL, "HFPERCLK.USART0", |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 46 | "HFXO", 0, base + CMU_HFPERCLKEN0, 0, 0, NULL); |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 47 | hws[clk_HFPERCLKUSART1] = clk_hw_register_gate(NULL, "HFPERCLK.USART1", |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 48 | "HFXO", 0, base + CMU_HFPERCLKEN0, 1, 0, NULL); |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 49 | hws[clk_HFPERCLKUSART2] = clk_hw_register_gate(NULL, "HFPERCLK.USART2", |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 50 | "HFXO", 0, base + CMU_HFPERCLKEN0, 2, 0, NULL); |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 51 | hws[clk_HFPERCLKUART0] = clk_hw_register_gate(NULL, "HFPERCLK.UART0", |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 52 | "HFXO", 0, base + CMU_HFPERCLKEN0, 3, 0, NULL); |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 53 | hws[clk_HFPERCLKUART1] = clk_hw_register_gate(NULL, "HFPERCLK.UART1", |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 54 | "HFXO", 0, base + CMU_HFPERCLKEN0, 4, 0, NULL); |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 55 | hws[clk_HFPERCLKTIMER0] = clk_hw_register_gate(NULL, "HFPERCLK.TIMER0", |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 56 | "HFXO", 0, base + CMU_HFPERCLKEN0, 5, 0, NULL); |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 57 | hws[clk_HFPERCLKTIMER1] = clk_hw_register_gate(NULL, "HFPERCLK.TIMER1", |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 58 | "HFXO", 0, base + CMU_HFPERCLKEN0, 6, 0, NULL); |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 59 | hws[clk_HFPERCLKTIMER2] = clk_hw_register_gate(NULL, "HFPERCLK.TIMER2", |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 60 | "HFXO", 0, base + CMU_HFPERCLKEN0, 7, 0, NULL); |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 61 | hws[clk_HFPERCLKTIMER3] = clk_hw_register_gate(NULL, "HFPERCLK.TIMER3", |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 62 | "HFXO", 0, base + CMU_HFPERCLKEN0, 8, 0, NULL); |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 63 | hws[clk_HFPERCLKACMP0] = clk_hw_register_gate(NULL, "HFPERCLK.ACMP0", |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 64 | "HFXO", 0, base + CMU_HFPERCLKEN0, 9, 0, NULL); |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 65 | hws[clk_HFPERCLKACMP1] = clk_hw_register_gate(NULL, "HFPERCLK.ACMP1", |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 66 | "HFXO", 0, base + CMU_HFPERCLKEN0, 10, 0, NULL); |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 67 | hws[clk_HFPERCLKI2C0] = clk_hw_register_gate(NULL, "HFPERCLK.I2C0", |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 68 | "HFXO", 0, base + CMU_HFPERCLKEN0, 11, 0, NULL); |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 69 | hws[clk_HFPERCLKI2C1] = clk_hw_register_gate(NULL, "HFPERCLK.I2C1", |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 70 | "HFXO", 0, base + CMU_HFPERCLKEN0, 12, 0, NULL); |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 71 | hws[clk_HFPERCLKGPIO] = clk_hw_register_gate(NULL, "HFPERCLK.GPIO", |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 72 | "HFXO", 0, base + CMU_HFPERCLKEN0, 13, 0, NULL); |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 73 | hws[clk_HFPERCLKVCMP] = clk_hw_register_gate(NULL, "HFPERCLK.VCMP", |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 74 | "HFXO", 0, base + CMU_HFPERCLKEN0, 14, 0, NULL); |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 75 | hws[clk_HFPERCLKPRS] = clk_hw_register_gate(NULL, "HFPERCLK.PRS", |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 76 | "HFXO", 0, base + CMU_HFPERCLKEN0, 15, 0, NULL); |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 77 | hws[clk_HFPERCLKADC0] = clk_hw_register_gate(NULL, "HFPERCLK.ADC0", |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 78 | "HFXO", 0, base + CMU_HFPERCLKEN0, 16, 0, NULL); |
Stephen Boyd | 9337631 | 2016-06-01 16:15:14 -0700 | [diff] [blame] | 79 | hws[clk_HFPERCLKDAC0] = clk_hw_register_gate(NULL, "HFPERCLK.DAC0", |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 80 | "HFXO", 0, base + CMU_HFPERCLKEN0, 17, 0, NULL); |
| 81 | |
Stephen Boyd | bdfdabf | 2016-11-16 11:02:00 -0800 | [diff] [blame] | 82 | of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data); |
Uwe Kleine-König | 9ed9c07 | 2013-10-08 09:57:20 +0200 | [diff] [blame] | 83 | } |
| 84 | CLK_OF_DECLARE(efm32ggcmu, "efm32gg,cmu", efm32gg_cmu_init); |