Re: [PATCH v6 3/3] clk: tenstorrent: Add Atlantis clock controller driver

From: Anirudh Srinivasan

Date: Tue Feb 17 2026 - 18:30:17 EST


Hi Brian,

On Tue, Feb 17, 2026 at 5:22 PM Brian Masney <bmasney@xxxxxxxxxx> wrote:
> >
> > We have a group of gate clocks that have a single enable bit shared
> > among them (instead of individual enable bits for each clock). We need
> > to keep track of the number of clocks within a group that have
> > requested an enable, and only unset the bit if all the clocks are
> > disabled. share_count is used to keep track of this. It gets updated
> > by each clock. Hence it's a pointer (and the mutexes around access to
> > it).
>
> The code currently has:
>
> struct atlantis_clk_gate_shared_config {
> ...
> unsigned int *share_count;
> }
>
> That pointer is dereferenced like this in several places:
>
> need_enable = (*gate->config.share_count)++ == 0;
>
> I don't see why the pointer is needed. Can you drop the pointer
> and the dereference like this?
>
> struct atlantis_clk_gate_shared_config {
> ...
> unsigned int share_count;
> }
>
> need_enable = gate->config.share_count++ == 0;
>

In this case, wouldn't each atlantis_clk_gate_shared end up getting
its own copy of share_count? Which is not what we want. Or maybe I'm
not quite understanding what you're saying.

Every time we create a group of these shared gate clks, we create a
refcnt variable like this and pass the var to all clks that share it.

static unsigned int refcnt_qspi;
ATLANTIS_GATE_SHARED_DEFINE(CLK_QSPI_SCLK, qspi_sclk, nocc_clk_mux,
LSIO_BLK_CG_REG, BIT(0), &refcnt_qspi, 0);
ATLANTIS_GATE_SHARED_DEFINE(CLK_QSPI_HCLK, qspi_hclk, nocc_div2_clk,
LSIO_BLK_CG_REG, BIT(0), &refcnt_qspi, 0);