From d5d7bb70a6ad1b4f8ceafa5e0fec78297963578c Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 15 Dec 2021 11:36:18 -0500 Subject: clk: Alphabetize Makefile This alphabetizes the clock makefile by Kconfig option. This will help prevent merge conflicts. Signed-off-by: Sean Anderson Link: https://lore.kernel.org/r/20211215163620.2770126-2-seanga2@gmail.com --- drivers/clk/Makefile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index 711ae5b..cf559ff 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile @@ -15,41 +15,41 @@ obj-y += analogbits/ obj-y += imx/ obj-y += tegra/ obj-y += ti/ +obj-$(CONFIG_$(SPL_TPL_)CLK_INTEL) += intel/ obj-$(CONFIG_ARCH_ASPEED) += aspeed/ obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/ -obj-$(CONFIG_ARCH_MTMIPS) += mtmips/ obj-$(CONFIG_ARCH_MESON) += meson/ +obj-$(CONFIG_ARCH_MTMIPS) += mtmips/ obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/ obj-$(CONFIG_ARCH_SOCFPGA) += altera/ +obj-$(CONFIG_ARCH_SUNXI) += sunxi/ obj-$(CONFIG_CLK_AT91) += at91/ -obj-$(CONFIG_CLK_MVEBU) += mvebu/ obj-$(CONFIG_CLK_BCM6345) += clk_bcm6345.o obj-$(CONFIG_CLK_BOSTON) += clk_boston.o +obj-$(CONFIG_CLK_CDCE9XX) += clk-cdce9xx.o obj-$(CONFIG_CLK_EXYNOS) += exynos/ -obj-$(CONFIG_$(SPL_TPL_)CLK_INTEL) += intel/ obj-$(CONFIG_CLK_HSDK) += clk-hsdk-cgu.o obj-$(CONFIG_CLK_K210) += clk_kendryte.o obj-$(CONFIG_CLK_MPC83XX) += mpc83xx_clk.o obj-$(CONFIG_CLK_MPFS) += microchip/ +obj-$(CONFIG_CLK_MVEBU) += mvebu/ obj-$(CONFIG_CLK_OCTEON) += clk_octeon.o obj-$(CONFIG_CLK_OWL) += owl/ obj-$(CONFIG_CLK_RENESAS) += renesas/ obj-$(CONFIG_CLK_SCMI) += clk_scmi.o obj-$(CONFIG_CLK_SIFIVE) += sifive/ -obj-$(CONFIG_ARCH_SUNXI) += sunxi/ obj-$(CONFIG_CLK_STM32F) += clk_stm32f.o obj-$(CONFIG_CLK_STM32MP1) += clk_stm32mp1.o obj-$(CONFIG_CLK_UNIPHIER) += uniphier/ +obj-$(CONFIG_CLK_VERSACLOCK) += clk_versaclock.o +obj-$(CONFIG_CLK_VERSAL) += clk_versal.o obj-$(CONFIG_CLK_VEXPRESS_OSC) += clk_vexpress_osc.o +obj-$(CONFIG_CLK_XLNX_CLKWZRD) += clk-xlnx-clock-wizard.o obj-$(CONFIG_CLK_ZYNQ) += clk_zynq.o obj-$(CONFIG_CLK_ZYNQMP) += clk_zynqmp.o -obj-$(CONFIG_CLK_XLNX_CLKWZRD) += clk-xlnx-clock-wizard.o obj-$(CONFIG_ICS8N3QV01) += ics8n3qv01.o obj-$(CONFIG_MACH_PIC32) += clk_pic32.o +obj-$(CONFIG_SANDBOX_CLK_CCF) += clk_sandbox_ccf.o obj-$(CONFIG_SANDBOX) += clk_sandbox.o obj-$(CONFIG_SANDBOX) += clk_sandbox_test.o -obj-$(CONFIG_SANDBOX_CLK_CCF) += clk_sandbox_ccf.o obj-$(CONFIG_STM32H7) += clk_stm32h7.o -obj-$(CONFIG_CLK_VERSAL) += clk_versal.o -obj-$(CONFIG_CLK_CDCE9XX) += clk-cdce9xx.o -obj-$(CONFIG_CLK_VERSACLOCK) += clk_versaclock.o -- cgit v1.1 From 7d4a78520331aadc8328ba6ea125223b7a7f6a97 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 15 Dec 2021 11:36:19 -0500 Subject: clk: Alphabetize Kconfig This alphabetizes the Kconfig for the clock subsystem. This will help people find their clocks, and help prevent merge conflicts. Signed-off-by: Sean Anderson Link: https://lore.kernel.org/r/20211215163620.2770126-3-seanga2@gmail.com --- drivers/clk/Kconfig | 182 ++++++++++++++++++++++++++-------------------------- 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig index baac8d2..2cd03c2 100644 --- a/drivers/clk/Kconfig +++ b/drivers/clk/Kconfig @@ -30,22 +30,6 @@ config TPL_CLK setting up clocks within TPL, and allows the same drivers to be used as U-Boot proper. -config CLK_BCM6345 - bool "Clock controller driver for BCM6345" - depends on CLK && ARCH_BMIPS - default y - help - This clock driver adds support for enabling and disabling peripheral - clocks on BCM6345 SoCs. HW has no rate changing capabilities. - -config CLK_BOSTON - def_bool y if TARGET_BOSTON - depends on CLK - select REGMAP - select SYSCON - help - Enable this to support the clocks - config SPL_CLK_CCF bool "SPL Common Clock Framework [CCF] support " depends on SPL @@ -73,6 +57,37 @@ config CLK_COMPOSITE_CCF Enable this option if you want to (re-)use the Linux kernel's Common Clock Framework [CCF] composite code in U-Boot's clock driver. +config CLK_BCM6345 + bool "Clock controller driver for BCM6345" + depends on CLK && ARCH_BMIPS + default y + help + This clock driver adds support for enabling and disabling peripheral + clocks on BCM6345 SoCs. HW has no rate changing capabilities. + +config CLK_BOSTON + def_bool y if TARGET_BOSTON + depends on CLK + select REGMAP + select SYSCON + help + Enable this to support the clocks + +config CLK_CDCE9XX + bool "Enable CDCD9XX clock driver" + depends on CLK + help + Enable the clock synthesizer driver for CDCE913/925/937/949 + series of chips. + +config ICS8N3QV01 + bool "Enable ICS8N3QV01 VCXO driver" + depends on CLK + help + Support for the ICS8N3QV01 Quad-Frequency VCXO (Voltage-Controlled + Crystal Oscillator). The output frequency can be programmed via an + I2C interface. + config CLK_INTEL bool "Enable clock driver for Intel x86" depends on CLK && X86 @@ -83,6 +98,25 @@ config CLK_INTEL set up by U-Boot itself but only statically. Thus the driver does not support changing clock rates, only querying them. +config CLK_K210 + bool "Clock support for Kendryte K210" + depends on CLK + help + This enables support clock driver for Kendryte K210 platforms. + +config CLK_K210_SET_RATE + bool "Enable setting the Kendryte K210 PLL rate" + depends on CLK_K210 + help + Add functionality to calculate new rates for K210 PLLs. Enabling this + feature adds around 1K to U-Boot's final size. + +config CLK_MPC83XX + bool "Enable MPC83xx clock driver" + depends on CLK + help + Support for the clock driver of the MPC83xx series of SoCs. + config CLK_OCTEON bool "Clock controller driver for Marvell MIPS Octeon" depends on CLK && ARCH_OCTEON @@ -90,6 +124,22 @@ config CLK_OCTEON help Enable this to support the clocks on Octeon MIPS platforms. +config SANDBOX_CLK_CCF + bool "Sandbox Common Clock Framework [CCF] support " + depends on SANDBOX + select CLK_CCF + help + Enable this option if you want to test the Linux kernel's Common + Clock Framework [CCF] code in U-Boot's Sandbox clock driver. + +config CLK_SCMI + bool "Enable SCMI clock driver" + depends on SCMI_FIRMWARE + help + Enable this option if you want to support clock devices exposed + by a SCMI agent based on SCMI clock protocol communication + with a SCMI server. + config CLK_STM32F bool "Enable clock driver support for STM32F family" depends on CLK && (STM32F7 || STM32F4) @@ -98,6 +148,14 @@ config CLK_STM32F This clock driver adds support for RCC clock management for STM32F4 and STM32F7 SoCs. +config CLK_STM32MP1 + bool "Enable RCC clock driver for STM32MP1" + depends on ARCH_STM32MP && CLK + default y + help + Enable the STM32 clock (RCC) driver. Enable support for + manipulating STM32MP1's on-SoC clocks. + config CLK_HSDK bool "Enable cgu clock driver for HSDK boards" depends on CLK && TARGET_HSDK @@ -105,6 +163,15 @@ config CLK_HSDK Enable this to support the cgu clocks on Synopsys ARC HSDK and Synopsys ARC HSDK-4xD boards +config CLK_VERSACLOCK + tristate "Enable VersaClock 5/6 devices" + depends on CLK + depends on CLK_CCF + depends on OF_CONTROL + help + This driver supports the IDT VersaClock 5 and VersaClock 6 + programmable clock generators. + config CLK_VERSAL bool "Enable clock driver support for Versal" depends on ARCH_VERSAL @@ -120,14 +187,6 @@ config CLK_VEXPRESS_OSC This clock driver adds support for clock generators present on Arm Versatile Express platforms. -config CLK_ZYNQ - bool "Enable clock driver support for Zynq" - depends on CLK && ARCH_ZYNQ - default y - help - This clock driver adds support for clock related settings for - Zynq platform. - config CLK_XLNX_CLKWZRD bool "Xilinx Clocking Wizard" depends on CLK @@ -139,6 +198,14 @@ config CLK_XLNX_CLKWZRD set_duty_cycle API, this driver only supports set_rate to modify the frequency. +config CLK_ZYNQ + bool "Enable clock driver support for Zynq" + depends on CLK && ARCH_ZYNQ + default y + help + This clock driver adds support for clock related settings for + Zynq platform. + config CLK_ZYNQMP bool "Enable clock driver support for ZynqMP" depends on ARCH_ZYNQMP @@ -147,42 +214,6 @@ config CLK_ZYNQMP This clock driver adds support for clock realted settings for ZynqMP platform. -config CLK_STM32MP1 - bool "Enable RCC clock driver for STM32MP1" - depends on ARCH_STM32MP && CLK - default y - help - Enable the STM32 clock (RCC) driver. Enable support for - manipulating STM32MP1's on-SoC clocks. - -config CLK_CDCE9XX - bool "Enable CDCD9XX clock driver" - depends on CLK - help - Enable the clock synthesizer driver for CDCE913/925/937/949 - series of chips. - -config CLK_SCMI - bool "Enable SCMI clock driver" - depends on SCMI_FIRMWARE - help - Enable this option if you want to support clock devices exposed - by a SCMI agent based on SCMI clock protocol communication - with a SCMI server. - -config CLK_K210 - bool "Clock support for Kendryte K210" - depends on CLK - help - This enables support clock driver for Kendryte K210 platforms. - -config CLK_K210_SET_RATE - bool "Enable setting the Kendryte K210 PLL rate" - depends on CLK_K210 - help - Add functionality to calculate new rates for K210 PLLs. Enabling this - feature adds around 1K to U-Boot's final size. - source "drivers/clk/analogbits/Kconfig" source "drivers/clk/at91/Kconfig" source "drivers/clk/exynos/Kconfig" @@ -198,35 +229,4 @@ source "drivers/clk/tegra/Kconfig" source "drivers/clk/ti/Kconfig" source "drivers/clk/uniphier/Kconfig" -config ICS8N3QV01 - bool "Enable ICS8N3QV01 VCXO driver" - depends on CLK - help - Support for the ICS8N3QV01 Quad-Frequency VCXO (Voltage-Controlled - Crystal Oscillator). The output frequency can be programmed via an - I2C interface. - -config CLK_MPC83XX - bool "Enable MPC83xx clock driver" - depends on CLK - help - Support for the clock driver of the MPC83xx series of SoCs. - -config SANDBOX_CLK_CCF - bool "Sandbox Common Clock Framework [CCF] support " - depends on SANDBOX - select CLK_CCF - help - Enable this option if you want to test the Linux kernel's Common - Clock Framework [CCF] code in U-Boot's Sandbox clock driver. - -config CLK_VERSACLOCK - tristate "Enable VersaClock 5/6 devices" - depends on CLK - depends on CLK_CCF - depends on OF_CONTROL - help - This driver supports the IDT VersaClock 5 and VersaClock 6 - programmable clock generators. - endmenu -- cgit v1.1 From 052bebe54f0b73e10b744347179c6815f8dd55f3 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 15 Dec 2021 11:36:20 -0500 Subject: clk: Rename ICS8N3QV01 to CLK_ICS8N3QV01 This driver was missing a clock prefix. Add one. Signed-off-by: Sean Anderson Link: https://lore.kernel.org/r/20211215163620.2770126-4-seanga2@gmail.com --- configs/gazerbeam_defconfig | 2 +- drivers/clk/Kconfig | 2 +- drivers/clk/Makefile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/configs/gazerbeam_defconfig b/configs/gazerbeam_defconfig index 5d8d199..199afb4 100644 --- a/configs/gazerbeam_defconfig +++ b/configs/gazerbeam_defconfig @@ -157,7 +157,7 @@ CONFIG_REGMAP=y CONFIG_AXI=y CONFIG_IHS_AXI=y CONFIG_CLK=y -CONFIG_ICS8N3QV01=y +CONFIG_CLK_ICS8N3QV01=y CONFIG_CPU=y CONFIG_CPU_MPC83XX=y CONFIG_SYS_BR0_PRELIM_BOOL=y diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig index 2cd03c2..6dc271f 100644 --- a/drivers/clk/Kconfig +++ b/drivers/clk/Kconfig @@ -80,7 +80,7 @@ config CLK_CDCE9XX Enable the clock synthesizer driver for CDCE913/925/937/949 series of chips. -config ICS8N3QV01 +config CLK_ICS8N3QV01 bool "Enable ICS8N3QV01 VCXO driver" depends on CLK help diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index cf559ff..f922a7c 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile @@ -47,7 +47,7 @@ obj-$(CONFIG_CLK_VEXPRESS_OSC) += clk_vexpress_osc.o obj-$(CONFIG_CLK_XLNX_CLKWZRD) += clk-xlnx-clock-wizard.o obj-$(CONFIG_CLK_ZYNQ) += clk_zynq.o obj-$(CONFIG_CLK_ZYNQMP) += clk_zynqmp.o -obj-$(CONFIG_ICS8N3QV01) += ics8n3qv01.o +obj-$(CONFIG_CLK_ICS8N3QV01) += ics8n3qv01.o obj-$(CONFIG_MACH_PIC32) += clk_pic32.o obj-$(CONFIG_SANDBOX_CLK_CCF) += clk_sandbox_ccf.o obj-$(CONFIG_SANDBOX) += clk_sandbox.o -- cgit v1.1 From ea5f44325ab6e8e47d299d52991f1ca6089a1592 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 1 Dec 2021 14:51:00 -0500 Subject: clk: Remove no-op request and rfree callbacks These callbacks are optional. Remove ones which do nothing. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass Link: https://lore.kernel.org/r/20211201195100.2173465-1-seanga2@gmail.com --- drivers/clk/ics8n3qv01.c | 6 ------ drivers/clk/tegra/tegra-car-clk.c | 9 --------- drivers/clk/ti/clk-sci.c | 14 -------------- 3 files changed, 29 deletions(-) diff --git a/drivers/clk/ics8n3qv01.c b/drivers/clk/ics8n3qv01.c index 6bc1b8b..33fb6ed 100644 --- a/drivers/clk/ics8n3qv01.c +++ b/drivers/clk/ics8n3qv01.c @@ -180,11 +180,6 @@ static ulong ics8n3qv01_set_rate(struct clk *clk, ulong fout) return 0; } -static int ics8n3qv01_request(struct clk *clock) -{ - return 0; -} - static ulong ics8n3qv01_get_rate(struct clk *clk) { struct ics8n3qv01_priv *priv = dev_get_priv(clk->dev); @@ -203,7 +198,6 @@ static int ics8n3qv01_disable(struct clk *clk) } static const struct clk_ops ics8n3qv01_ops = { - .request = ics8n3qv01_request, .get_rate = ics8n3qv01_get_rate, .set_rate = ics8n3qv01_set_rate, .enable = ics8n3qv01_enable, diff --git a/drivers/clk/tegra/tegra-car-clk.c b/drivers/clk/tegra/tegra-car-clk.c index 09a7cf4..c5214b9 100644 --- a/drivers/clk/tegra/tegra-car-clk.c +++ b/drivers/clk/tegra/tegra-car-clk.c @@ -30,14 +30,6 @@ static int tegra_car_clk_request(struct clk *clk) return 0; } -static int tegra_car_clk_free(struct clk *clk) -{ - debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev, - clk->id); - - return 0; -} - static ulong tegra_car_clk_get_rate(struct clk *clk) { enum clock_id parent; @@ -82,7 +74,6 @@ static int tegra_car_clk_disable(struct clk *clk) static struct clk_ops tegra_car_clk_ops = { .request = tegra_car_clk_request, - .rfree = tegra_car_clk_free, .get_rate = tegra_car_clk_get_rate, .set_rate = tegra_car_clk_set_rate, .enable = tegra_car_clk_enable, diff --git a/drivers/clk/ti/clk-sci.c b/drivers/clk/ti/clk-sci.c index acb9ead..74df5a3 100644 --- a/drivers/clk/ti/clk-sci.c +++ b/drivers/clk/ti/clk-sci.c @@ -64,18 +64,6 @@ static int ti_sci_clk_of_xlate(struct clk *clk, return 0; } -static int ti_sci_clk_request(struct clk *clk) -{ - debug("%s(clk=%p)\n", __func__, clk); - return 0; -} - -static int ti_sci_clk_free(struct clk *clk) -{ - debug("%s(clk=%p)\n", __func__, clk); - return 0; -} - static ulong ti_sci_clk_get_rate(struct clk *clk) { struct ti_sci_clk_data *data = dev_get_priv(clk->dev); @@ -208,8 +196,6 @@ static const struct udevice_id ti_sci_clk_of_match[] = { static struct clk_ops ti_sci_clk_ops = { .of_xlate = ti_sci_clk_of_xlate, - .request = ti_sci_clk_request, - .rfree = ti_sci_clk_free, .get_rate = ti_sci_clk_get_rate, .set_rate = ti_sci_clk_set_rate, .set_parent = ti_sci_clk_set_parent, -- cgit v1.1 From e8db644e0d4381b438abf165dd9542393ec9e022 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 1 Dec 2021 15:13:17 -0500 Subject: clk: versaclock: Remove xlate function This function is the same as the default xlate. Remove it. Signed-off-by: Sean Anderson Reviewed-by: Adam Ford Link: https://lore.kernel.org/r/20211201201317.2174547-1-seanga2@gmail.com --- drivers/clk/clk_versaclock.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/drivers/clk/clk_versaclock.c b/drivers/clk/clk_versaclock.c index 89c8d02..26c014c 100644 --- a/drivers/clk/clk_versaclock.c +++ b/drivers/clk/clk_versaclock.c @@ -618,24 +618,6 @@ static int vc5_clk_out_set_parent(struct vc5_driver_data *vc, u8 num, u8 index) return vc5_update_bits(vc->i2c, VC5_OUT_DIV_CONTROL(num), mask, src); } -/* - * The device references to the Versaclock point to the head, so xlate needs to - * redirect it to clk_out[idx] - */ -static int vc5_clk_out_xlate(struct clk *hw, struct ofnode_phandle_args *args) -{ - unsigned int idx = args->args[0]; - - if (args->args_count != 1) { - debug("Invalid args_count: %d\n", args->args_count); - return -EINVAL; - } - - hw->id = idx; - - return 0; -} - static unsigned long vc5_clk_out_set_rate(struct clk *hw, unsigned long rate) { struct udevice *dev; @@ -671,7 +653,6 @@ static const struct clk_ops vc5_clk_out_sel_ops = { static const struct clk_ops vc5_clk_ops = { .enable = vc5_clk_out_prepare, .disable = vc5_clk_out_unprepare, - .of_xlate = vc5_clk_out_xlate, .set_rate = vc5_clk_out_set_rate, .get_rate = vc5_clk_out_get_rate, }; -- cgit v1.1 From 6c9239351af7aa3d074c325880b6c265f217cf80 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 15 Dec 2021 11:47:17 -0500 Subject: clk: cdce9xx: Convert .of_xlate to .request This xlate function just performs some checking. We can do this in request() instead and use the default xlate. Signed-off-by: Sean Anderson Reviewed-by: Tero Kristo Link: https://lore.kernel.org/r/20211215164718.2778664-1-seanga2@gmail.com --- drivers/clk/clk-cdce9xx.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/clk/clk-cdce9xx.c b/drivers/clk/clk-cdce9xx.c index 6634b7b..f23465d 100644 --- a/drivers/clk/clk-cdce9xx.c +++ b/drivers/clk/clk-cdce9xx.c @@ -86,19 +86,13 @@ static int cdce9xx_reg_write(struct udevice *dev, u8 addr, u8 val) return ret; } -static int cdce9xx_clk_of_xlate(struct clk *clk, - struct ofnode_phandle_args *args) +static int cdce9xx_clk_request(struct clk *clk) { struct cdce9xx_clk_data *data = dev_get_priv(clk->dev); - if (args->args_count != 1) + if (clk->id > data->chip->num_outputs) return -EINVAL; - if (args->args[0] > data->chip->num_outputs) - return -EINVAL; - - clk->id = args->args[0]; - return 0; } @@ -241,7 +235,7 @@ static const struct udevice_id cdce9xx_clk_of_match[] = { }; static const struct clk_ops cdce9xx_clk_ops = { - .of_xlate = cdce9xx_clk_of_xlate, + .request = cdce9xx_clk_request, .get_rate = cdce9xx_clk_get_rate, .set_rate = cdce9xx_clk_set_rate, }; -- cgit v1.1 From 011bbfbb304fc6554163df34fbe0d50b88ace968 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 22 Dec 2021 12:11:10 -0500 Subject: clk: Rename clk_get_optional_nodev This normalizes the name of this accessor function to put "_optional" last. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass Link: https://lore.kernel.org/r/20211222171114.3091780-2-seanga2@gmail.com --- drivers/clk/clk-uclass.c | 3 ++- drivers/phy/phy-mtk-tphy.c | 8 ++++---- include/clk.h | 7 ++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index d245b67..9aa5189 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -432,7 +432,8 @@ int clk_get_by_name_nodev(ofnode node, const char *name, struct clk *clk) return clk_get_by_index_nodev(node, index, clk); } -int clk_get_optional_nodev(ofnode node, const char *name, struct clk *clk) +int clk_get_by_name_nodev_optional(ofnode node, const char *name, + struct clk *clk) { int ret; diff --git a/drivers/phy/phy-mtk-tphy.c b/drivers/phy/phy-mtk-tphy.c index 824244b..2dd964f 100644 --- a/drivers/phy/phy-mtk-tphy.c +++ b/drivers/phy/phy-mtk-tphy.c @@ -723,13 +723,13 @@ static int mtk_tphy_probe(struct udevice *dev) tphy->phys[index] = instance; index++; - err = clk_get_optional_nodev(subnode, "ref", - &instance->ref_clk); + err = clk_get_by_name_nodev_optional(subnode, "ref", + &instance->ref_clk); if (err) return err; - err = clk_get_optional_nodev(subnode, "da_ref", - &instance->da_ref_clk); + err = clk_get_by_name_nodev_optional(subnode, "da_ref", + &instance->da_ref_clk); if (err) return err; } diff --git a/include/clk.h b/include/clk.h index 040d2d6..a8225ee 100644 --- a/include/clk.h +++ b/include/clk.h @@ -194,7 +194,7 @@ int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk); int clk_get_by_name_nodev(ofnode node, const char *name, struct clk *clk); /** - * clk_get_optional_nodev - Get/request an optinonal clock by name + * clk_get_by_name_nodev_optional - Get/request an optinonal clock by name * without a device. * @node: The client ofnode. * @name: The name of the clock to request. @@ -206,7 +206,8 @@ int clk_get_by_name_nodev(ofnode node, const char *name, struct clk *clk); * no clock producer, in this case, skip the error number -ENODATA, and * the function returns 0. */ -int clk_get_optional_nodev(ofnode node, const char *name, struct clk *clk); +int clk_get_by_name_nodev_optional(ofnode node, const char *name, + struct clk *clk); /** * devm_clk_get - lookup and obtain a managed reference to a clock producer. @@ -291,7 +292,7 @@ clk_get_by_name_nodev(ofnode node, const char *name, struct clk *clk) } static inline int -clk_get_optional_nodev(ofnode node, const char *name, struct clk *clk) +clk_get_by_name_nodev_optional(ofnode node, const char *name, struct clk *clk) { return -ENOSYS; } -- cgit v1.1 From 14cacb019c2d2a97e8407fad08b164bc67def395 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 22 Dec 2021 12:11:11 -0500 Subject: clk: Inline clk_get_*_optional The optional varients of clk_get_* functions are just simple wrappers. Reduce code size a bit by inlining them. On platforms where it is not used (most of them), it will not be compiled in any more. On platforms where they are used, the inlined branch should not cause any significant growth. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass Link: https://lore.kernel.org/r/20211222171114.3091780-3-seanga2@gmail.com --- drivers/clk/clk-uclass.c | 22 ------------------- include/clk.h | 56 +++++++++++++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 44 deletions(-) diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index 9aa5189..fca4b83 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -432,18 +432,6 @@ int clk_get_by_name_nodev(ofnode node, const char *name, struct clk *clk) return clk_get_by_index_nodev(node, index, clk); } -int clk_get_by_name_nodev_optional(ofnode node, const char *name, - struct clk *clk) -{ - int ret; - - ret = clk_get_by_name_nodev(node, name, clk); - if (ret == -ENODATA) - return 0; - - return ret; -} - int clk_release_all(struct clk *clk, int count) { int i, ret; @@ -824,16 +812,6 @@ struct clk *devm_clk_get(struct udevice *dev, const char *id) return clk; } -struct clk *devm_clk_get_optional(struct udevice *dev, const char *id) -{ - struct clk *clk = devm_clk_get(dev, id); - - if (PTR_ERR(clk) == -ENODATA) - return NULL; - - return clk; -} - void devm_clk_put(struct udevice *dev, struct clk *clk) { int rc; diff --git a/include/clk.h b/include/clk.h index a8225ee..6706afa 100644 --- a/include/clk.h +++ b/include/clk.h @@ -194,22 +194,6 @@ int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk); int clk_get_by_name_nodev(ofnode node, const char *name, struct clk *clk); /** - * clk_get_by_name_nodev_optional - Get/request an optinonal clock by name - * without a device. - * @node: The client ofnode. - * @name: The name of the clock to request. - * @name: The name of the clock to request, within the client's list of - * clocks. - * @clock: A pointer to a clock struct to initialize. - * - * Behaves the same as clk_get_by_name_nodev() except where there is - * no clock producer, in this case, skip the error number -ENODATA, and - * the function returns 0. - */ -int clk_get_by_name_nodev_optional(ofnode node, const char *name, - struct clk *clk); - -/** * devm_clk_get - lookup and obtain a managed reference to a clock producer. * @dev: device for clock "consumer" * @id: clock consumer ID @@ -238,7 +222,16 @@ struct clk *devm_clk_get(struct udevice *dev, const char *id); * Behaves the same as devm_clk_get() except where there is no clock producer. * In this case, instead of returning -ENOENT, the function returns NULL. */ -struct clk *devm_clk_get_optional(struct udevice *dev, const char *id); +static inline struct clk *devm_clk_get_optional(struct udevice *dev, + const char *id) +{ + struct clk *clk = devm_clk_get(dev, id); + + if (PTR_ERR(clk) == -ENODATA) + return NULL; + + return clk; +} /** * clk_release_all() - Disable (turn off)/Free an array of previously @@ -291,17 +284,36 @@ clk_get_by_name_nodev(ofnode node, const char *name, struct clk *clk) return -ENOSYS; } -static inline int -clk_get_by_name_nodev_optional(ofnode node, const char *name, struct clk *clk) +static inline int clk_release_all(struct clk *clk, int count) { return -ENOSYS; } +#endif -static inline int clk_release_all(struct clk *clk, int count) +/** + * clk_get_by_name_nodev_optional - Get/request an optinonal clock by name + * without a device. + * @node: The client ofnode. + * @name: The name of the clock to request. + * @name: The name of the clock to request, within the client's list of + * clocks. + * @clock: A pointer to a clock struct to initialize. + * + * Behaves the same as clk_get_by_name_nodev() except where there is + * no clock producer, in this case, skip the error number -ENODATA, and + * the function returns 0. + */ +static inline int clk_get_by_name_nodev_optional(ofnode node, const char *name, + struct clk *clk) { - return -ENOSYS; + int ret; + + ret = clk_get_by_name_nodev(node, name, clk); + if (ret == -ENODATA) + return 0; + + return ret; } -#endif /** * enum clk_defaults_stage - What stage clk_set_defaults() is called at -- cgit v1.1 From 9c88b13a9031e8c1d9f4c2422791f84cd6604242 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 22 Dec 2021 12:11:12 -0500 Subject: clk: Add client API to HTML docs This converts the existing client (aka clk.h) documentation to kernel doc format, and adds it to the HTML docs. I have tried to preserve existing comments as much as possible, refraining from semantic changes. Signed-off-by: Sean Anderson Tested-by: Heinrich Schuchardt Reviewed-by: Simon Glass Link: https://lore.kernel.org/r/20211222171114.3091780-4-seanga2@gmail.com [rebased onto u-boot/master and resolved conflicts] Signed-off-by: Sean Anderson --- doc/api/clk.rst | 13 ++++ doc/api/index.rst | 1 + include/clk.h | 176 ++++++++++++++++++++++++++---------------------------- 3 files changed, 99 insertions(+), 91 deletions(-) create mode 100644 doc/api/clk.rst diff --git a/doc/api/clk.rst b/doc/api/clk.rst new file mode 100644 index 0000000..7eb3b56 --- /dev/null +++ b/doc/api/clk.rst @@ -0,0 +1,13 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +Clock API +========= + +.. kernel-doc:: include/clk.h + :doc: Overview + +Client API +---------- + +.. kernel-doc:: include/clk.h + :internal: diff --git a/doc/api/index.rst b/doc/api/index.rst index 3f36174..72fea98 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -6,6 +6,7 @@ U-Boot API documentation .. toctree:: :maxdepth: 2 + clk dfu dm efi diff --git a/include/clk.h b/include/clk.h index 6706afa..303b04a 100644 --- a/include/clk.h +++ b/include/clk.h @@ -14,6 +14,8 @@ #include /** + * DOC: Overview + * * A clock is a hardware signal that oscillates autonomously at a specific * frequency and duty cycle. Most hardware modules require one or more clock * signal to drive their operation. Clock signals are typically generated @@ -34,22 +36,22 @@ struct udevice; /** * struct clk - A handle to (allowing control of) a single clock. - * - * Clients provide storage for clock handles. The content of the structure is - * managed solely by the clock API and clock drivers. A clock struct is - * initialized by "get"ing the clock struct. The clock struct is passed to all - * other clock APIs to identify which clock signal to operate upon. - * * @dev: The device which implements the clock signal. * @rate: The clock rate (in HZ). - * @flags: Flags used across common clock structure (e.g. CLK_) + * @flags: Flags used across common clock structure (e.g. %CLK_) * Clock IP blocks specific flags (i.e. mux, div, gate, etc) are defined - * in struct's for those devices (e.g. struct clk_mux). + * in struct's for those devices (e.g. &struct clk_mux). + * @enable_count: The number of times this clock has been enabled. * @id: The clock signal ID within the provider. * @data: An optional data field for scenarios where a single integer ID is not * sufficient. If used, it can be populated through an .of_xlate op and * processed during the various clock ops. * + * Clients provide storage for clock handles. The content of the structure is + * managed solely by the clock API and clock drivers. A clock struct is + * initialized by "get"ing the clock struct. The clock struct is passed to all + * other clock APIs to identify which clock signal to operate upon. + * * Should additional information to identify and configure any clock signal * for any provider be required in the future, the struct could be expanded to * either (a) add more fields to allow clock providers to store additional @@ -72,15 +74,14 @@ struct clk { /** * struct clk_bulk - A handle to (allowing control of) a bulk of clocks. + * @clks: An array of clock handles. + * @count: The number of clock handles in the clks array. * * Clients provide storage for the clock bulk. The content of the structure is * managed solely by the clock API. A clock bulk struct is * initialized by "get"ing the clock bulk struct. * The clock bulk struct is passed to all other bulk clock APIs to apply * the API to all the clock in the bulk struct. - * - * @clks: An array of clock handles. - * @count: The number of clock handles in the clks array. */ struct clk_bulk { struct clk *clks; @@ -91,16 +92,19 @@ struct clk_bulk { struct phandle_1_arg; /** * clk_get_by_phandle() - Get a clock by its phandle information (of-platadata) + * @dev: Device containing the phandle + * @cells: Phandle info + * @clk: A pointer to a clock struct to initialise * * This function is used when of-platdata is enabled. * * This looks up a clock using the phandle info. With dtoc, each phandle in the - * 'clocks' property is transformed into an idx representing the device. For - * example: + * 'clocks' property is transformed into an idx representing the device. + * For example:: * * clocks = <&dpll_mpu_ck 23>; * - * might result in: + * might result in:: * * .clocks = {1, {23}},}, * @@ -109,9 +113,6 @@ struct phandle_1_arg; * this example it would return a clock containing the 'dpll_mpu_ck' device and * the clock ID 23. * - * @dev: Device containing the phandle - * @cells: Phandle info - * @clock: A pointer to a clock struct to initialise * Return: 0 if OK, or a negative error code. */ int clk_get_by_phandle(struct udevice *dev, const struct phandle_1_arg *cells, @@ -119,6 +120,10 @@ int clk_get_by_phandle(struct udevice *dev, const struct phandle_1_arg *cells, /** * clk_get_by_index() - Get/request a clock by integer index. + * @dev: The client device. + * @index: The index of the clock to request, within the client's list of + * clocks. + * @clk: A pointer to a clock struct to initialize. * * This looks up and requests a clock. The index is relative to the client * device; each device is assumed to have n clocks associated with it somehow, @@ -126,30 +131,26 @@ int clk_get_by_phandle(struct udevice *dev, const struct phandle_1_arg *cells, * device clock indices to provider clocks may be via device-tree properties, * board-provided mapping tables, or some other mechanism. * - * @dev: The client device. - * @index: The index of the clock to request, within the client's list of - * clocks. - * @clock A pointer to a clock struct to initialize. * Return: 0 if OK, or a negative error code. */ int clk_get_by_index(struct udevice *dev, int index, struct clk *clk); /** - * clk_get_by_index_nodev - Get/request a clock by integer index - * without a device. - * - * This is a version of clk_get_by_index() that does not use a device. - * + * clk_get_by_index_nodev() - Get/request a clock by integer index without a + * device. * @node: The client ofnode. * @index: The index of the clock to request, within the client's list of * clocks. - * @clock A pointer to a clock struct to initialize. + * @clk: A pointer to a clock struct to initialize. + * * Return: 0 if OK, or a negative error code. */ int clk_get_by_index_nodev(ofnode node, int index, struct clk *clk); /** - * clk_get_bulk - Get/request all clocks of a device. + * clk_get_bulk() - Get/request all clocks of a device. + * @dev: The client device. + * @bulk: A pointer to a clock bulk struct to initialize. * * This looks up and requests all clocks of the client device; each device is * assumed to have n clocks associated with it somehow, and this function finds @@ -157,14 +158,16 @@ int clk_get_by_index_nodev(ofnode node, int index, struct clk *clk); * device clock indices to provider clocks may be via device-tree properties, * board-provided mapping tables, or some other mechanism. * - * @dev: The client device. - * @bulk A pointer to a clock bulk struct to initialize. * Return: 0 if OK, or a negative error code. */ int clk_get_bulk(struct udevice *dev, struct clk_bulk *bulk); /** - * clk_get_by_name - Get/request a clock by name. + * clk_get_by_name() - Get/request a clock by name. + * @dev: The client device. + * @name: The name of the clock to request, within the client's list of + * clocks. + * @clk: A pointer to a clock struct to initialize. * * This looks up and requests a clock. The name is relative to the client * device; each device is assumed to have n clocks associated with it somehow, @@ -172,55 +175,49 @@ int clk_get_bulk(struct udevice *dev, struct clk_bulk *bulk); * device clock names to provider clocks may be via device-tree properties, * board-provided mapping tables, or some other mechanism. * - * @dev: The client device. - * @name: The name of the clock to request, within the client's list of - * clocks. - * @clock: A pointer to a clock struct to initialize. * Return: 0 if OK, or a negative error code. */ int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk); /** * clk_get_by_name_nodev - Get/request a clock by name without a device. - * - * This is a version of clk_get_by_name() that does not use a device. - * * @node: The client ofnode. * @name: The name of the clock to request, within the client's list of * clocks. - * @clock: A pointer to a clock struct to initialize. + * @clk: A pointer to a clock struct to initialize. + * * Return: 0 if OK, or a negative error code. */ int clk_get_by_name_nodev(ofnode node, const char *name, struct clk *clk); /** - * devm_clk_get - lookup and obtain a managed reference to a clock producer. + * devm_clk_get() - lookup and obtain a managed reference to a clock producer. * @dev: device for clock "consumer" * @id: clock consumer ID * - * Returns a struct clk corresponding to the clock producer, or - * valid IS_ERR() condition containing errno. The implementation - * uses @dev and @id to determine the clock consumer, and thereby - * the clock producer. (IOW, @id may be identical strings, but - * clk_get may return different clock producers depending on @dev.) + * The implementation uses @dev and @id to determine the clock consumer, and + * thereby the clock producer. (IOW, @id may be identical strings, but clk_get + * may return different clock producers depending on @dev.) * * Drivers must assume that the clock source is not enabled. * - * devm_clk_get should not be called from within interrupt context. - * * The clock will automatically be freed when the device is unbound * from the bus. + * + * Return: + * a struct clk corresponding to the clock producer, or + * valid IS_ERR() condition containing errno */ struct clk *devm_clk_get(struct udevice *dev, const char *id); /** - * devm_clk_get_optional - lookup and obtain a managed reference to an optional - * clock producer. + * devm_clk_get_optional() - lookup and obtain a managed reference to an + * optional clock producer. * @dev: device for clock "consumer" * @id: clock consumer ID * * Behaves the same as devm_clk_get() except where there is no clock producer. - * In this case, instead of returning -ENOENT, the function returns NULL. + * In this case, instead of returning -%ENOENT, the function returns NULL. */ static inline struct clk *devm_clk_get_optional(struct udevice *dev, const char *id) @@ -236,13 +233,13 @@ static inline struct clk *devm_clk_get_optional(struct udevice *dev, /** * clk_release_all() - Disable (turn off)/Free an array of previously * requested clocks. + * @clk: A clock struct array that was previously successfully + * requested by clk_request/get_by_*(). + * @count: Number of clock contained in the array * * For each clock contained in the clock array, this function will check if * clock has been previously requested and then will disable and free it. * - * @clk: A clock struct array that was previously successfully - * requested by clk_request/get_by_*(). - * @count Number of clock contained in the array * Return: zero on success, or -ve error code. */ int clk_release_all(struct clk *clk, int count); @@ -294,13 +291,12 @@ static inline int clk_release_all(struct clk *clk, int count) * clk_get_by_name_nodev_optional - Get/request an optinonal clock by name * without a device. * @node: The client ofnode. - * @name: The name of the clock to request. * @name: The name of the clock to request, within the client's list of * clocks. - * @clock: A pointer to a clock struct to initialize. + * @clk: A pointer to a clock struct to initialize. * * Behaves the same as clk_get_by_name_nodev() except where there is - * no clock producer, in this case, skip the error number -ENODATA, and + * no clock producer, in this case, skip the error number -%ENODATA, and * the function returns 0. */ static inline int clk_get_by_name_nodev_optional(ofnode node, const char *name, @@ -340,12 +336,13 @@ enum clk_defaults_stage { #if CONFIG_IS_ENABLED(OF_REAL) && CONFIG_IS_ENABLED(CLK) /** - * clk_set_defaults - Process 'assigned-{clocks/clock-parents/clock-rates}' + * clk_set_defaults - Process ``assigned-{clocks/clock-parents/clock-rates}`` * properties to configure clocks - * * @dev: A device to process (the ofnode associated with this device * will be processed). * @stage: The stage of the probing process this function is called during. + * + * Return: zero on success, or -ve error code. */ int clk_set_defaults(struct udevice *dev, enum clk_defaults_stage stage); #else @@ -358,12 +355,12 @@ static inline int clk_set_defaults(struct udevice *dev, int stage) /** * clk_release_bulk() - Disable (turn off)/Free an array of previously * requested clocks in a clock bulk struct. + * @bulk: A clock bulk struct that was previously successfully + * requested by clk_get_bulk(). * * For each clock contained in the clock bulk struct, this function will check * if clock has been previously requested and then will disable and free it. * - * @clk: A clock bulk struct that was previously successfully - * requested by clk_get_bulk(). * Return: zero on success, or -ve error code. */ static inline int clk_release_bulk(struct clk_bulk *bulk) @@ -373,35 +370,35 @@ static inline int clk_release_bulk(struct clk_bulk *bulk) #if CONFIG_IS_ENABLED(CLK) /** - * clk_request - Request a clock by provider-specific ID. + * clk_request() - Request a clock by provider-specific ID. + * @dev: The clock provider device. + * @clk: A pointer to a clock struct to initialize. The caller must + * have already initialized any field in this struct which the + * clock provider uses to identify the clock. * * This requests a clock using a provider-specific ID. Generally, this function * should not be used, since clk_get_by_index/name() provide an interface that * better separates clients from intimate knowledge of clock providers. * However, this function may be useful in core SoC-specific code. * - * @dev: The clock provider device. - * @clock: A pointer to a clock struct to initialize. The caller must - * have already initialized any field in this struct which the - * clock provider uses to identify the clock. * Return: 0 if OK, or a negative error code. */ int clk_request(struct udevice *dev, struct clk *clk); /** - * clk_free - Free a previously requested clock. - * - * @clock: A clock struct that was previously successfully requested by + * clk_free() - Free a previously requested clock. + * @clk: A clock struct that was previously successfully requested by * clk_request/get_by_*(). + * * Return: 0 if OK, or a negative error code. */ int clk_free(struct clk *clk); /** * clk_get_rate() - Get current clock rate. - * * @clk: A clock struct that was previously successfully requested by * clk_request/get_by_*(). + * * Return: clock rate in Hz on success, 0 for invalid clock, or -ve error code * for other errors. */ @@ -409,98 +406,98 @@ ulong clk_get_rate(struct clk *clk); /** * clk_get_parent() - Get current clock's parent. - * * @clk: A clock struct that was previously successfully requested by * clk_request/get_by_*(). + * * Return: pointer to parent's struct clk, or error code passed as pointer */ struct clk *clk_get_parent(struct clk *clk); /** * clk_get_parent_rate() - Get parent of current clock rate. - * * @clk: A clock struct that was previously successfully requested by * clk_request/get_by_*(). + * * Return: clock rate in Hz, or -ve error code. */ long long clk_get_parent_rate(struct clk *clk); /** * clk_round_rate() - Adjust a rate to the exact rate a clock can provide + * @clk: A clock struct that was previously successfully requested by + * clk_request/get_by_*(). + * @rate: desired clock rate in Hz. * * This answers the question "if I were to pass @rate to clk_set_rate(), * what clock rate would I end up with?" without changing the hardware - * in any way. In other words: + * in any way. In other words:: * * rate = clk_round_rate(clk, r); * - * and: + * and:: * * rate = clk_set_rate(clk, r); * * are equivalent except the former does not modify the clock hardware * in any way. * - * @clk: A clock struct that was previously successfully requested by - * clk_request/get_by_*(). - * @rate: desired clock rate in Hz. * Return: rounded rate in Hz, or -ve error code. */ ulong clk_round_rate(struct clk *clk, ulong rate); /** * clk_set_rate() - Set current clock rate. - * * @clk: A clock struct that was previously successfully requested by * clk_request/get_by_*(). * @rate: New clock rate in Hz. + * * Return: new rate, or -ve error code. */ ulong clk_set_rate(struct clk *clk, ulong rate); /** * clk_set_parent() - Set current clock parent. - * * @clk: A clock struct that was previously successfully requested by * clk_request/get_by_*(). * @parent: A clock struct that was previously successfully requested by * clk_request/get_by_*(). + * * Return: new rate, or -ve error code. */ int clk_set_parent(struct clk *clk, struct clk *parent); /** * clk_enable() - Enable (turn on) a clock. - * * @clk: A clock struct that was previously successfully requested by * clk_request/get_by_*(). + * * Return: zero on success, or -ve error code. */ int clk_enable(struct clk *clk); /** * clk_enable_bulk() - Enable (turn on) all clocks in a clock bulk struct. - * * @bulk: A clock bulk struct that was previously successfully requested * by clk_get_bulk(). + * * Return: zero on success, or -ve error code. */ int clk_enable_bulk(struct clk_bulk *bulk); /** * clk_disable() - Disable (turn off) a clock. - * * @clk: A clock struct that was previously successfully requested by * clk_request/get_by_*(). + * * Return: zero on success, or -ve error code. */ int clk_disable(struct clk *clk); /** * clk_disable_bulk() - Disable (turn off) all clocks in a clock bulk struct. - * * @bulk: A clock bulk struct that was previously successfully requested * by clk_get_bulk(). + * * Return: zero on success, or -ve error code. */ int clk_disable_bulk(struct clk_bulk *bulk); @@ -510,28 +507,25 @@ int clk_disable_bulk(struct clk_bulk *bulk); * @p: clk compared against q * @q: clk compared against p * - * Returns true if the two struct clk pointers both point to the same hardware - * clock node. - * - * Returns false otherwise. Note that two NULL clks are treated as matching. + * Return: + * %true if the two struct clk pointers both point to the same hardware clock + * node, and %false otherwise. Note that two %NULL clks are treated as matching. */ bool clk_is_match(const struct clk *p, const struct clk *q); /** * clk_get_by_id() - Get the clock by its ID - * * @id: The clock ID to search for - * * @clkp: A pointer to clock struct that has been found among added clocks * to UCLASS_CLK + * * Return: zero on success, or -ENOENT on error */ int clk_get_by_id(ulong id, struct clk **clkp); /** * clk_dev_binded() - Check whether the clk has a device binded - * - * @clk A pointer to the clk + * @clk: A pointer to the clk * * Return: true on binded, or false on no */ @@ -617,8 +611,8 @@ static inline bool clk_dev_binded(struct clk *clk) /** * clk_valid() - check if clk is valid - * * @clk: the clock to check + * * Return: true if valid, or false */ static inline bool clk_valid(struct clk *clk) -- cgit v1.1 From a0abea867a0d344d8e5290adf6380903b0f52e0f Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 22 Dec 2021 12:11:13 -0500 Subject: clk: Add driver API to HTML docs This converts the existing driver API docs (clk-uclass.h) to kernel doc format and adds them to the HTML documentation. Because the kernel doc sphinx converter does not handle functions in structs very well, the individual methods are documented separately. This is primarily inspired by the phylink documentation [1], which uses this trick extensively. [1] https://www.kernel.org/doc/html/latest/networking/kapi.html#c.phylink_mac_ops Signed-off-by: Sean Anderson Tested-by: Heinrich Schuchardt Reviewed-by: Simon Glass Link: https://lore.kernel.org/r/20211222171114.3091780-5-seanga2@gmail.com --- doc/api/clk.rst | 6 ++ include/clk-uclass.h | 187 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 115 insertions(+), 78 deletions(-) diff --git a/doc/api/clk.rst b/doc/api/clk.rst index 7eb3b56..7c27066 100644 --- a/doc/api/clk.rst +++ b/doc/api/clk.rst @@ -11,3 +11,9 @@ Client API .. kernel-doc:: include/clk.h :internal: + +Driver API +---------- + +.. kernel-doc:: include/clk-uclass.h + :internal: diff --git a/include/clk-uclass.h b/include/clk-uclass.h index 50e8681..e44f1ca 100644 --- a/include/clk-uclass.h +++ b/include/clk-uclass.h @@ -16,96 +16,127 @@ struct ofnode_phandle_args; /** * struct clk_ops - The functions that a clock driver must implement. + * @of_xlate: Translate a client's device-tree (OF) clock specifier. + * @request: Request a translated clock. + * @rfree: Free a previously requested clock. + * @round_rate: Adjust a rate to the exact rate a clock can provide. + * @get_rate: Get current clock rate. + * @set_rate: Set current clock rate. + * @set_parent: Set current clock parent + * @enable: Enable a clock. + * @disable: Disable a clock. + * + * The individual methods are described more fully below. */ struct clk_ops { - /** - * of_xlate - Translate a client's device-tree (OF) clock specifier. - * - * The clock core calls this function as the first step in implementing - * a client's clk_get_by_*() call. - * - * If this function pointer is set to NULL, the clock core will use a - * default implementation, which assumes #clock-cells = <1>, and that - * the DT cell contains a simple integer clock ID. - * - * At present, the clock API solely supports device-tree. If this - * changes, other xxx_xlate() functions may be added to support those - * other mechanisms. - * - * @clock: The clock struct to hold the translation result. - * @args: The clock specifier values from device tree. - * @return 0 if OK, or a negative error code. - */ int (*of_xlate)(struct clk *clock, struct ofnode_phandle_args *args); - /** - * request - Request a translated clock. - * - * The clock core calls this function as the second step in - * implementing a client's clk_get_by_*() call, following a successful - * xxx_xlate() call, or as the only step in implementing a client's - * clk_request() call. - * - * @clock: The clock struct to request; this has been fille in by - * a previoux xxx_xlate() function call, or by the caller - * of clk_request(). - * @return 0 if OK, or a negative error code. - */ int (*request)(struct clk *clock); - /** - * rfree - Free a previously requested clock. - * - * This is the implementation of the client clk_free() API. - * - * @clock: The clock to free. - * @return 0 if OK, or a negative error code. - */ int (*rfree)(struct clk *clock); - /** - * round_rate() - Adjust a rate to the exact rate a clock can provide. - * - * @clk: The clock to manipulate. - * @rate: Desidered clock rate in Hz. - * @return rounded rate in Hz, or -ve error code. - */ ulong (*round_rate)(struct clk *clk, ulong rate); - /** - * get_rate() - Get current clock rate. - * - * @clk: The clock to query. - * @return clock rate in Hz, or -ve error code - */ ulong (*get_rate)(struct clk *clk); - /** - * set_rate() - Set current clock rate. - * - * @clk: The clock to manipulate. - * @rate: New clock rate in Hz. - * @return new rate, or -ve error code. - */ ulong (*set_rate)(struct clk *clk, ulong rate); - /** - * set_parent() - Set current clock parent - * - * @clk: The clock to manipulate. - * @parent: New clock parent. - * @return zero on success, or -ve error code. - */ int (*set_parent)(struct clk *clk, struct clk *parent); - /** - * enable() - Enable a clock. - * - * @clk: The clock to manipulate. - * @return zero on success, or -ve error code. - */ int (*enable)(struct clk *clk); - /** - * disable() - Disable a clock. - * - * @clk: The clock to manipulate. - * @return zero on success, or -ve error code. - */ int (*disable)(struct clk *clk); }; +#if 0 /* For documentation only */ +/** + * of_xlate() - Translate a client's device-tree (OF) clock specifier. + * @clock: The clock struct to hold the translation result. + * @args: The clock specifier values from device tree. + * + * The clock core calls this function as the first step in implementing + * a client's clk_get_by_*() call. + * + * If this function pointer is set to NULL, the clock core will use a + * default implementation, which assumes #clock-cells = <1>, and that + * the DT cell contains a simple integer clock ID. + * + * At present, the clock API solely supports device-tree. If this + * changes, other xxx_xlate() functions may be added to support those + * other mechanisms. + * + * Return: 0 if OK, or a negative error code. + */ +int of_xlate(struct clk *clock, struct ofnode_phandle_args *args); + +/** + * request() - Request a translated clock. + * @clock: The clock struct to request; this has been fille in by + * a previoux xxx_xlate() function call, or by the caller + * of clk_request(). + * + * The clock core calls this function as the second step in + * implementing a client's clk_get_by_*() call, following a successful + * xxx_xlate() call, or as the only step in implementing a client's + * clk_request() call. + * + * Return: 0 if OK, or a negative error code. + */ +int request(struct clk *clock); + +/** + * rfree() - Free a previously requested clock. + * @clock: The clock to free. + * + * This is the implementation of the client clk_free() API. + * + * Return: 0 if OK, or a negative error code. + */ +int rfree(struct clk *clock); + +/** + * round_rate() - Adjust a rate to the exact rate a clock can provide. + * @clk: The clock to manipulate. + * @rate: Desidered clock rate in Hz. + * + * Return: rounded rate in Hz, or -ve error code. + */ +ulong round_rate(struct clk *clk, ulong rate); + +/** + * get_rate() - Get current clock rate. + * @clk: The clock to query. + * + * Return: clock rate in Hz, or -ve error code + */ +ulong get_rate(struct clk *clk); + +/** + * set_rate() - Set current clock rate. + * @clk: The clock to manipulate. + * @rate: New clock rate in Hz. + * + * Return: new rate, or -ve error code. + */ +ulong set_rate(struct clk *clk, ulong rate); + +/** + * set_parent() - Set current clock parent + * @clk: The clock to manipulate. + * @parent: New clock parent. + * + * Return: zero on success, or -ve error code. + */ +int set_parent(struct clk *clk, struct clk *parent); + +/** + * enable() - Enable a clock. + * @clk: The clock to manipulate. + * + * Return: zero on success, or -ve error code. + */ +int enable(struct clk *clk); + +/** + * disable() - Disable a clock. + * @clk: The clock to manipulate. + * + * Return: zero on success, or -ve error code. + */ +int disable(struct clk *clk); +#endif + #endif -- cgit v1.1 From e96e2132f977aab738994c11162b14695029be6e Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Sat, 15 Jan 2022 15:52:47 -0500 Subject: clk: Add clk_get_by_name_optional This adds a helper function for clk_get_by_name in cases where the clock is optional. Hopefully this helps point driver writers in the right direction. Also convert some existing users. Signed-off-by: Sean Anderson Reviewed-by: Neil Armstrong Reviewed-by: Simon Glass Link: https://lore.kernel.org/r/20220115205247.566210-2-seanga2@gmail.com --- drivers/clk/clk_zynq.c | 5 +++-- drivers/rng/meson-rng.c | 4 ++-- include/clk.h | 24 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/drivers/clk/clk_zynq.c b/drivers/clk/clk_zynq.c index 18915c3..e80500e 100644 --- a/drivers/clk/clk_zynq.c +++ b/drivers/clk/clk_zynq.c @@ -472,8 +472,9 @@ static int zynq_clk_probe(struct udevice *dev) for (i = 0; i < 2; i++) { sprintf(name, "gem%d_emio_clk", i); - ret = clk_get_by_name(dev, name, &priv->gem_emio_clk[i]); - if (ret < 0 && ret != -ENODATA) { + ret = clk_get_by_name_optional(dev, name, + &priv->gem_emio_clk[i]); + if (ret) { dev_err(dev, "failed to get %s clock\n", name); return ret; } diff --git a/drivers/rng/meson-rng.c b/drivers/rng/meson-rng.c index 5a4f45a..e0a1e8c 100644 --- a/drivers/rng/meson-rng.c +++ b/drivers/rng/meson-rng.c @@ -91,8 +91,8 @@ static int meson_rng_of_to_plat(struct udevice *dev) return -ENODEV; /* Get optional "core" clock */ - err = clk_get_by_name(dev, "core", &pdata->clk); - if (err && err != -ENODATA) + err = clk_get_by_name_optional(dev, "core", &pdata->clk); + if (err) return err; return 0; diff --git a/include/clk.h b/include/clk.h index 303b04a..23e4d4e 100644 --- a/include/clk.h +++ b/include/clk.h @@ -288,6 +288,30 @@ static inline int clk_release_all(struct clk *clk, int count) #endif /** + * clk_get_by_name_optional() - Get/request a optional clock by name. + * @dev: The client device. + * @name: The name of the clock to request, within the client's list of + * clocks. + * @clk: A pointer to a clock struct to initialize. + * + * Behaves the same as clk_get_by_name(), except when there is no clock + * provider. In the latter case, return 0. + * + * Return: 0 if OK, or a negative error code. + */ +static inline int clk_get_by_name_optional(struct udevice *dev, + const char *name, struct clk *clk) +{ + int ret; + + ret = clk_get_by_name(dev, name, clk); + if (ret == -ENODATA) + return 0; + + return ret; +} + +/** * clk_get_by_name_nodev_optional - Get/request an optinonal clock by name * without a device. * @node: The client ofnode. -- cgit v1.1 From b0cdd8287add19d1af6668b6e9e968046506c08d Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 24 Jan 2022 14:17:14 +0100 Subject: clk: ccf: correct the test on the parent uclass in clk_enable/clk_disable It is safe to check if the uclass id on the device is UCLASS_CLK before to call the clk_ functions, but today this comparison is not done on the device used in API: clkp->dev->parent but on the device himself: clkp->dev. This patch corrects this behavior and tests if the parent device is a clock device before to call the clock API, clk_enable or clk_disable, on this device. Fixes: 0520be0f67e3 ("clk: prograte clk enable/disable to parent") Signed-off-by: Patrick Delaunay Reviewed-by: Sean Anderson --- drivers/clk/clk-uclass.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index fca4b83..c20c928 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -641,7 +641,7 @@ int clk_enable(struct clk *clk) return 0; } if (clkp->dev->parent && - device_get_uclass_id(clkp->dev) == UCLASS_CLK) { + device_get_uclass_id(clkp->dev->parent) == UCLASS_CLK) { ret = clk_enable(dev_get_clk_ptr(clkp->dev->parent)); if (ret) { printf("Enable %s failed\n", @@ -715,7 +715,7 @@ int clk_disable(struct clk *clk) } if (clkp && clkp->dev->parent && - device_get_uclass_id(clkp->dev) == UCLASS_CLK) { + device_get_uclass_id(clkp->dev->parent) == UCLASS_CLK) { ret = clk_disable(dev_get_clk_ptr(clkp->dev->parent)); if (ret) { printf("Disable %s failed\n", -- cgit v1.1 From 3386fb1e485da7f206488ed206a61ae811885d90 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 31 Jan 2022 17:21:37 +0100 Subject: cmd: clk: test the number of argument in setfreq command Test the number of argument in setfreq command to avoid a crash when the command setfreq is called without argument: STM32MP> clk setfreq data abort pc : [] lr : [] reloc pc : [] lr : [] sp : dbaf45b8 ip : ddb1d859 fp : 00000002 r10: dbb3fd80 r9 : dbb11e90 r8 : ddbf38cc r7 : ddb39725 r6 : 00000000 r5 : 00000000 r4 : dbb3fd84 r3 : dbb3fd84 r2 : 0000000a r1 : dbaf45bc r0 : 00000011 Flags: nzCv IRQs off FIQs off Mode SVC_32 (T) Code: 4dd3 1062 85a3 ddbd (7803) 2b30 Resetting CPU ... Fixes: 7ab418fbe612 ("clk: add support for setting clk rate from cmdline") Signed-off-by: Patrick Delaunay Reviewed-by: Sean Anderson Link: https://lore.kernel.org/r/20220131172131.1.I32a8f213d330dccd922f7aafc60d3d63fcbe8615@changeid --- cmd/clk.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/clk.c b/cmd/clk.c index dbbdc31..5223779 100644 --- a/cmd/clk.c +++ b/cmd/clk.c @@ -120,6 +120,9 @@ static int do_clk_setfreq(struct cmd_tbl *cmdtp, int flag, int argc, s32 freq; struct udevice *dev; + if (argc != 3) + return CMD_RET_USAGE; + freq = dectoul(argv[2], NULL); dev = clk_lookup(argv[1]); -- cgit v1.1 From afcc26140bc6bff7c23ce02dbba7882c97d2c14a Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 31 Jan 2022 17:21:38 +0100 Subject: cmd: clk: replace clk_lookup by uclass_get_device_by_name The function clk_lookup can be replaced by a direct call to uclass_get_device_by_name for UCLASS_CLK. This patch removes duplicated codes by the generic DM API and avoids issue in clk_lookup because result of uclass_get_device wasn't tested; when ret < 0, dev = NULL and dev->name is invalid, the next function call strcmp(name, dev->name) causes a crash. Signed-off-by: Patrick Delaunay Link: https://lore.kernel.org/r/20220131172131.2.I7bc7762eff1e31ab7ff5b34c416ee03b8fe52200@changeid --- cmd/clk.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/cmd/clk.c b/cmd/clk.c index 5223779..d615f14 100644 --- a/cmd/clk.c +++ b/cmd/clk.c @@ -99,20 +99,6 @@ static int do_clk_dump(struct cmd_tbl *cmdtp, int flag, int argc, } #if CONFIG_IS_ENABLED(DM) && CONFIG_IS_ENABLED(CLK) -struct udevice *clk_lookup(const char *name) -{ - int i = 0; - struct udevice *dev; - - do { - uclass_get_device(UCLASS_CLK, i++, &dev); - if (!strcmp(name, dev->name)) - return dev; - } while (dev); - - return NULL; -} - static int do_clk_setfreq(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -125,9 +111,7 @@ static int do_clk_setfreq(struct cmd_tbl *cmdtp, int flag, int argc, freq = dectoul(argv[2], NULL); - dev = clk_lookup(argv[1]); - - if (dev) + if (!uclass_get_device_by_name(UCLASS_CLK, argv[1], &dev)) clk = dev_get_clk_ptr(dev); if (!clk) { -- cgit v1.1 From 534859ac6b2fecb631457736e77e9d0df1e57616 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 31 Jan 2022 17:21:39 +0100 Subject: cmd: clk: update result of do_clk_setfreq Update the result of do_clk_setfreq and always returns a CMD_RET_ value (-EINVAL was a possible result). This patch avoid the CLI output "exit not allowed from main input shell." Fixes: 7ab418fbe612 ("clk: add support for setting clk rate from cmdline") Signed-off-by: Patrick Delaunay Reviewed-by: Sean Anderson Link: https://lore.kernel.org/r/20220131172131.3.Iec2029edb7fc0b29e13bcb86058ad2f614f62779@changeid --- cmd/clk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/clk.c b/cmd/clk.c index d615f14..73dea5e 100644 --- a/cmd/clk.c +++ b/cmd/clk.c @@ -116,7 +116,7 @@ static int do_clk_setfreq(struct cmd_tbl *cmdtp, int flag, int argc, if (!clk) { printf("clock '%s' not found.\n", argv[1]); - return -EINVAL; + return CMD_RET_FAILURE; } freq = clk_set_rate(clk, freq); -- cgit v1.1 From 92a1bba85761e4dd5c0647c48048423bceef4749 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 31 Jan 2022 17:21:40 +0100 Subject: cmd: clk: fix long help message Fix the long help message for "clk setfreq" command Fixes: 7ab418fbe612 ("clk: add support for setting clk rate from cmdline") Signed-off-by: Patrick Delaunay Reviewed-by: Sean Anderson Link: https://lore.kernel.org/r/20220131172131.4.Ic863c28ffdcc15b3f4616434c2efd88b4e45495c@changeid --- cmd/clk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/clk.c b/cmd/clk.c index 73dea5e..a483fd8 100644 --- a/cmd/clk.c +++ b/cmd/clk.c @@ -160,7 +160,7 @@ static int do_clk(struct cmd_tbl *cmdtp, int flag, int argc, #ifdef CONFIG_SYS_LONGHELP static char clk_help_text[] = "dump - Print clock frequencies\n" - "setfreq [clk] [freq] - Set clock frequency"; + "clk setfreq [clk] [freq] - Set clock frequency"; #endif U_BOOT_CMD(clk, 4, 1, do_clk, "CLK sub-system", clk_help_text); -- cgit v1.1