linux-stable/drivers/clk
Chen-Yu Tsai 6f691a5862 clk: mediatek: Switch to clk_hw provider APIs
As part of the effort to improve the MediaTek clk drivers, the next step
is to switch from the old 'struct clk' clk prodivder APIs to the new
'struct clk_hw' ones.

In a previous patch, 'struct clk_onecell_data' was replaced with
'struct clk_hw_onecell_data', with (struct clk_hw *)->clk and
__clk_get_hw() bridging the new data structures and old code.

Now switch from the old 'clk_(un)?register*()' APIs to the new
'clk_hw_(un)?register*()' ones. This is done with the coccinelle script
below.

Unfortunately this also leaves clk-mt8173.c with a compile error that
would need a coccinelle script longer than the actual diff to fix. This
last part is fixed up by hand.

    // Fix prototypes
    @@
    identifier F =~ "^mtk_clk_register_";
    @@
    - struct clk *
    + struct clk_hw *
      F(...);

    // Fix calls to mtk_clk_register_<singular>
    @ reg @
    identifier F =~ "^mtk_clk_register_";
    identifier FS =~ "^mtk_clk_register_[a-z_]*s";
    identifier I;
    expression clk_data;
    expression E;
    @@
      FS(...) {
	    ...
    -	struct clk *I;
    +	struct clk_hw *hw;
	    ...
	    for (...;...;...) {
		    ...
    (
    -		I
    +		hw
		    =
    -		clk_register_fixed_rate(
    +		clk_hw_register_fixed_rate(
					    ...
		    );
    |
    -		I
    +		hw
		    =
    -		clk_register_fixed_factor(
    +		clk_hw_register_fixed_factor(
					    ...
		    );
    |
    -		I
    +		hw
		    =
    -		clk_register_divider(
    +		clk_hw_register_divider(
					    ...
		    );
    |
    -		I
    +		hw
		    =
		    F(...);
    )
		    ...
		    if (
    -		    IS_ERR(I)
    +		    IS_ERR(hw)
		       ) {
			    pr_err(...,
    -			       I
    +			       hw
			    ,...);
			    ...
		    }

    -		clk_data->hws[E] = __clk_get_hw(I);
    +		clk_data->hws[E] = hw;
	    }
	    ...
      }

    @ depends on reg @
    identifier reg.I;
    @@
      return PTR_ERR(
    - I
    + hw
      );

    // Fix mtk_clk_register_composite to return clk_hw instead of clk
    @@
    identifier I, R;
    expression E;
    @@
    - struct clk *
    + struct clk_hw *
      mtk_clk_register_composite(...) {
	    ...
    -	struct clk *I;
    +	struct clk_hw *hw;
	    ...
    -	I = clk_register_composite(
    +	hw = clk_hw_register_composite(
		    ...);
	    if (IS_ERR(
    -		   I
    +		   hw
		       )) {
		    ...
		    R = PTR_ERR(
    -			      I
    +			      hw
				  );
		    ...
	    }

	    return
    -		I
    +		hw
	    ;
	    ...
      }

    // Fix other mtk_clk_register_<singular> to return clk_hw instead of clk
    @@
    identifier F =~ "^mtk_clk_register_";
    identifier I, D, C;
    expression E;
    @@
    - struct clk *
    + struct clk_hw *
      F(...) {
	    ...
    -	struct clk *I;
    +	int ret;
	    ...
    -	I = clk_register(D, E);
    +	ret = clk_hw_register(D, E);
	    ...
    (
    -	if (IS_ERR(I))
    +	if (ret) {
		    kfree(C);
    +		return ERR_PTR(ret);
    +	}
    |
    -	if (IS_ERR(I))
    +	if (ret)
	    {
		    kfree(C);
    -		return I;
    +		return ERR_PTR(ret);
	    }
    )

    -	return I;
    +	return E;
      }

    // Fix mtk_clk_unregister_<singular> to take clk_hw instead of clk
    @@
    identifier F =~ "^mtk_clk_unregister_";
    identifier I, I2;
    @@
      static void F(
    - 	struct clk *I
    +	struct clk_hw *I2
      )
      {
	    ...
    -	struct clk_hw *I2;
	    ...
    -	I2 = __clk_get_hw(I);
	    ...
    (
    -	clk_unregister(I);
    +	clk_hw_unregister(I2);
    |
    -	clk_unregister_composite(I);
    +	clk_hw_unregister_composite(I2);
    )
	    ...
      }

    // Fix calls to mtk_clk_unregister_*()
    @@
    identifier F =~ "^mtk_clk_unregister_";
    expression I;
    expression E;
    @@
    - F(I->hws[E]->clk);
    + F(I->hws[E]);

Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Reviewed-by: Miles Chen <miles.chen@mediatek.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Tested-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Tested-by: Miles Chen <miles.chen@mediatek.com>
Link: https://lore.kernel.org/r/20220519071610.423372-5-wenst@chromium.org
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2022-05-19 16:57:57 -07:00
..
actions clk: actions: Make sentinel elements more obvious 2022-03-11 18:13:24 -08:00
analogbits
at91 Merge branches 'clk-starfive', 'clk-ti', 'clk-terminate' and 'clk-cleanup' into clk-next 2022-03-29 10:19:10 -07:00
axis clk: cleanup comments 2022-03-11 18:22:15 -08:00
axs10x
baikal-t1
bcm Merge branches 'clk-range', 'clk-uniphier', 'clk-apple' and 'clk-qcom' into clk-next 2022-03-29 10:19:36 -07:00
berlin
davinci
h8300
hisilicon Merge branches 'clk-starfive', 'clk-ti', 'clk-terminate' and 'clk-cleanup' into clk-next 2022-03-29 10:19:10 -07:00
imgtec
imx clk: imx: Select MXC_CLK for i.MX93 clock driver 2022-03-15 14:44:46 -07:00
ingenic clk: jz4725b: fix mmc0 clock gating 2022-02-17 17:05:07 -08:00
keystone
loongson1 clk: loongson1: Terminate clk_div_table with sentinel element 2022-03-11 18:13:24 -08:00
mediatek clk: mediatek: Switch to clk_hw provider APIs 2022-05-19 16:57:57 -07:00
meson clk: cleanup comments 2022-03-11 18:22:15 -08:00
microchip clk: microchip: Add driver for Microchip PolarFire SoC 2022-03-11 19:31:52 -08:00
mmp Merge branches 'clk-starfive', 'clk-ti', 'clk-terminate' and 'clk-cleanup' into clk-next 2022-03-29 10:19:10 -07:00
mstar
mvebu clk: mvebu: use time_is_before_eq_jiffies() instead of open coding it 2022-02-17 14:06:12 -08:00
mxs
nxp clk: nxp: Declare mux table parameter as const u32 * 2022-02-25 16:41:39 -08:00
pistachio clk: pistachio: Declare mux table as const u32[] 2022-02-25 16:41:39 -08:00
pxa
qcom There's one large change in the core clk framework here. We change how 2022-03-30 10:11:04 -07:00
ralink clk: ralink: make system controller node a reset provider 2022-02-15 17:06:37 +01:00
renesas clk: renesas: r8a779f0: Add PFC clock 2022-02-22 09:51:20 +01:00
rockchip clk: rockchip: re-add rational best approximation algorithm to the fractional divider 2022-02-24 00:07:16 +01:00
samsung clk: samsung: fix missing Tesla FSD dependency on Exynos 2022-02-01 09:14:53 +01:00
sifive clk: sifive: Move all stuff into SoCs header files from C files 2022-03-15 15:56:28 -07:00
socfpga clk: cleanup comments 2022-03-11 18:22:15 -08:00
spear
sprd
st clk: st: clkgen-mux: search reg within node or parent 2022-01-05 17:21:28 -08:00
starfive clk: starfive: Add JH7100 audio clock driver 2022-03-10 18:17:33 -08:00
sunxi clk: sunxi: sun8i-apb0: Make use of the helper function devm_platform_ioremap_resource() 2021-09-13 09:03:24 +02:00
sunxi-ng clk: sunxi-ng: sun6i-rtc: include clk/sunxi-ng.h 2022-03-25 11:36:29 +01:00
tegra clk: tegra: tegra124-emc: Fix missing put_device() call in emc_ensure_emc_driver 2022-03-11 19:22:18 -08:00
ti Merge branches 'clk-starfive', 'clk-ti', 'clk-terminate' and 'clk-cleanup' into clk-next 2022-03-29 10:19:10 -07:00
uniphier clk: uniphier: Fix fixed-rate initialization 2022-03-11 19:29:02 -08:00
ux500 clk: ux500: Add driver for the reset portions of PRCC 2021-10-26 18:06:05 -07:00
versatile clk: versatile: clk-icst: use after free on error path 2021-12-07 12:25:29 -08:00
visconti clk: visconti: prevent array overflow in visconti_clk_register_gates() 2022-03-17 12:21:28 -07:00
x86 clk: x86: Fix clk_gate_flags for RV_CLK_GATE 2022-01-06 17:57:53 -08:00
xilinx
zynq clk: zynq: Update the parameters to zynq_clk_register_periph_clk 2022-03-29 10:17:49 -07:00
zynqmp clk: zynqmp: replace warn_once with pr_debug for failed clock ops 2022-01-24 17:18:23 -08:00
.kunitconfig clk: Introduce Kunit Tests for the framework 2022-03-11 19:14:38 -08:00
clk-apple-nco.c clk: clk-apple-nco: Allow and fix module building 2022-03-15 09:56:12 -07:00
clk-asm9260.c
clk-aspeed.c
clk-aspeed.h
clk-ast2600.c clk/ast2600: Fix soc revision for AHB 2021-11-03 19:42:35 -07:00
clk-axi-clkgen.c
clk-axm5516.c
clk-bd718x7.c
clk-bm1880.c clk: bm1880: remove kfrees on static allocations 2022-01-06 17:46:56 -08:00
clk-bulk.c
clk-cdce706.c
clk-cdce925.c
clk-clps711x.c clk: clps711x: Terminate clk_div_table with sentinel element 2022-03-11 18:13:24 -08:00
clk-composite.c clk: composite: Fix 'switching' to same clock 2021-11-03 17:49:54 -07:00
clk-conf.c
clk-cs2000-cp.c clk: cs2000-cp: convert driver to regmap 2022-01-25 14:23:16 -08:00
clk-devres.c
clk-divider.c
clk-fixed-factor.c clk: fixed-factor: Introduce devm_clk_hw_register_fixed_factor_index() 2022-03-18 14:04:54 -07:00
clk-fixed-mmio.c
clk-fixed-rate.c
clk-fractional-divider.c clk: cleanup comments 2022-03-11 18:22:15 -08:00
clk-fractional-divider.h
clk-fsl-flexspi.c
clk-fsl-sai.c
clk-gate.c clk: gate: Add devm_clk_hw_register_gate() 2021-12-08 11:19:20 +01:00
clk-gate_test.c clk: gate: Add some kunit test suites 2022-01-24 17:22:53 -08:00
clk-gemini.c clk: Gemini: fix struct name in kernel-doc 2021-12-02 17:27:48 -08:00
clk-gpio.c
clk-hi655x.c
clk-highbank.c
clk-hsdk-pll.c
clk-k210.c
clk-lan966x.c clk: lan966x: Extend lan966x clock driver for clock gating support 2021-12-08 11:19:20 +01:00
clk-lmk04832.c spi: make remove callback a void function 2022-02-09 13:00:45 +00:00
clk-lochnagar.c
clk-max9485.c
clk-max77686.c
clk-milbeaut.c
clk-moxart.c
clk-multiplier.c
clk-mux.c clk: mux: Declare u32 *table parameter as const 2022-02-25 16:41:39 -08:00
clk-nomadik.c
clk-npcm7xx.c
clk-nspire.c
clk-oxnas.c clk: Use of_device_get_match_data() 2022-03-11 19:23:30 -08:00
clk-palmas.c
clk-plldig.c
clk-pwm.c
clk-qoriq.c
clk-renesas-pcie.c clk: rs9: Add Renesas 9-series PCIe clock generator driver 2022-03-18 14:09:27 -07:00
clk-rk808.c
clk-s2mps11.c
clk-scmi.c clk: scmi: Support atomic clock enable/disable API 2022-02-21 10:37:00 +00:00
clk-scpi.c
clk-si514.c
clk-si544.c
clk-si570.c
clk-si5341.c Merge branches 'clk-starfive', 'clk-ti', 'clk-terminate' and 'clk-cleanup' into clk-next 2022-03-29 10:19:10 -07:00
clk-si5351.c clk: si5351: Update datasheet references 2021-11-02 14:29:17 -07:00
clk-si5351.h clk: si5351: Update datasheet references 2021-11-02 14:29:17 -07:00
clk-sparx5.c
clk-stm32f4.c clk: stm32: Fix ltdc's clock turn off by clk_disable_unused() after system enter shell 2021-12-15 22:45:48 -08:00
clk-stm32h7.c
clk-stm32mp1.c clk: stm32mp1: Add parent_data to ETHRX clock 2022-01-24 17:17:31 -08:00
clk-tps68470.c clk: Introduce clk-tps68470 driver 2021-12-15 20:12:07 -08:00
clk-twl6040.c
clk-versaclock5.c clk: vc5: Use i2c .probe_new 2021-11-02 14:28:51 -07:00
clk-vt8500.c
clk-wm831x.c
clk-xgene.c
clk.c Revert "clk: Drop the rate range on clk_put()" 2022-04-02 19:28:53 -07:00
clk.h
clk_test.c Revert "clk: Drop the rate range on clk_put()" 2022-04-02 19:28:53 -07:00
clkdev.c
Kconfig There's one large change in the core clk framework here. We change how 2022-03-30 10:11:04 -07:00
Makefile Merge branches 'clk-range', 'clk-uniphier', 'clk-apple' and 'clk-qcom' into clk-next 2022-03-29 10:19:36 -07:00