From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796064455; b=K6xtQEFUXzfl+tCoys7jzpCIkCS4vmw3H4SB3UT/NGbMk/H8RND+Htahoo0oDaXBO68M VkckL9LXfjUfZYSz4kWHy5rgCT81SXEn5tRgynGS3e+8WdRgvFdZNRzlqKS3eYVH4Y544 t9R5srBLH5r0HbHGCah+z1CMPGyE+xcNfjHINUkd1v0Ew2b7mTG/c7Z4v5AHoSTTyScrE Nke0YPExXEmcBvTHDNJZ5gYkzBez6GksRUglStz+09zoNfpXVbVrc+FwMrYjxdMmtMcRP RLJxqsSE6LxkTweizpsa6f48cyDIr+7S39xKwwQGtEynoa9Xr41MPTGOfoENdYtWH6w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796064455; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=jDWUcfpG+E7PMpcQK1g90M2Nzfpj5CZ1xKGz0JgeB7I=; b=v9hyL/Q+dbAEBns9sypA6OU9o//9RHmhRvNgePFiCdhUJj7Ixd5iGv7J8hEvrWSjptCH mxi1sH8knEqFzBc5Fb48dNbWve310eqhRQtfv4GQ3DfSKcPvJgihxYVjsWEv6ZfpAfa3o G+aX8bOvdji+6SFKEOUSfsaYnd13K+0fQRQF9KhHL2gz0Gf3hwoRYyqRCNW+fYA0hek9x DtWqOOxdoWNaVGCwcQACSUbKU0hVgI+ch5xcA9e73QnhiJU4Ic9VC/rO9ZWs08QtgUUzl JVP16WpYTAUNmIBI8YwqWmCkiyoj5kp0vbwi49cvXwyjqE504O1PU/rTNUAi9dfUppA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=riscstar.com; spf=pass smtp.mailfrom=riscstar.com; dkim=pass header.d=riscstar.com header.i=@riscstar.com header.a=rsa-sha256 header.s=google header.b=toiqfCKY; arc=none smtp.remote-ip=209.85.216.47 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 242B3606A320 for ; Mon, 30 Nov 2026 18:47:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 242B3606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=riscstar.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=riscstar.com header.i=@riscstar.com header.a=rsa-sha256 header.s=google header.b=toiqfCKY Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-3b542b4d7bcso1191063a91.0 for ; Mon, 30 Nov 2026 10:47:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar.com; s=google; t=1796064453; x=1796669253; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=jDWUcfpG+E7PMpcQK1g90M2Nzfpj5CZ1xKGz0JgeB7I=; b=toiqfCKYh2VZSEZKFaLS3G9/UEJlXEpuEVaLaIpcZolTt9deXTtC6tVtz/Pp74TWHh 0Y/QwIDeO52VjdrUAWz7Ctqouli0z5h7VmKbPEsDyeQJZBbPeuVBe1Pxqp3NamFCYzYL YCYtVSOb2GOPyY0xdQu/kzI3nqnzkeOMAB5PBHeBJCcn94TZ8kYBUSOvTUEXG9eGSedi BS+fuf/bqmaOcpZdITQccG5EcO/zMR2TPq3d1IWxsiiwM7fpYnORTYc2efvi4KNDpHKn fc35fnqdljH13eHsRSTl0s8l0QZ6JbgeCmnwPocP4jX2KqIcLpGumubZQQG3ADMhjPLe W2IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796064453; x=1796669253; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=jDWUcfpG+E7PMpcQK1g90M2Nzfpj5CZ1xKGz0JgeB7I=; b=Ms9Lbb2euXLSb/iKtyu/++TDi/f/9N3kV83lfmA0qwdMF2E/N/u56Atwbq7nPZBD8M 5RAZyEo7MUL8JPWVkzchA069HlPKF6ojSLbc2bloKlDttl1HbAMltnRivXJMhEXnYT1P ES3GckWzhyUb9uUHbPYF48GLqhTFDkKO7JqHE01KztVa0lcOjEHRbJjZ2jI9e9bfhgE3 kIfUW+SJ5Rk2VFLC5pLsrOOnLv6sAJcKYA9nLwk1aYzC5OWeJtL2IBwjwE4i9Oy6qt/r kH3kNVIcrdAkpVLbfp1uE1m4jvuVNdbqDBI5JeT73FJOoRNXyioCzLtch5ockIXh/o/y SDtg== X-Forwarded-Encrypted: i=1; AL+hErELs1jT5JSQfCtjZ7OV6Au+S1WZMAsd+OmJ8vreDYo/ZPMEoXaMsLc19dAnaEyiEVnPBfCnm72oPcLAT7w=@vger.kernel.org X-Gm-Message-State: APuU4Z+wVSOupmnmHcaaD7IsoWp8fdEYReV/7uek+/4Iz4bVnzK27MPu rRHDfVIVn+PvcUhiS8Eg9PMHQh3RkBoPGMfFQ+mA6NqTNuqxbZcy8v+eX3gBJ7056Nc= X-Gm-Gg: AZFdTZcsfLLyEWKiC78f465S0AsHqvA6teTuTcGU2e+BE/mBSJRb+kC8+7RVxgssNIb zSOUTDlibY7OgZq0tWmo4lisSurR1j7WssCa2ZXQiQGFv120WATM+Z+YHj7k/meEdRfkycD6Zpt mB0oqaYomIw7Uarax0ywIXCpMTTuwz1tA2IaEPXayV8c3XT5y+yY8n1BrLpnEOxt2EqFfLCNDP8 ZdfDSqbEy+GzRrxxTQatgeWNw1u7O3aeh6pUrKxHptXJBcGvVFQDAZH6Z9VkUcZP9/X7SzRkvET QHw0O7tQUIJZAyr0hJSMacOwGfuqYzHVPrBk6HwBcYHkdc0ixP6D3dkOjmOKGuJ/VLY0PcZyWCF orK4JpSSCRb6+ekA4lWNQJBumW7DUWKU7pDkd6GQHRDsF66NFpSAMzTbRMNnoHoGcPh/WQdRXXp yenOo+uCXuv4BdgX343f6qhb4R/EyQN1lJ8V4rq/CdYyzHjGdsVnrH5NjM8nHrGyx3BHNsA35mP /6w63NKpFR3HPjA7fFTlFjX/EJevEIiOanAwkF42VDilab63IO/j9bn+q226rsK4iCeMoHMcQss vk9s4Kdq/CeOVq7Do1zD9EynMNOamuA1 X-Received: by 2002:a17:90a:d2c7:b0:3b4:1a5f:8664 with SMTP id 98e67ed59e1d1-3b41c97aaa0mr31171901a91.65.1796064453290; Mon, 30 Nov 2026 10:47:33 -0800 (PST) Received: from [172.22.22.28] ([76.156.233.211]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b41aab4729sm53305254a91.0.2026.11.30.10.47.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Nov 2026 10:47:32 -0800 (PST) Message-ID: <7f958d16-ec98-4c29-adcd-56eb96715e04@riscstar.com> Date: Mon, 30 Nov 2026 12:47:31 -0600 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 2/3] clk: toshiba: introduce a TC9564 clock/reset driver To: Jerome Brunet Cc: sboyd@kernel.org, bmasney+clk@redhat.com, jbrunet+clk@baylibre.com, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, p.zabel@pengutronix.de, andersson@kernel.org, konradybcio@kernel.org, abelvesa@kernel.org, daniel@riscstar.com, mohd.anwar@oss.qualcomm.com, lorenzo.bianconi@oss.qualcomm.com, fabrice.gasnier@foss.st.com, alexandre.torgue@foss.st.com, marex@nabladev.com, changhuang.liang@starfivetech.com, devicetree@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20261125202141.1288493-1-elder@riscstar.com> <20261125202141.1288493-3-elder@riscstar.com> <179580249573.2809466.11581167108626346174.b4-review@b4> Content-Language: en-US From: Alex Elder In-Reply-To: <179580249573.2809466.11581167108626346174.b4-review@b4> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 11/27/26 12:01 PM, Jerome Brunet wrote: >> Define a new platform driver that manages clocks and resets implemented >> by the Toshiba TC9564 SoC. There are 21 gate clocks that can be enabled >> and disabled, but currently only the clocks that are (or will soon be) >> used are defined to be controllable. There are also 13 resets that can >> be asserted or deasserted, but support for some of these is omitted as >> well. >> >> Two registers manage the state of the clocks, and two others manage >> the state of the resets. All four registers are found in a region >> mapped for MMIO. The region is provided via a BAR on one of the PCI >> functions embedded in the TC9564 SoC. >> >> The I2C and PCIE clocks and resets are treated as CRITICAL, meaning their >> state should never be changed (and a warning is issued if changing their >> state is attempted). >> >> Co-developed-by: Daniel Thompson >> Signed-off-by: Daniel Thompson >> Signed-off-by: Alex Elder >> --- >> v3: - Fixed problems/garbage in the patch header >> - The Kconfig option now depends on RESET_CONTROLLER, and can now >> be enabled if COMPILE_TEST is enabled >> - The generic gate clock controller code is now used rather than >> implementing a custom one >> - The PLL and internal fixed clocks IDs are no longer available >> outside "clk-tc9564.c" >> - The PLL is initialialized, followed by all fixed rate clocks, >> followed by the gate clocks, to ensure each clock's parent is >> initialized before the clock is >> - Updating the reset registers (read/modify/write) is now protected >> by a spinlock >> - "Unnecessary newlines" have been removed >> >> MAINTAINERS | 1 + >> drivers/clk/Kconfig | 9 + >> drivers/clk/Makefile | 1 + >> drivers/clk/clk-tc9564.c | 456 +++++++++++++++++++++++++++++++++++++++ >> 4 files changed, 467 insertions(+) >> create mode 100644 drivers/clk/clk-tc9564.c >> >> diff --git a/MAINTAINERS b/MAINTAINERS >> index 4d1f4cbfd731..b433e40cb023 100644 >> --- a/MAINTAINERS >> +++ b/MAINTAINERS >> @@ -28338,6 +28338,7 @@ M: Alex Elder >> M: Daniel Thompson >> S: Maintained >> F: Documentation/devicetree/bindings/clock/toshiba,tc9564-clock.yaml >> +F: drivers/clk/clk-tc9564.c >> F: include/dt-bindings/clock/toshiba,tc9564.h >> >> TOSHIBA TC9564 PCI DRIVER >> diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig >> index 37a8e35d4178..33d6f90743f0 100644 >> --- a/drivers/clk/Kconfig >> +++ b/drivers/clk/Kconfig >> @@ -185,6 +185,15 @@ config COMMON_CLK_CDCE706 >> help >> This driver supports TI CDCE706 programmable 3-PLL clock synthesizer. >> >> +config COMMON_CLK_TC9564 >> + tristate "Toshiba TC9564 clock and reset support" >> + depends on TC9564_PCI || COMPILE_TEST > > Does it really depend on it ? > Shouldn't you imply this driver from TC9564_PCI instead ? Yes I think that might be better. I've used "imply" once before but I still don't automatically think to use it. I'll work on that. It seems to me it was tricky to get the config options to all go the way I wanted to, but I think what you're suggesting makes sense. >> + depends on RESET_CONTROLLER >> + default TC9564_PCI > > ... if you do, this is not needed OK. > >> + help >> + This enables support for the clock and reset controllers embedded >> + in the Toshiba TC9564 SoC. >> + >> config COMMON_CLK_TPS68470 >> tristate "Clock Driver for TI TPS68470 PMIC" >> depends on I2C >> diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile >> index 52d138d4ffc8..a11a8326d79c 100644 >> --- a/drivers/clk/Makefile >> +++ b/drivers/clk/Makefile >> @@ -111,6 +111,7 @@ obj-$(CONFIG_COMMON_CLK_SI570) += clk-si570.o >> obj-$(CONFIG_COMMON_CLK_SP7021) += clk-sp7021.o >> obj-$(CONFIG_COMMON_CLK_STM32F) += clk-stm32f4.o >> obj-$(CONFIG_COMMON_CLK_STM32H7) += clk-stm32h7.o >> +obj-$(CONFIG_COMMON_CLK_TC9564) += clk-tc9564.o >> obj-$(CONFIG_COMMON_CLK_TPS68470) += clk-tps68470.o >> obj-$(CONFIG_CLK_TWL6040) += clk-twl6040.o >> obj-$(CONFIG_CLK_TWL) += clk-twl.o >> diff --git a/drivers/clk/clk-tc9564.c b/drivers/clk/clk-tc9564.c >> new file mode 100644 >> index 000000000000..306781e2f7b4 >> --- /dev/null >> +++ b/drivers/clk/clk-tc9564.c >> @@ -0,0 +1,456 @@ >> +// SPDX-License-Identifier: GPL-2.0-only >> + >> +/* >> + * Copyright (C) 2026 by RISCstar Solutions Corporation. All rights reserved. >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include > > Reset controllers belong in drivers/reset. > Please use the auxialiary or the MFD bus to handle this case. I have gone back and forth several times on this code, combining and separating the reset and clock drivers. They were separate platform drivers under a syscon, then in the latest iteration the syscon was dropped and they were combined, because the registers used were interleaved: #define CLOCK0_OFFSET 0x0 #define CLOCK1_OFFSET 0x8 #define RESET0_OFFSET 0x4 #define RESET1_OFFSET 0xc And it seemed better to use a single mapped region rather than having the clock driver use two 4-byte regions and the reset driver use two other 4-byte regions. Having the reset device be created by the clock device we can just have the clock define the small I/O mapped range and each driver can define its own offsets into that space. > Grep devm_auxiliary_device_create(), there are several example > of this already. I'm getting proficient at switching between platform and MFD and auxiliary device drivers... >> +#include >> + >> +#include >> + >> +/* >> + * Define the offsets for the registers that implement clock enable/disable >> + * bits for gated clocks, and those that implement reset assertion bits for >> + * resets. These offsets are relative to the address space defined in >> + * devicetree. >> + */ >> +#define CLOCK0_OFFSET 0x0 >> +#define CLOCK1_OFFSET 0x8 >> + >> +#define RESET0_OFFSET 0x4 >> +#define RESET1_OFFSET 0xc >> + >> +/* >> + * A PLL driven by a 25 MHz input oscillator provides a clock source to >> + * the chip. A set of fixed rate clocks is derived from the PLL, and a >> + * set of gate clocks are children of the fixed rate clocks. >> + * >> + * The clk_hw[] array within a clk_hw_onecell_data structure tracks all >> + * of them. The following definitions describe how these are laid out >> + * based on their indexes into the clk_hw[] array. Gate clocks are first, >> + * so their "raw" public IDs can be used as indexes into the array. >> + */ >> +#define GATE_BASE 0 >> +#define FIXED_BASE (GATE_BASE + GATE_COUNT) >> +#define CLOCK_PLL (FIXED_BASE + FIXED_COUNT) > > That seems very fragile. Are sure you've defined all the clocks in the chip ? > Because, if you did not and someone later add one, all the ids shift and it will > be quite a mess to stay align with the DT ids. The gate clocks are the only ones we make public. They're defined as part of the devicetree binding, and won't change. If more were added, the (private) fixed clock indexes would work fine even after renumbering. GATE_COUNT is defined based on the size of the array that initializes gate clocks, and is not defined as part of the binding. Also, based on Lorenzo's suggestion, I have reworked the code so there are three clock providers registered: one for the PLL; one for the fixed clocks; and one for the gate clocks. So the three types no longer have interrelated indexes into the clk_hw[] array(s), each uses a zero-based index. >> +/* The total number of clocks in the clk_hw[] array */ >> +#define CLOCK_COUNT (GATE_COUNT + FIXED_COUNT + 1) >> + >> +struct tc9564_clock { >> + void __iomem *ioaddr; /* Mapped clock/reset registers */ >> + spinlock_t lock; /* Protects reset register updates */ >> + struct clk_hw_onecell_data *clk_data; > > That would means have a 2 cells controller. Those are rather uncommon for clock > controllers. The representation here would be <&clk TYPE NUM>. > Unnecessary complex IMO I'm not sure I understand this comment, but I think what I said above *might* address it. The cells for the public gate clocks are defined by their ID, defined under include/device-tree/... >> + struct reset_controller_dev rcdev; >> +}; >> + >> +/* Indexes into the fixed_init[] array */ >> +enum fixed_clock { >> + CLOCK_62_5M, >> + CLOCK_125M, >> + CLOCK_250M, >> + CLOCK_312_5M, >> +}; > > not sure why you need this It is to allow the gate clocks to identify which fixed rate clock is its parent. The fixed rate clocks will be in a distinct, private clk_hw[] (onecell) array, different from the gate clocks. >> +struct fixed_init { >> + const char *name; >> + unsigned int div; /* Rate is PLL rate divided by this */ >> +}; >> + >> +struct gate_init { >> + const char *name; >> + enum fixed_clock parent; >> + u8 offset; /* Control register offset (0x0 or 0x8) */ >> + u8 bit; /* Bit in the control register (0-31) */ >> + bool critical; >> +}; >> + >> +struct reset_init { >> + u8 offset; /* Control register offset (0x4 or 0xc) */ >> + u8 bit; /* Bit in the control register (0-31) */ >> +}; >> + >> +/* Add FIXED_BASE to index values to get their index into the clk_hw[] array */ >> +static const struct fixed_init fixed_init[] = { >> + [CLOCK_312_5M] = { >> + .name = "312.5MHz", >> + .div = 4, > > What you can do is store the DT id associated to each clock, because this is fixed. > Then all you have to do is iterate over your 3 tables to fill the HW onecell. Are you just suggesting to store the ID as a field in the struct, rather than indexing the struct using the ID? The fixed clock IDs are private and can freely change. And as stated earlier, the gate clock IDs (their names and numeric values) never will. Any new clock IDs will need to be added to the end. But I might be missing something. > This way, it is still possible to add clock later on without wrecking the DTS ids > you can also put the onecell id of the parent. I'm sorry but I'm not sure I fully understand what you're saying here. The fixed clocks exist simply to provide the parent input for the gate clocks. (Note that the rates used are reasonable but are speculated--we did not get a proper clock tree from the vendor.) As I said, the fixed clocks will now be described by a separate clk_hw_onecell_data structure, using things like CLOCK_312_5M as indexes into the array. I might just be missing your point, and of so, maybe if you just try to describe it again I'll get it this time. >> + }, >> + [CLOCK_250M] = { >> + .name = "250MHz", >> + .div = 5, >> + }, >> + [CLOCK_125M] = { >> + .name = "125MHz", >> + .div = 10, >> + }, >> + [CLOCK_62_5M] = { >> + .name = "62.5MHz", >> + .div = 20, >> + }, >> +}; >> +#define FIXED_COUNT ARRAY_SIZE(fixed_init) >> + >> +/* Add GATE_BASE to index values to get their index into the clk_hw[] array */ >> +static const struct gate_init gate_init[] = { >> + [CLOCK_MAC0_TX] = { >> + .name = "MAC0-TX", >> + .parent = CLOCK_312_5M, >> + .offset = CLOCK0_OFFSET, >> + .bit = 7, >> + }, >> + [CLOCK_PCIE] = { >> + .name = "PCIe", >> + .parent = CLOCK_250M, >> + .offset = CLOCK0_OFFSET, >> + .bit = 9, >> + .critical = true, >> + }, >> + [CLOCK_I2C] = { >> + .name = "i2c", >> + .parent = CLOCK_62_5M, >> + .offset = CLOCK0_OFFSET, >> + .bit = 12, >> + .critical = true, >> + }, >> + [CLOCK_MAC0_RX] = { >> + .name = "MAC0-RX", >> + .parent = CLOCK_312_5M, >> + .offset = CLOCK0_OFFSET, >> + .bit = 14, >> + }, >> + [CLOCK_MSIGEN] = { >> + .name = "msigen", >> + .parent = CLOCK_125M, >> + .offset = CLOCK0_OFFSET, >> + .bit = 18, >> + }, >> + [CLOCK_MAC0_125M] = { >> + .name = "MAC0-125MHz", >> + .parent = CLOCK_125M, >> + .offset = CLOCK0_OFFSET, >> + .bit = 29, >> + }, >> + [CLOCK_MAC0_ALL] = { >> + .name = "MAC0-ALL", >> + .parent = CLOCK_250M, >> + .offset = CLOCK0_OFFSET, >> + .bit = 31, >> + }, >> + [CLOCK_MAC1_TX] = { >> + .name = "MAC1-TX", >> + .parent = CLOCK_312_5M, >> + .offset = CLOCK1_OFFSET, >> + .bit = 7, >> + }, >> + [CLOCK_MAC1_RX] = { >> + .name = "MAC1-RX", >> + .parent = CLOCK_312_5M, >> + .offset = CLOCK1_OFFSET, >> + .bit = 14, >> + }, >> + [CLOCK_MAC1_125M] = { >> + .name = "MAC1-125MHz", >> + .parent = CLOCK_125M, >> + .offset = CLOCK1_OFFSET, >> + .bit = 29, >> + }, >> + [CLOCK_MAC1_ALL] = { >> + .name = "MAC1-ALL", >> + .parent = CLOCK_250M, >> + .offset = CLOCK1_OFFSET, >> + .bit = 31, >> + }, >> +}; >> +#define GATE_COUNT ARRAY_SIZE(gate_init) >> + >> +static const struct reset_init reset_init[] = { >> + [RESET_MAC0_MAC] = { >> + .offset = RESET0_OFFSET, >> + .bit = 7, >> + }, >> + [RESET_PCIE] = { >> + .offset = RESET0_OFFSET, >> + .bit = 9, >> + }, >> + [RESET_I2C] = { >> + .offset = RESET0_OFFSET, >> + .bit = 12, >> + }, >> + [RESET_MSIGEN] = { >> + .offset = RESET0_OFFSET, >> + .bit = 18, >> + }, >> + [RESET_MAC0_PMA] = { >> + .offset = RESET0_OFFSET, >> + .bit = 30, >> + }, >> + [RESET_MAC0_XPCS] = { >> + .offset = RESET0_OFFSET, >> + .bit = 31, >> + }, >> + [RESET_MAC1_MAC] = { >> + .offset = RESET1_OFFSET, >> + .bit = 7, >> + }, >> + [RESET_MAC1_PMA] = { >> + .offset = RESET1_OFFSET, >> + .bit = 30, >> + }, >> + [RESET_MAC1_XPCS] = { >> + .offset = RESET1_OFFSET, >> + .bit = 31, >> + }, >> +}; >> +#define RESET_COUNT ARRAY_SIZE(reset_init) >> + >> +/* Caller must free the returned pointer if non-null */ >> +static const char *clock_name(struct device *dev, const char *name) >> +{ >> + return kasprintf(GFP_KERNEL, "%s-%s", dev_name(dev), name); >> +} > > if you mean devm_kasprintf, it is possible but it means memory get wasted > for the lifetime of the device. CCF already copies this on init, so it > is useless after it. I do not mean that, and explained to Lorenzo I don't want to use devm_*() for the exact reason you mention (wasted memory). What I intend is for the caller to free the returned memory pointer. > That being said, it would be nice if the function name made it clear it > allocate something. tc9564_clk_name_alloc() maybe ? I'll do that. As I also mentioned elsewhere, I'll also have each caller use __free(kfree) where the pointer taking the return value is declared, so the memory gets freed automatically. >> + >> +/* Initialize the PLL (parent is the input oscillator); called from probe */ >> +static int pll_init(struct device *dev, struct tc9564_clock *clock) >> +{ >> + struct clk_hw *hw; >> + const char *name; >> + >> + /* Initialize the PLL clock first (input oscillator is parent) */ >> + name = clock_name(dev, "pll"); >> + if (!name) >> + return -ENOMEM; >> + >> + hw = devm_clk_hw_register_fixed_factor_index(dev, name, 0, 0, 50, 1); >> + kfree(name); >> + if (IS_ERR(hw)) >> + return dev_err_probe(dev, PTR_ERR(hw), >> + "failed to register pll\n"); >> + >> + clock->clk_data->hws[CLOCK_PLL] = hw; >> + >> + return 0; >> +} >> + >> +/* Initialize the fixed rate clocks (PLL is parent); called from probe */ >> +static int fixed_clock_init(struct device *dev, struct tc9564_clock *clock) >> +{ >> + struct clk_hw_onecell_data *clk_data = clock->clk_data; >> + struct clk_hw *pll_hw = clk_data->hws[CLOCK_PLL]; >> + const char *name; >> + >> + for (u32 i = 0; i < FIXED_COUNT; i++) { >> + const struct fixed_init *init = &fixed_init[i]; >> + struct clk_hw *hw; >> + >> + name = clock_name(dev, init->name); >> + if (!name) >> + return -ENOMEM; >> + >> + hw = devm_clk_hw_register_fixed_factor_parent_hw(dev, name, >> + pll_hw, 0, >> + 1, init->div); >> + kfree(name); >> + if (IS_ERR(hw)) >> + return dev_err_probe(dev, PTR_ERR(hw), >> + "failed to register %s\n", >> + init->name); >> + >> + clk_data->hws[FIXED_BASE + i] = hw; >> + } >> + >> + return 0; >> +} >> + >> +/* Initialize the gate clocks; called from probe */ >> +static int gate_clock_init(struct device *dev, struct tc9564_clock *clock) >> +{ >> + struct clk_hw_onecell_data *clk_data = clock->clk_data; >> + struct clk_hw *parent_hw; >> + const char *name; >> + >> + for (u32 i = 0; i < GATE_COUNT; i++) { >> + const struct gate_init *init = &gate_init[i]; >> + unsigned long flags; >> + struct clk_hw *hw; >> + void __iomem *reg; >> + u32 parent_index; >> + >> + name = clock_name(dev, init->name); >> + if (!name) >> + return -ENOMEM; >> + >> + /* Each gate clock's parent is a fixed rate clock */ >> + parent_index = FIXED_BASE + init->parent; >> + parent_hw = clk_data->hws[parent_index]; >> + flags = init->critical ? CLK_IS_CRITICAL : 0; >> + reg = clock->ioaddr + init->offset; >> + >> + hw = devm_clk_hw_register_gate_parent_hw(dev, name, parent_hw, >> + flags, reg, init->bit, >> + 0, NULL); >> + kfree(name); >> + if (IS_ERR(hw)) >> + return dev_err_probe(dev, PTR_ERR(hw), >> + "failed to register %s\n", >> + init->name); >> + >> + clk_data->hws[GATE_BASE + i] = hw; >> + } >> + >> + return 0; >> +} >> + >> +static int reset_update(struct reset_controller_dev *rcdev, >> + unsigned long id, bool assert) >> +{ >> + const struct reset_init *reset; >> + struct tc9564_clock *clock; >> + unsigned long flags; >> + void __iomem *reg; >> + u32 mask; >> + u32 val; >> + >> + /* Warn on any attempt to change state of a critical reset */ >> + if (WARN_ON(id == RESET_I2C) || WARN_ON(id == RESET_PCIE)) >> + return 0; >> + >> + clock = dev_get_drvdata(rcdev->dev); >> + reset = &reset_init[id]; >> + reg = clock->ioaddr + reset->offset; >> + mask = BIT(reset->bit); >> + >> + spin_lock_irqsave(&clock->lock, flags); >> + >> + val = readl(reg); >> + if (assert) >> + val |= mask; >> + else >> + val &= ~mask; >> + writel(val, reg); >> + >> + spin_unlock_irqrestore(&clock->lock, flags); > > look like you are re-implementing what regmap mmio provides here. We are not using regmap any more. In addition, this will use the guard(spinlock_irqsave)(&clock->lock) here, as suggested by Philipp. > >> + >> + return 0; >> +} >> + >> +static int reset_assert(struct reset_controller_dev *rcdev, unsigned long id) >> +{ >> + return reset_update(rcdev, id, true); >> +} >> + >> +static int reset_deassert(struct reset_controller_dev *rcdev, unsigned long id) >> +{ >> + return reset_update(rcdev, id, false); >> +} >> + >> +static int reset_status(struct reset_controller_dev *rcdev, unsigned long id) >> +{ >> + struct tc9564_clock *clock = dev_get_drvdata(rcdev->dev); >> + const struct reset_init *reset = &reset_init[id]; >> + void __iomem *reg; >> + >> + reg = clock->ioaddr + reset->offset; >> + >> + return readl(reg) & BIT(reset->bit) ? 1 : 0; >> +} >> + >> +static const struct reset_control_ops reset_control_ops = { >> + .assert = reset_assert, >> + .deassert = reset_deassert, >> + .status = reset_status, >> +}; >> + >> +static int tc9564_clk_probe(struct platform_device *pdev) >> +{ >> + struct clk_hw_onecell_data *clk_data; >> + struct reset_controller_dev *rcdev; >> + struct tc9564_clock *clock; >> + struct device *dev = &pdev->dev; >> + struct device_node *np; >> + int ret; >> + >> + np = dev_of_node(dev); >> + if (!np) >> + return dev_err_probe(dev, -EINVAL, "no devicetree node\n"); >> + >> + clock = devm_kzalloc_obj(dev, *clock); >> + if (!clock) >> + return -ENOMEM; >> + >> + clock->ioaddr = devm_platform_ioremap_resource(pdev, 0); >> + if (IS_ERR(clock->ioaddr)) >> + return dev_err_probe(dev, PTR_ERR(clock->ioaddr), >> + "failed to map registers\n"); >> + >> + clk_data = devm_kzalloc_flex(dev, *clock->clk_data, hws, >> + CLOCK_COUNT); >> + if (!clk_data) >> + return -ENOMEM; >> + clk_data->num = CLOCK_COUNT; >> + >> + clock->clk_data = clk_data; >> + >> + /* We need the driver data pointer to initialize clocks and resets */ >> + dev_set_drvdata(dev, clock); >> + >> + /* Set up the clocks and register the provider */ >> + ret = pll_init(dev, clock); >> + if (ret) >> + return ret; >> + >> + ret = fixed_clock_init(dev, clock); >> + if (ret) >> + return ret; >> + >> + ret = gate_clock_init(dev, clock); >> + if (ret) >> + return ret; >> + >> + ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, clk_data); >> + if (ret) >> + return dev_err_probe(dev, ret, >> + "failed to add clock provider\n"); >> + >> + /* Set up and register the reset controller */ >> + rcdev = &clock->rcdev; >> + rcdev->ops = &reset_control_ops; >> + rcdev->owner = THIS_MODULE; >> + rcdev->dev = dev; >> + rcdev->of_node = np; >> + rcdev->nr_resets = RESET_COUNT; >> + >> + spin_lock_init(&clock->lock); >> + >> + ret = devm_reset_controller_register(dev, rcdev); >> + if (ret) >> + return dev_err_probe(dev, ret, >> + "failed to register reset controller\n"); >> + >> + return 0; >> +} >> + >> +static const struct of_device_id tc9564_clock_match[] = { >> + { .compatible = "toshiba,tc9564-clock", }, >> + { } >> +}; >> +MODULE_DEVICE_TABLE(of, tc9564_clock_match); >> + >> +static struct platform_driver tc9564_clk_driver = { >> + .probe = tc9564_clk_probe, >> + .driver = { >> + .name = KBUILD_MODNAME, >> + .of_match_table = tc9564_clock_match, >> + .probe_type = PROBE_PREFER_ASYNCHRONOUS, > > Why do you need to set this ? if you have a reason, > you should probably add a comment about it It's not strictly necessary. I think I added it based on a suggestion from someone long ago. Since you ask, I'll just drop it. It can be added later if someone thinks it's important. Thank you very much for your review. -Alex