2
0

852-clk-bcm-Add-BCM63268-timer-clock-and-reset-driver.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. <[email protected]>
  7. X-Patchwork-Id: 13184392
  8. Return-Path: <[email protected]>
  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 <[email protected]>; Wed, 22 Mar 2023 17:16:11 +0000 (UTC)
  14. Received: ([email protected]) by vger.kernel.org via listexpand
  15. id S231512AbjCVRQJ (ORCPT <rfc822;[email protected]>);
  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;[email protected]>); 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?= <[email protected]>
  66. To: [email protected], [email protected], [email protected],
  67. [email protected], [email protected],
  68. [email protected], [email protected],
  69. [email protected], [email protected],
  70. [email protected], [email protected]
  71. Cc: =?utf-8?q?=C3=81lvaro_Fern=C3=A1ndez_Rojas?= <[email protected]>
  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: <[email protected]>
  75. X-Mailer: git-send-email 2.30.2
  76. In-Reply-To: <[email protected]>
  77. References: <[email protected]>
  78. MIME-Version: 1.0
  79. Precedence: bulk
  80. List-ID: <linux-clk.vger.kernel.org>
  81. X-Mailing-List: [email protected]
  82. Add driver for BCM63268 timer clock and reset controller.
  83. Signed-off-by: Álvaro Fernández Rojas <[email protected]>
  84. ---
  85. v4: add changes suggested by Stephen Boyd:
  86. - Usage of of_device_get_match_data() isn't needed.
  87. - Use devm_clk_hw_register_gate().
  88. - Drop clk_hw_unregister_gate().
  89. v3: add missing <linux/io.h> include to fix build warning
  90. v2: add changes suggested by Stephen Boyd
  91. drivers/clk/bcm/Kconfig | 9 ++
  92. drivers/clk/bcm/Makefile | 1 +
  93. drivers/clk/bcm/clk-bcm63268-timer.c | 215 +++++++++++++++++++++++++++
  94. 3 files changed, 225 insertions(+)
  95. create mode 100644 drivers/clk/bcm/clk-bcm63268-timer.c
  96. --- a/drivers/clk/bcm/Kconfig
  97. +++ b/drivers/clk/bcm/Kconfig
  98. @@ -37,6 +37,15 @@ config CLK_BCM_63XX_GATE
  99. Enable common clock framework support for Broadcom BCM63xx DSL SoCs
  100. based on the MIPS architecture
  101. +config CLK_BCM63268_TIMER
  102. + bool "Broadcom BCM63268 timer clock and reset support"
  103. + depends on BMIPS_GENERIC || COMPILE_TEST
  104. + default BMIPS_GENERIC
  105. + select RESET_CONTROLLER
  106. + help
  107. + Enable timer clock and reset support for Broadcom BCM63268 DSL SoCs
  108. + based on the MIPS architecture.
  109. +
  110. config CLK_BCM_KONA
  111. bool "Broadcom Kona CCU clock support"
  112. depends on ARCH_BCM_MOBILE || COMPILE_TEST
  113. --- a/drivers/clk/bcm/Makefile
  114. +++ b/drivers/clk/bcm/Makefile
  115. @@ -1,6 +1,7 @@
  116. # SPDX-License-Identifier: GPL-2.0
  117. obj-$(CONFIG_CLK_BCM_63XX) += clk-bcm63xx.o
  118. obj-$(CONFIG_CLK_BCM_63XX_GATE) += clk-bcm63xx-gate.o
  119. +obj-$(CONFIG_CLK_BCM63268_TIMER) += clk-bcm63268-timer.o
  120. obj-$(CONFIG_CLK_BCM_KONA) += clk-kona.o
  121. obj-$(CONFIG_CLK_BCM_KONA) += clk-kona-setup.o
  122. obj-$(CONFIG_CLK_BCM_KONA) += clk-bcm281xx.o
  123. --- /dev/null
  124. +++ b/drivers/clk/bcm/clk-bcm63268-timer.c
  125. @@ -0,0 +1,215 @@
  126. +// SPDX-License-Identifier: GPL-2.0
  127. +/*
  128. + * BCM63268 Timer Clock and Reset Controller Driver
  129. + *
  130. + * Copyright (C) 2023 Álvaro Fernández Rojas <[email protected]>
  131. + */
  132. +
  133. +#include <linux/clk-provider.h>
  134. +#include <linux/delay.h>
  135. +#include <linux/io.h>
  136. +#include <linux/of.h>
  137. +#include <linux/of_device.h>
  138. +#include <linux/platform_device.h>
  139. +#include <linux/reset-controller.h>
  140. +
  141. +#include <dt-bindings/clock/bcm63268-clock.h>
  142. +
  143. +#define BCM63268_TIMER_RESET_SLEEP_MIN_US 10000
  144. +#define BCM63268_TIMER_RESET_SLEEP_MAX_US 20000
  145. +
  146. +struct bcm63268_tclkrst_hw {
  147. + void __iomem *regs;
  148. + spinlock_t lock;
  149. +
  150. + struct reset_controller_dev rcdev;
  151. + struct clk_hw_onecell_data data;
  152. +};
  153. +
  154. +struct bcm63268_tclk_table_entry {
  155. + const char * const name;
  156. + u8 bit;
  157. +};
  158. +
  159. +static const struct bcm63268_tclk_table_entry bcm63268_timer_clocks[] = {
  160. + {
  161. + .name = "ephy1",
  162. + .bit = BCM63268_TCLK_EPHY1,
  163. + }, {
  164. + .name = "ephy2",
  165. + .bit = BCM63268_TCLK_EPHY2,
  166. + }, {
  167. + .name = "ephy3",
  168. + .bit = BCM63268_TCLK_EPHY3,
  169. + }, {
  170. + .name = "gphy1",
  171. + .bit = BCM63268_TCLK_GPHY1,
  172. + }, {
  173. + .name = "dsl",
  174. + .bit = BCM63268_TCLK_DSL,
  175. + }, {
  176. + .name = "wakeon_ephy",
  177. + .bit = BCM63268_TCLK_WAKEON_EPHY,
  178. + }, {
  179. + .name = "wakeon_dsl",
  180. + .bit = BCM63268_TCLK_WAKEON_DSL,
  181. + }, {
  182. + .name = "fap1_pll",
  183. + .bit = BCM63268_TCLK_FAP1,
  184. + }, {
  185. + .name = "fap2_pll",
  186. + .bit = BCM63268_TCLK_FAP2,
  187. + }, {
  188. + .name = "uto_50",
  189. + .bit = BCM63268_TCLK_UTO_50,
  190. + }, {
  191. + .name = "uto_extin",
  192. + .bit = BCM63268_TCLK_UTO_EXTIN,
  193. + }, {
  194. + .name = "usb_ref",
  195. + .bit = BCM63268_TCLK_USB_REF,
  196. + }, {
  197. + /* sentinel */
  198. + }
  199. +};
  200. +
  201. +static inline struct bcm63268_tclkrst_hw *
  202. +to_bcm63268_timer_reset(struct reset_controller_dev *rcdev)
  203. +{
  204. + return container_of(rcdev, struct bcm63268_tclkrst_hw, rcdev);
  205. +}
  206. +
  207. +static int bcm63268_timer_reset_update(struct reset_controller_dev *rcdev,
  208. + unsigned long id, bool assert)
  209. +{
  210. + struct bcm63268_tclkrst_hw *reset = to_bcm63268_timer_reset(rcdev);
  211. + unsigned long flags;
  212. + uint32_t val;
  213. +
  214. + spin_lock_irqsave(&reset->lock, flags);
  215. + val = __raw_readl(reset->regs);
  216. + if (assert)
  217. + val &= ~BIT(id);
  218. + else
  219. + val |= BIT(id);
  220. + __raw_writel(val, reset->regs);
  221. + spin_unlock_irqrestore(&reset->lock, flags);
  222. +
  223. + return 0;
  224. +}
  225. +
  226. +static int bcm63268_timer_reset_assert(struct reset_controller_dev *rcdev,
  227. + unsigned long id)
  228. +{
  229. + return bcm63268_timer_reset_update(rcdev, id, true);
  230. +}
  231. +
  232. +static int bcm63268_timer_reset_deassert(struct reset_controller_dev *rcdev,
  233. + unsigned long id)
  234. +{
  235. + return bcm63268_timer_reset_update(rcdev, id, false);
  236. +}
  237. +
  238. +static int bcm63268_timer_reset_reset(struct reset_controller_dev *rcdev,
  239. + unsigned long id)
  240. +{
  241. + bcm63268_timer_reset_update(rcdev, id, true);
  242. + usleep_range(BCM63268_TIMER_RESET_SLEEP_MIN_US,
  243. + BCM63268_TIMER_RESET_SLEEP_MAX_US);
  244. +
  245. + bcm63268_timer_reset_update(rcdev, id, false);
  246. + /*
  247. + * Ensure component is taken out reset state by sleeping also after
  248. + * deasserting the reset. Otherwise, the component may not be ready
  249. + * for operation.
  250. + */
  251. + usleep_range(BCM63268_TIMER_RESET_SLEEP_MIN_US,
  252. + BCM63268_TIMER_RESET_SLEEP_MAX_US);
  253. +
  254. + return 0;
  255. +}
  256. +
  257. +static int bcm63268_timer_reset_status(struct reset_controller_dev *rcdev,
  258. + unsigned long id)
  259. +{
  260. + struct bcm63268_tclkrst_hw *reset = to_bcm63268_timer_reset(rcdev);
  261. +
  262. + return !(__raw_readl(reset->regs) & BIT(id));
  263. +}
  264. +
  265. +static struct reset_control_ops bcm63268_timer_reset_ops = {
  266. + .assert = bcm63268_timer_reset_assert,
  267. + .deassert = bcm63268_timer_reset_deassert,
  268. + .reset = bcm63268_timer_reset_reset,
  269. + .status = bcm63268_timer_reset_status,
  270. +};
  271. +
  272. +static int bcm63268_tclk_probe(struct platform_device *pdev)
  273. +{
  274. + struct device *dev = &pdev->dev;
  275. + const struct bcm63268_tclk_table_entry *entry;
  276. + struct bcm63268_tclkrst_hw *hw;
  277. + struct clk_hw *clk;
  278. + u8 maxbit = 0;
  279. + int i, ret;
  280. +
  281. + for (entry = bcm63268_timer_clocks; entry->name; entry++)
  282. + maxbit = max(maxbit, entry->bit);
  283. + maxbit++;
  284. +
  285. + hw = devm_kzalloc(&pdev->dev, struct_size(hw, data.hws, maxbit),
  286. + GFP_KERNEL);
  287. + if (!hw)
  288. + return -ENOMEM;
  289. +
  290. + platform_set_drvdata(pdev, hw);
  291. +
  292. + spin_lock_init(&hw->lock);
  293. +
  294. + hw->data.num = maxbit;
  295. + for (i = 0; i < maxbit; i++)
  296. + hw->data.hws[i] = ERR_PTR(-ENODEV);
  297. +
  298. + hw->regs = devm_platform_ioremap_resource(pdev, 0);
  299. + if (IS_ERR(hw->regs))
  300. + return PTR_ERR(hw->regs);
  301. +
  302. + for (entry = bcm63268_timer_clocks; entry->name; entry++) {
  303. + clk = devm_clk_hw_register_gate(dev, entry->name, NULL, 0,
  304. + hw->regs, entry->bit,
  305. + CLK_GATE_BIG_ENDIAN,
  306. + &hw->lock);
  307. + if (IS_ERR(clk))
  308. + return PTR_ERR(clk);
  309. +
  310. + hw->data.hws[entry->bit] = clk;
  311. + }
  312. +
  313. + ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
  314. + &hw->data);
  315. + if (ret)
  316. + return ret;
  317. +
  318. + hw->rcdev.of_node = dev->of_node;
  319. + hw->rcdev.ops = &bcm63268_timer_reset_ops;
  320. +
  321. + ret = devm_reset_controller_register(dev, &hw->rcdev);
  322. + if (ret)
  323. + dev_err(dev, "Failed to register reset controller\n");
  324. +
  325. + return 0;
  326. +}
  327. +
  328. +static const struct of_device_id bcm63268_tclk_dt_ids[] = {
  329. + { .compatible = "brcm,bcm63268-timer-clocks" },
  330. + { /* sentinel */ }
  331. +};
  332. +
  333. +static struct platform_driver bcm63268_tclk = {
  334. + .probe = bcm63268_tclk_probe,
  335. + .driver = {
  336. + .name = "bcm63268-timer-clock",
  337. + .of_match_table = bcm63268_tclk_dt_ids,
  338. + },
  339. +};
  340. +builtin_platform_driver(bcm63268_tclk);