mtd: fix build with GCC 14
[openwrt/openwrt.git] / target / linux / generic / pending-6.1 / 852-clk-bcm-Add-BCM63268-timer-clock-and-reset-driver.patch
1 From patchwork Wed Mar 22 17:15:15 2023
2 Content-Type: text/plain; charset="utf-8"
3 MIME-Version: 1.0
4 Content-Transfer-Encoding: 8bit
5 X-Patchwork-Submitter: =?utf-8?q?=C3=81lvaro_Fern=C3=A1ndez_Rojas?=
6 <noltari@gmail.com>
7 X-Patchwork-Id: 13184392
8 Return-Path: <linux-clk-owner@vger.kernel.org>
9 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
10 aws-us-west-2-korg-lkml-1.web.codeaurora.org
11 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
12 by smtp.lore.kernel.org (Postfix) with ESMTP id 199D9C76196
13 for <linux-clk@archiver.kernel.org>; Wed, 22 Mar 2023 17:16:11 +0000 (UTC)
14 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
15 id S231512AbjCVRQJ (ORCPT <rfc822;linux-clk@archiver.kernel.org>);
16 Wed, 22 Mar 2023 13:16:09 -0400
17 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58942 "EHLO
18 lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
19 with ESMTP id S231442AbjCVRP5 (ORCPT
20 <rfc822;linux-clk@vger.kernel.org>); Wed, 22 Mar 2023 13:15:57 -0400
21 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com
22 [IPv6:2a00:1450:4864:20::32c])
23 by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DDB36487D;
24 Wed, 22 Mar 2023 10:15:27 -0700 (PDT)
25 Received: by mail-wm1-x32c.google.com with SMTP id
26 i5-20020a05600c354500b003edd24054e0so6717370wmq.4;
27 Wed, 22 Mar 2023 10:15:27 -0700 (PDT)
28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
29 d=gmail.com; s=20210112; t=1679505325;
30 h=content-transfer-encoding:mime-version:references:in-reply-to
31 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
32 :message-id:reply-to;
33 bh=rkv/eZYA1ncHp5FnV2ZWc3hgYnAx28S86QA9vmcXFCY=;
34 b=Y1mva2Bt3sUbKxLgEUS331CJbGxUc4z8kTQW8qiHWGhYlFKtm+d5z4sT40E5BeZAnU
35 zmTbCI7jbroe9NYBxGUmSli6LNVDPjND80ChbhWTqbqMQTmeQFWut9KmeBWK6Oze2lC/
36 XMSOorUzowjcU2xtHNrzoq2KH2pstW573lsB8WnzFVfhMaRkE9DfRr6WNyA7zC8DyxM5
37 ezxlCQtCmgPfCqlyksbIDKrgrRf3GiUR0yUd6xRU+MssyvH1FkYGDCerPctDto6lGHBz
38 8Y15jT3l6OnQMT6dkekgpPF5/XrSUY93u9g0B4U8+0dhNj+K7vmDen+jqdess+tpLnq/
39 gFrA==
40 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
41 d=1e100.net; s=20210112; t=1679505325;
42 h=content-transfer-encoding:mime-version:references:in-reply-to
43 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
44 :subject:date:message-id:reply-to;
45 bh=rkv/eZYA1ncHp5FnV2ZWc3hgYnAx28S86QA9vmcXFCY=;
46 b=Ym4+u8bbTQGNkewUBrLf+89vE0EFJBQp2f1crwUxZFboKTROF9ltZonY1CGepo7b0B
47 fkx3TbWQy5X65g3ScuieqtClCI8WanPeNBJ48+JipJYO3ODVNBxnVaTuW/0FOIcahfqe
48 sG5GvggHhzRz+Yeybsbnupmzxnw8Ez0BpMl3p7zcjHL7BGZDdOOX2Zbw3zfyYa5sg2nX
49 UXYJT36zy2h39gxUsy9QkhQ76CG3w6omniohZpYidpojpiDjbOy0nKFky4kUe+YyA1fF
50 4IBhjAm6mH+uh6wHSG1qj+NAXHs0xDDJps16PbJwAgL7Qt9K5WW+R/UAYPmHFgaRIHOw
51 /seA==
52 X-Gm-Message-State: AO0yUKXRtoYO8Nfus6Ca8lhM39P1Xn6TGkhatEfoISd1YNOkTJJN2hW+
53 xRphLgxlzNfCLcVPlpGK9dk=
54 X-Google-Smtp-Source:
55 AK7set9VnMEykugk8ZYnkXuqK41bX1dzlvKsAXHEjr8i2NZBld0buKhQLcGYEcwxnBgVTtC7eRGfXw==
56 X-Received: by 2002:a1c:7c0b:0:b0:3e2:1dac:b071 with SMTP id
57 x11-20020a1c7c0b000000b003e21dacb071mr178053wmc.13.1679505325582;
58 Wed, 22 Mar 2023 10:15:25 -0700 (PDT)
59 Received: from atlantis.lan (255.red-79-146-124.dynamicip.rima-tde.net.
60 [79.146.124.255])
61 by smtp.gmail.com with ESMTPSA id
62 v10-20020a05600c470a00b003ee11ac2288sm8414333wmo.21.2023.03.22.10.15.24
63 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
64 Wed, 22 Mar 2023 10:15:25 -0700 (PDT)
65 From: =?utf-8?q?=C3=81lvaro_Fern=C3=A1ndez_Rojas?= <noltari@gmail.com>
66 To: mturquette@baylibre.com, sboyd@kernel.org, robh+dt@kernel.org,
67 krzysztof.kozlowski+dt@linaro.org, p.zabel@pengutronix.de,
68 f.fainelli@gmail.com, jonas.gorski@gmail.com,
69 william.zhang@broadcom.com, linux-clk@vger.kernel.org,
70 devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
71 Cc: =?utf-8?q?=C3=81lvaro_Fern=C3=A1ndez_Rojas?= <noltari@gmail.com>
72 Subject: [PATCH v4 4/4] clk: bcm: Add BCM63268 timer clock and reset driver
73 Date: Wed, 22 Mar 2023 18:15:15 +0100
74 Message-Id: <20230322171515.120353-5-noltari@gmail.com>
75 X-Mailer: git-send-email 2.30.2
76 In-Reply-To: <20230322171515.120353-1-noltari@gmail.com>
77 References: <20230322171515.120353-1-noltari@gmail.com>
78 MIME-Version: 1.0
79 Precedence: bulk
80 List-ID: <linux-clk.vger.kernel.org>
81 X-Mailing-List: linux-clk@vger.kernel.org
82
83 Add driver for BCM63268 timer clock and reset controller.
84
85 Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
86 ---
87 v4: add changes suggested by Stephen Boyd:
88 - Usage of of_device_get_match_data() isn't needed.
89 - Use devm_clk_hw_register_gate().
90 - Drop clk_hw_unregister_gate().
91 v3: add missing <linux/io.h> include to fix build warning
92 v2: add changes suggested by Stephen Boyd
93
94 drivers/clk/bcm/Kconfig | 9 ++
95 drivers/clk/bcm/Makefile | 1 +
96 drivers/clk/bcm/clk-bcm63268-timer.c | 215 +++++++++++++++++++++++++++
97 3 files changed, 225 insertions(+)
98 create mode 100644 drivers/clk/bcm/clk-bcm63268-timer.c
99
100 --- a/drivers/clk/bcm/Kconfig
101 +++ b/drivers/clk/bcm/Kconfig
102 @@ -37,6 +37,15 @@ config CLK_BCM_63XX_GATE
103 Enable common clock framework support for Broadcom BCM63xx DSL SoCs
104 based on the MIPS architecture
105
106 +config CLK_BCM63268_TIMER
107 + bool "Broadcom BCM63268 timer clock and reset support"
108 + depends on BMIPS_GENERIC || COMPILE_TEST
109 + default BMIPS_GENERIC
110 + select RESET_CONTROLLER
111 + help
112 + Enable timer clock and reset support for Broadcom BCM63268 DSL SoCs
113 + based on the MIPS architecture.
114 +
115 config CLK_BCM_KONA
116 bool "Broadcom Kona CCU clock support"
117 depends on ARCH_BCM_MOBILE || COMPILE_TEST
118 --- a/drivers/clk/bcm/Makefile
119 +++ b/drivers/clk/bcm/Makefile
120 @@ -1,6 +1,7 @@
121 # SPDX-License-Identifier: GPL-2.0
122 obj-$(CONFIG_CLK_BCM_63XX) += clk-bcm63xx.o
123 obj-$(CONFIG_CLK_BCM_63XX_GATE) += clk-bcm63xx-gate.o
124 +obj-$(CONFIG_CLK_BCM63268_TIMER) += clk-bcm63268-timer.o
125 obj-$(CONFIG_CLK_BCM_KONA) += clk-kona.o
126 obj-$(CONFIG_CLK_BCM_KONA) += clk-kona-setup.o
127 obj-$(CONFIG_CLK_BCM_KONA) += clk-bcm281xx.o
128 --- /dev/null
129 +++ b/drivers/clk/bcm/clk-bcm63268-timer.c
130 @@ -0,0 +1,215 @@
131 +// SPDX-License-Identifier: GPL-2.0
132 +/*
133 + * BCM63268 Timer Clock and Reset Controller Driver
134 + *
135 + * Copyright (C) 2023 Álvaro Fernández Rojas <noltari@gmail.com>
136 + */
137 +
138 +#include <linux/clk-provider.h>
139 +#include <linux/delay.h>
140 +#include <linux/io.h>
141 +#include <linux/of.h>
142 +#include <linux/of_device.h>
143 +#include <linux/platform_device.h>
144 +#include <linux/reset-controller.h>
145 +
146 +#include <dt-bindings/clock/bcm63268-clock.h>
147 +
148 +#define BCM63268_TIMER_RESET_SLEEP_MIN_US 10000
149 +#define BCM63268_TIMER_RESET_SLEEP_MAX_US 20000
150 +
151 +struct bcm63268_tclkrst_hw {
152 + void __iomem *regs;
153 + spinlock_t lock;
154 +
155 + struct reset_controller_dev rcdev;
156 + struct clk_hw_onecell_data data;
157 +};
158 +
159 +struct bcm63268_tclk_table_entry {
160 + const char * const name;
161 + u8 bit;
162 +};
163 +
164 +static const struct bcm63268_tclk_table_entry bcm63268_timer_clocks[] = {
165 + {
166 + .name = "ephy1",
167 + .bit = BCM63268_TCLK_EPHY1,
168 + }, {
169 + .name = "ephy2",
170 + .bit = BCM63268_TCLK_EPHY2,
171 + }, {
172 + .name = "ephy3",
173 + .bit = BCM63268_TCLK_EPHY3,
174 + }, {
175 + .name = "gphy1",
176 + .bit = BCM63268_TCLK_GPHY1,
177 + }, {
178 + .name = "dsl",
179 + .bit = BCM63268_TCLK_DSL,
180 + }, {
181 + .name = "wakeon_ephy",
182 + .bit = BCM63268_TCLK_WAKEON_EPHY,
183 + }, {
184 + .name = "wakeon_dsl",
185 + .bit = BCM63268_TCLK_WAKEON_DSL,
186 + }, {
187 + .name = "fap1_pll",
188 + .bit = BCM63268_TCLK_FAP1,
189 + }, {
190 + .name = "fap2_pll",
191 + .bit = BCM63268_TCLK_FAP2,
192 + }, {
193 + .name = "uto_50",
194 + .bit = BCM63268_TCLK_UTO_50,
195 + }, {
196 + .name = "uto_extin",
197 + .bit = BCM63268_TCLK_UTO_EXTIN,
198 + }, {
199 + .name = "usb_ref",
200 + .bit = BCM63268_TCLK_USB_REF,
201 + }, {
202 + /* sentinel */
203 + }
204 +};
205 +
206 +static inline struct bcm63268_tclkrst_hw *
207 +to_bcm63268_timer_reset(struct reset_controller_dev *rcdev)
208 +{
209 + return container_of(rcdev, struct bcm63268_tclkrst_hw, rcdev);
210 +}
211 +
212 +static int bcm63268_timer_reset_update(struct reset_controller_dev *rcdev,
213 + unsigned long id, bool assert)
214 +{
215 + struct bcm63268_tclkrst_hw *reset = to_bcm63268_timer_reset(rcdev);
216 + unsigned long flags;
217 + uint32_t val;
218 +
219 + spin_lock_irqsave(&reset->lock, flags);
220 + val = __raw_readl(reset->regs);
221 + if (assert)
222 + val &= ~BIT(id);
223 + else
224 + val |= BIT(id);
225 + __raw_writel(val, reset->regs);
226 + spin_unlock_irqrestore(&reset->lock, flags);
227 +
228 + return 0;
229 +}
230 +
231 +static int bcm63268_timer_reset_assert(struct reset_controller_dev *rcdev,
232 + unsigned long id)
233 +{
234 + return bcm63268_timer_reset_update(rcdev, id, true);
235 +}
236 +
237 +static int bcm63268_timer_reset_deassert(struct reset_controller_dev *rcdev,
238 + unsigned long id)
239 +{
240 + return bcm63268_timer_reset_update(rcdev, id, false);
241 +}
242 +
243 +static int bcm63268_timer_reset_reset(struct reset_controller_dev *rcdev,
244 + unsigned long id)
245 +{
246 + bcm63268_timer_reset_update(rcdev, id, true);
247 + usleep_range(BCM63268_TIMER_RESET_SLEEP_MIN_US,
248 + BCM63268_TIMER_RESET_SLEEP_MAX_US);
249 +
250 + bcm63268_timer_reset_update(rcdev, id, false);
251 + /*
252 + * Ensure component is taken out reset state by sleeping also after
253 + * deasserting the reset. Otherwise, the component may not be ready
254 + * for operation.
255 + */
256 + usleep_range(BCM63268_TIMER_RESET_SLEEP_MIN_US,
257 + BCM63268_TIMER_RESET_SLEEP_MAX_US);
258 +
259 + return 0;
260 +}
261 +
262 +static int bcm63268_timer_reset_status(struct reset_controller_dev *rcdev,
263 + unsigned long id)
264 +{
265 + struct bcm63268_tclkrst_hw *reset = to_bcm63268_timer_reset(rcdev);
266 +
267 + return !(__raw_readl(reset->regs) & BIT(id));
268 +}
269 +
270 +static struct reset_control_ops bcm63268_timer_reset_ops = {
271 + .assert = bcm63268_timer_reset_assert,
272 + .deassert = bcm63268_timer_reset_deassert,
273 + .reset = bcm63268_timer_reset_reset,
274 + .status = bcm63268_timer_reset_status,
275 +};
276 +
277 +static int bcm63268_tclk_probe(struct platform_device *pdev)
278 +{
279 + struct device *dev = &pdev->dev;
280 + const struct bcm63268_tclk_table_entry *entry;
281 + struct bcm63268_tclkrst_hw *hw;
282 + struct clk_hw *clk;
283 + u8 maxbit = 0;
284 + int i, ret;
285 +
286 + for (entry = bcm63268_timer_clocks; entry->name; entry++)
287 + maxbit = max(maxbit, entry->bit);
288 + maxbit++;
289 +
290 + hw = devm_kzalloc(&pdev->dev, struct_size(hw, data.hws, maxbit),
291 + GFP_KERNEL);
292 + if (!hw)
293 + return -ENOMEM;
294 +
295 + platform_set_drvdata(pdev, hw);
296 +
297 + spin_lock_init(&hw->lock);
298 +
299 + hw->data.num = maxbit;
300 + for (i = 0; i < maxbit; i++)
301 + hw->data.hws[i] = ERR_PTR(-ENODEV);
302 +
303 + hw->regs = devm_platform_ioremap_resource(pdev, 0);
304 + if (IS_ERR(hw->regs))
305 + return PTR_ERR(hw->regs);
306 +
307 + for (entry = bcm63268_timer_clocks; entry->name; entry++) {
308 + clk = devm_clk_hw_register_gate(dev, entry->name, NULL, 0,
309 + hw->regs, entry->bit,
310 + CLK_GATE_BIG_ENDIAN,
311 + &hw->lock);
312 + if (IS_ERR(clk))
313 + return PTR_ERR(clk);
314 +
315 + hw->data.hws[entry->bit] = clk;
316 + }
317 +
318 + ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
319 + &hw->data);
320 + if (ret)
321 + return ret;
322 +
323 + hw->rcdev.of_node = dev->of_node;
324 + hw->rcdev.ops = &bcm63268_timer_reset_ops;
325 +
326 + ret = devm_reset_controller_register(dev, &hw->rcdev);
327 + if (ret)
328 + dev_err(dev, "Failed to register reset controller\n");
329 +
330 + return 0;
331 +}
332 +
333 +static const struct of_device_id bcm63268_tclk_dt_ids[] = {
334 + { .compatible = "brcm,bcm63268-timer-clocks" },
335 + { /* sentinel */ }
336 +};
337 +
338 +static struct platform_driver bcm63268_tclk = {
339 + .probe = bcm63268_tclk_probe,
340 + .driver = {
341 + .name = "bcm63268-timer-clock",
342 + .of_match_table = bcm63268_tclk_dt_ids,
343 + },
344 +};
345 +builtin_platform_driver(bcm63268_tclk);