Manivannan Sadhasivam | 91a8513 | 2018-06-14 23:38:35 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Amit Singh Tomar | 8821be4 | 2020-04-19 19:28:30 +0530 | [diff] [blame] | 3 | * Common clock driver for Actions Semi SoCs. |
Manivannan Sadhasivam | 91a8513 | 2018-06-14 23:38:35 +0530 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2015 Actions Semi Co., Ltd. |
| 6 | * Copyright (C) 2018 Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <dm.h> |
Amit Singh Tomar | 8821be4 | 2020-04-19 19:28:30 +0530 | [diff] [blame] | 11 | #include "clk_owl.h" |
Manivannan Sadhasivam | 91a8513 | 2018-06-14 23:38:35 +0530 | [diff] [blame] | 12 | #include <asm/io.h> |
Amit Singh Tomar | 8821be4 | 2020-04-19 19:28:30 +0530 | [diff] [blame] | 13 | #if defined(CONFIG_MACH_S900) |
| 14 | #include <asm/arch-owl/regs_s900.h> |
Amit Singh Tomar | 7c8e84c | 2020-04-19 19:28:28 +0530 | [diff] [blame] | 15 | #include <dt-bindings/clock/actions,s900-cmu.h> |
Amit Singh Tomar | 8821be4 | 2020-04-19 19:28:30 +0530 | [diff] [blame] | 16 | #elif defined(CONFIG_MACH_S700) |
| 17 | #include <asm/arch-owl/regs_s700.h> |
| 18 | #include <dt-bindings/clock/actions,s700-cmu.h> |
| 19 | #endif |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame^] | 20 | #include <linux/delay.h> |
Manivannan Sadhasivam | 91a8513 | 2018-06-14 23:38:35 +0530 | [diff] [blame] | 21 | |
| 22 | void owl_clk_init(struct owl_clk_priv *priv) |
| 23 | { |
| 24 | u32 bus_clk = 0, core_pll, dev_pll; |
| 25 | |
Amit Singh Tomar | 8821be4 | 2020-04-19 19:28:30 +0530 | [diff] [blame] | 26 | #if defined(CONFIG_MACH_S900) |
Manivannan Sadhasivam | 91a8513 | 2018-06-14 23:38:35 +0530 | [diff] [blame] | 27 | /* Enable ASSIST_PLL */ |
| 28 | setbits_le32(priv->base + CMU_ASSISTPLL, BIT(0)); |
Manivannan Sadhasivam | 91a8513 | 2018-06-14 23:38:35 +0530 | [diff] [blame] | 29 | udelay(PLL_STABILITY_WAIT_US); |
Amit Singh Tomar | 8821be4 | 2020-04-19 19:28:30 +0530 | [diff] [blame] | 30 | #endif |
Manivannan Sadhasivam | 91a8513 | 2018-06-14 23:38:35 +0530 | [diff] [blame] | 31 | |
| 32 | /* Source HOSC to DEV_CLK */ |
| 33 | clrbits_le32(priv->base + CMU_DEVPLL, CMU_DEVPLL_CLK); |
| 34 | |
| 35 | /* Configure BUS_CLK */ |
| 36 | bus_clk |= (CMU_PDBGDIV_DIV | CMU_PERDIV_DIV | CMU_NOCDIV_DIV | |
| 37 | CMU_DMMCLK_SRC | CMU_APBCLK_DIV | CMU_AHBCLK_DIV | |
| 38 | CMU_NOCCLK_SRC | CMU_CORECLK_HOSC); |
| 39 | writel(bus_clk, priv->base + CMU_BUSCLK); |
| 40 | |
| 41 | udelay(PLL_STABILITY_WAIT_US); |
| 42 | |
| 43 | /* Configure CORE_PLL */ |
| 44 | core_pll = readl(priv->base + CMU_COREPLL); |
| 45 | core_pll |= (CMU_COREPLL_EN | CMU_COREPLL_HOSC_EN | CMU_COREPLL_OUT); |
| 46 | writel(core_pll, priv->base + CMU_COREPLL); |
| 47 | |
| 48 | udelay(PLL_STABILITY_WAIT_US); |
| 49 | |
| 50 | /* Configure DEV_PLL */ |
| 51 | dev_pll = readl(priv->base + CMU_DEVPLL); |
| 52 | dev_pll |= (CMU_DEVPLL_EN | CMU_DEVPLL_OUT); |
| 53 | writel(dev_pll, priv->base + CMU_DEVPLL); |
| 54 | |
| 55 | udelay(PLL_STABILITY_WAIT_US); |
| 56 | |
| 57 | /* Source CORE_PLL for CORE_CLK */ |
| 58 | clrsetbits_le32(priv->base + CMU_BUSCLK, CMU_CORECLK_MASK, |
| 59 | CMU_CORECLK_CPLL); |
| 60 | |
| 61 | /* Source DEV_PLL for DEV_CLK */ |
| 62 | setbits_le32(priv->base + CMU_DEVPLL, CMU_DEVPLL_CLK); |
| 63 | |
| 64 | udelay(PLL_STABILITY_WAIT_US); |
| 65 | } |
| 66 | |
Manivannan Sadhasivam | 91a8513 | 2018-06-14 23:38:35 +0530 | [diff] [blame] | 67 | int owl_clk_enable(struct clk *clk) |
| 68 | { |
| 69 | struct owl_clk_priv *priv = dev_get_priv(clk->dev); |
Amit Singh Tomar | 8821be4 | 2020-04-19 19:28:30 +0530 | [diff] [blame] | 70 | enum owl_soc model = dev_get_driver_data(clk->dev); |
Manivannan Sadhasivam | 91a8513 | 2018-06-14 23:38:35 +0530 | [diff] [blame] | 71 | |
| 72 | switch (clk->id) { |
Amit Singh Tomar | 7c8e84c | 2020-04-19 19:28:28 +0530 | [diff] [blame] | 73 | case CLK_UART5: |
Amit Singh Tomar | 8821be4 | 2020-04-19 19:28:30 +0530 | [diff] [blame] | 74 | if (model != S900) |
| 75 | return -EINVAL; |
| 76 | /* Source HOSC for UART5 interface */ |
| 77 | clrbits_le32(priv->base + CMU_UART5CLK, CMU_UARTCLK_SRC_DEVPLL); |
| 78 | /* Enable UART5 interface clock */ |
| 79 | setbits_le32(priv->base + CMU_DEVCLKEN1, CMU_DEVCLKEN1_UART5); |
| 80 | break; |
| 81 | case CLK_UART3: |
| 82 | if (model != S700) |
| 83 | return -EINVAL; |
| 84 | /* Source HOSC for UART3 interface */ |
| 85 | clrbits_le32(priv->base + CMU_UART3CLK, CMU_UARTCLK_SRC_DEVPLL); |
| 86 | /* Enable UART3 interface clock */ |
| 87 | setbits_le32(priv->base + CMU_DEVCLKEN1, CMU_DEVCLKEN1_UART3); |
Manivannan Sadhasivam | 91a8513 | 2018-06-14 23:38:35 +0530 | [diff] [blame] | 88 | break; |
| 89 | default: |
Amit Singh Tomar | 8821be4 | 2020-04-19 19:28:30 +0530 | [diff] [blame] | 90 | return -EINVAL; |
Manivannan Sadhasivam | 91a8513 | 2018-06-14 23:38:35 +0530 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | int owl_clk_disable(struct clk *clk) |
| 97 | { |
| 98 | struct owl_clk_priv *priv = dev_get_priv(clk->dev); |
Amit Singh Tomar | 8821be4 | 2020-04-19 19:28:30 +0530 | [diff] [blame] | 99 | enum owl_soc model = dev_get_driver_data(clk->dev); |
Manivannan Sadhasivam | 91a8513 | 2018-06-14 23:38:35 +0530 | [diff] [blame] | 100 | |
| 101 | switch (clk->id) { |
Amit Singh Tomar | 7c8e84c | 2020-04-19 19:28:28 +0530 | [diff] [blame] | 102 | case CLK_UART5: |
Amit Singh Tomar | 8821be4 | 2020-04-19 19:28:30 +0530 | [diff] [blame] | 103 | if (model != S900) |
| 104 | return -EINVAL; |
| 105 | /* Disable UART5 interface clock */ |
| 106 | clrbits_le32(priv->base + CMU_DEVCLKEN1, CMU_DEVCLKEN1_UART5); |
| 107 | break; |
| 108 | case CLK_UART3: |
| 109 | if (model != S700) |
| 110 | return -EINVAL; |
| 111 | /* Disable UART3 interface clock */ |
| 112 | clrbits_le32(priv->base + CMU_DEVCLKEN1, CMU_DEVCLKEN1_UART3); |
Manivannan Sadhasivam | 91a8513 | 2018-06-14 23:38:35 +0530 | [diff] [blame] | 113 | break; |
| 114 | default: |
Amit Singh Tomar | 8821be4 | 2020-04-19 19:28:30 +0530 | [diff] [blame] | 115 | return -EINVAL; |
Manivannan Sadhasivam | 91a8513 | 2018-06-14 23:38:35 +0530 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | static int owl_clk_probe(struct udevice *dev) |
| 122 | { |
| 123 | struct owl_clk_priv *priv = dev_get_priv(dev); |
| 124 | |
| 125 | priv->base = dev_read_addr(dev); |
| 126 | if (priv->base == FDT_ADDR_T_NONE) |
| 127 | return -EINVAL; |
| 128 | |
| 129 | /* setup necessary clocks */ |
| 130 | owl_clk_init(priv); |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
Amit Singh Tomar | 8821be4 | 2020-04-19 19:28:30 +0530 | [diff] [blame] | 135 | static const struct clk_ops owl_clk_ops = { |
Manivannan Sadhasivam | 91a8513 | 2018-06-14 23:38:35 +0530 | [diff] [blame] | 136 | .enable = owl_clk_enable, |
| 137 | .disable = owl_clk_disable, |
| 138 | }; |
| 139 | |
| 140 | static const struct udevice_id owl_clk_ids[] = { |
Amit Singh Tomar | 8821be4 | 2020-04-19 19:28:30 +0530 | [diff] [blame] | 141 | #if defined(CONFIG_MACH_S900) |
| 142 | { .compatible = "actions,s900-cmu", .data = S900 }, |
| 143 | #elif defined(CONFIG_MACH_S700) |
| 144 | { .compatible = "actions,s700-cmu", .data = S700 }, |
| 145 | #endif |
Manivannan Sadhasivam | 91a8513 | 2018-06-14 23:38:35 +0530 | [diff] [blame] | 146 | { } |
| 147 | }; |
| 148 | |
| 149 | U_BOOT_DRIVER(clk_owl) = { |
Amit Singh Tomar | 8821be4 | 2020-04-19 19:28:30 +0530 | [diff] [blame] | 150 | .name = "clk_owl", |
Manivannan Sadhasivam | 91a8513 | 2018-06-14 23:38:35 +0530 | [diff] [blame] | 151 | .id = UCLASS_CLK, |
| 152 | .of_match = owl_clk_ids, |
| 153 | .ops = &owl_clk_ops, |
| 154 | .priv_auto_alloc_size = sizeof(struct owl_clk_priv), |
| 155 | .probe = owl_clk_probe, |
Manivannan Sadhasivam | 91a8513 | 2018-06-14 23:38:35 +0530 | [diff] [blame] | 156 | }; |