* [PATCH v8 0/3] Add driver for lan966x Generic Clock Controller
@ 2021-10-08 8:26 Kavyasree Kotagiri
2021-10-08 8:26 ` [PATCH v8 1/3] dt-bindings: clock: lan966x: Add binding includes for lan966x SoC clock IDs Kavyasree Kotagiri
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Kavyasree Kotagiri @ 2021-10-08 8:26 UTC (permalink / raw)
To: robh+dt, mturquette, sboyd, nicolas.ferre
Cc: linux-kernel, devicetree, linux-clk, UNGLinuxDriver,
Eugen.Hristev, Kavyasree.Kotagiri, Manohar.Puri
This patch series adds a device driver for Generic Clock Controller
of lan966x SoC.
v7 -> v8:
- Defined new constant DIV_MAX.
- Corrected and updated prescaler divider condition check.
- Added Acked-by.
v6 -> v7:
- Added Kconfig and Makefile entires for lan966x clock driver.
v5 -> v6:
- Added Acked-by to dt-bindings file.
- Removed "_clk" in clock-names.
- Added Reviewed-by to Documentation file.
v4 -> v5:
- In v4 dt-bindings, missed adding "clock-names" in required
properties and example. So, added them.
- Returning proper error - PTR_ERR.
- Removed unused variable "ret" in probe function.
v3 -> v4:
- Updated "clocks" and added "clock-names" in dt-bindings.
- Used clk_parent_data instead of of_clk_get_parent_name().
v2 -> v3:
- Fixed dt_binding_check errors.
v1 -> v2:
- Updated license in dt-bindings.
- Updated example provided for clock controller node.
Kavyasree Kotagiri (3):
dt-bindings: clock: lan966x: Add binding includes for lan966x SoC
clock IDs
dt-bindings: clock: lan966x: Add LAN966X Clock Controller
clk: lan966x: Add lan966x SoC clock driver
.../bindings/clock/microchip,lan966x-gck.yaml | 57 +++++
drivers/clk/Kconfig | 7 +
drivers/clk/Makefile | 1 +
drivers/clk/clk-lan966x.c | 239 ++++++++++++++++++
include/dt-bindings/clock/microchip,lan966x.h | 28 ++
5 files changed, 332 insertions(+)
create mode 100644 Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml
create mode 100644 drivers/clk/clk-lan966x.c
create mode 100644 include/dt-bindings/clock/microchip,lan966x.h
--
2.17.1
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v8 1/3] dt-bindings: clock: lan966x: Add binding includes for lan966x SoC clock IDs 2021-10-08 8:26 [PATCH v8 0/3] Add driver for lan966x Generic Clock Controller Kavyasree Kotagiri @ 2021-10-08 8:26 ` Kavyasree Kotagiri 2021-10-18 11:55 ` Nicolas Ferre 2021-10-08 8:26 ` [PATCH v8 2/3] dt-bindings: clock: lan966x: Add LAN966X Clock Controller Kavyasree Kotagiri 2021-10-08 8:26 ` [PATCH v8 3/3] clk: lan966x: Add lan966x SoC clock driver Kavyasree Kotagiri 2 siblings, 1 reply; 7+ messages in thread From: Kavyasree Kotagiri @ 2021-10-08 8:26 UTC (permalink / raw) To: robh+dt, mturquette, sboyd, nicolas.ferre Cc: linux-kernel, devicetree, linux-clk, UNGLinuxDriver, Eugen.Hristev, Kavyasree.Kotagiri, Manohar.Puri LAN966X supports 14 clock outputs for its peripherals. This include file is introduced to use identifiers for clocks. Signed-off-by: Kavyasree Kotagiri <kavyasree.kotagiri@microchip.com> Acked-by: Rob Herring <robh@kernel.org> --- v7 -> v8: - No changes. v6 -> v7: - No changes. v5 -> v6: - Added Acked-by. v4 -> v5: - No changes. v3 -> v4: - No changes. v2 -> v3: - No changes. v1 -> v2: - Updated license. include/dt-bindings/clock/microchip,lan966x.h | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 include/dt-bindings/clock/microchip,lan966x.h diff --git a/include/dt-bindings/clock/microchip,lan966x.h b/include/dt-bindings/clock/microchip,lan966x.h new file mode 100644 index 000000000000..fe36ed6d8b5f --- /dev/null +++ b/include/dt-bindings/clock/microchip,lan966x.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ +/* + * Copyright (c) 2021 Microchip Inc. + * + * Author: Kavyasree Kotagiri <kavyasree.kotagiri@microchip.com> + */ + +#ifndef _DT_BINDINGS_CLK_LAN966X_H +#define _DT_BINDINGS_CLK_LAN966X_H + +#define GCK_ID_QSPI0 0 +#define GCK_ID_QSPI1 1 +#define GCK_ID_QSPI2 2 +#define GCK_ID_SDMMC0 3 +#define GCK_ID_PI 4 +#define GCK_ID_MCAN0 5 +#define GCK_ID_MCAN1 6 +#define GCK_ID_FLEXCOM0 7 +#define GCK_ID_FLEXCOM1 8 +#define GCK_ID_FLEXCOM2 9 +#define GCK_ID_FLEXCOM3 10 +#define GCK_ID_FLEXCOM4 11 +#define GCK_ID_TIMER 12 +#define GCK_ID_USB_REFCLK 13 + +#define N_CLOCKS 14 + +#endif -- 2.17.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v8 1/3] dt-bindings: clock: lan966x: Add binding includes for lan966x SoC clock IDs 2021-10-08 8:26 ` [PATCH v8 1/3] dt-bindings: clock: lan966x: Add binding includes for lan966x SoC clock IDs Kavyasree Kotagiri @ 2021-10-18 11:55 ` Nicolas Ferre 0 siblings, 0 replies; 7+ messages in thread From: Nicolas Ferre @ 2021-10-18 11:55 UTC (permalink / raw) To: Kavyasree Kotagiri, robh+dt, mturquette, sboyd Cc: linux-kernel, devicetree, linux-clk, UNGLinuxDriver, Eugen.Hristev, Manohar.Puri On 08/10/2021 at 10:26, Kavyasree Kotagiri wrote: > LAN966X supports 14 clock outputs for its peripherals. > This include file is introduced to use identifiers for clocks. > > Signed-off-by: Kavyasree Kotagiri <kavyasree.kotagiri@microchip.com> > Acked-by: Rob Herring <robh@kernel.org> If mine is missing: Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com> > --- > v7 -> v8: > - No changes. > > v6 -> v7: > - No changes. > > v5 -> v6: > - Added Acked-by. > > v4 -> v5: > - No changes. > > v3 -> v4: > - No changes. > > v2 -> v3: > - No changes. > > v1 -> v2: > - Updated license. > > include/dt-bindings/clock/microchip,lan966x.h | 28 +++++++++++++++++++ > 1 file changed, 28 insertions(+) > create mode 100644 include/dt-bindings/clock/microchip,lan966x.h > > diff --git a/include/dt-bindings/clock/microchip,lan966x.h b/include/dt-bindings/clock/microchip,lan966x.h > new file mode 100644 > index 000000000000..fe36ed6d8b5f > --- /dev/null > +++ b/include/dt-bindings/clock/microchip,lan966x.h > @@ -0,0 +1,28 @@ > +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ > +/* > + * Copyright (c) 2021 Microchip Inc. > + * > + * Author: Kavyasree Kotagiri <kavyasree.kotagiri@microchip.com> > + */ > + > +#ifndef _DT_BINDINGS_CLK_LAN966X_H > +#define _DT_BINDINGS_CLK_LAN966X_H > + > +#define GCK_ID_QSPI0 0 > +#define GCK_ID_QSPI1 1 > +#define GCK_ID_QSPI2 2 > +#define GCK_ID_SDMMC0 3 > +#define GCK_ID_PI 4 > +#define GCK_ID_MCAN0 5 > +#define GCK_ID_MCAN1 6 > +#define GCK_ID_FLEXCOM0 7 > +#define GCK_ID_FLEXCOM1 8 > +#define GCK_ID_FLEXCOM2 9 > +#define GCK_ID_FLEXCOM3 10 > +#define GCK_ID_FLEXCOM4 11 > +#define GCK_ID_TIMER 12 > +#define GCK_ID_USB_REFCLK 13 > + > +#define N_CLOCKS 14 > + > +#endif > -- Nicolas Ferre ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v8 2/3] dt-bindings: clock: lan966x: Add LAN966X Clock Controller 2021-10-08 8:26 [PATCH v8 0/3] Add driver for lan966x Generic Clock Controller Kavyasree Kotagiri 2021-10-08 8:26 ` [PATCH v8 1/3] dt-bindings: clock: lan966x: Add binding includes for lan966x SoC clock IDs Kavyasree Kotagiri @ 2021-10-08 8:26 ` Kavyasree Kotagiri 2021-10-18 11:55 ` Nicolas Ferre 2021-10-08 8:26 ` [PATCH v8 3/3] clk: lan966x: Add lan966x SoC clock driver Kavyasree Kotagiri 2 siblings, 1 reply; 7+ messages in thread From: Kavyasree Kotagiri @ 2021-10-08 8:26 UTC (permalink / raw) To: robh+dt, mturquette, sboyd, nicolas.ferre Cc: linux-kernel, devicetree, linux-clk, UNGLinuxDriver, Eugen.Hristev, Kavyasree.Kotagiri, Manohar.Puri This adds the DT bindings documentation for lan966x SoC generic clock controller. Signed-off-by: Kavyasree Kotagiri <kavyasree.kotagiri@microchip.com> Reviewed-by: Rob Herring <robh@kernel.org> --- v7 -> v8: - No changes. v6 -> v7: - No changes. v5 -> v6: - Removed "_clk" in clock-names. - Added Reviewed-by. v4 -> v5: - In v4 dt-bindings, missed adding "clock-names" in required properties and example. So, added them. v3 -> v4: - Updated "clocks" description. - Added "clock-names". v2 -> v3: - Fixed dt_binding_check errors. v1 -> v2: - Updated example provided for clk controller DT node. .../bindings/clock/microchip,lan966x-gck.yaml | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml diff --git a/Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml b/Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml new file mode 100644 index 000000000000..fca83bd68e26 --- /dev/null +++ b/Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml @@ -0,0 +1,57 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/clock/microchip,lan966x-gck.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Microchip LAN966X Generic Clock Controller + +maintainers: + - Kavyasree Kotagiri <kavyasree.kotagiri@microchip.com> + +description: | + The LAN966X Generic clock controller contains 3 PLLs - cpu_clk, + ddr_clk and sys_clk. This clock controller generates and supplies + clock to various peripherals within the SoC. + +properties: + compatible: + const: microchip,lan966x-gck + + reg: + maxItems: 1 + + clocks: + items: + - description: CPU clock source + - description: DDR clock source + - description: System clock source + + clock-names: + items: + - const: cpu + - const: ddr + - const: sys + + '#clock-cells': + const: 1 + +required: + - compatible + - reg + - clocks + - clock-names + - '#clock-cells' + +additionalProperties: false + +examples: + - | + clks: clock-controller@e00c00a8 { + compatible = "microchip,lan966x-gck"; + #clock-cells = <1>; + clocks = <&cpu_clk>, <&ddr_clk>, <&sys_clk>; + clock-names = "cpu", "ddr", "sys"; + reg = <0xe00c00a8 0x38>; + }; +... -- 2.17.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v8 2/3] dt-bindings: clock: lan966x: Add LAN966X Clock Controller 2021-10-08 8:26 ` [PATCH v8 2/3] dt-bindings: clock: lan966x: Add LAN966X Clock Controller Kavyasree Kotagiri @ 2021-10-18 11:55 ` Nicolas Ferre 0 siblings, 0 replies; 7+ messages in thread From: Nicolas Ferre @ 2021-10-18 11:55 UTC (permalink / raw) To: Kavyasree Kotagiri, robh+dt, mturquette, sboyd Cc: linux-kernel, devicetree, linux-clk, UNGLinuxDriver, Eugen.Hristev, Manohar.Puri On 08/10/2021 at 10:26, Kavyasree Kotagiri wrote: > This adds the DT bindings documentation for lan966x SoC > generic clock controller. > > Signed-off-by: Kavyasree Kotagiri <kavyasree.kotagiri@microchip.com> > Reviewed-by: Rob Herring <robh@kernel.org> If it can speed-up adoption: Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com> > --- > v7 -> v8: > - No changes. > > v6 -> v7: > - No changes. > > v5 -> v6: > - Removed "_clk" in clock-names. > - Added Reviewed-by. > > v4 -> v5: > - In v4 dt-bindings, missed adding "clock-names" in required > properties and example. So, added them. > > v3 -> v4: > - Updated "clocks" description. > - Added "clock-names". > > v2 -> v3: > - Fixed dt_binding_check errors. > > v1 -> v2: > - Updated example provided for clk controller DT node. > > .../bindings/clock/microchip,lan966x-gck.yaml | 57 +++++++++++++++++++ > 1 file changed, 57 insertions(+) > create mode 100644 Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml > > diff --git a/Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml b/Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml > new file mode 100644 > index 000000000000..fca83bd68e26 > --- /dev/null > +++ b/Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml > @@ -0,0 +1,57 @@ > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) > +%YAML 1.2 > +--- > +$id: http://devicetree.org/schemas/clock/microchip,lan966x-gck.yaml# > +$schema: http://devicetree.org/meta-schemas/core.yaml# > + > +title: Microchip LAN966X Generic Clock Controller > + > +maintainers: > + - Kavyasree Kotagiri <kavyasree.kotagiri@microchip.com> > + > +description: | > + The LAN966X Generic clock controller contains 3 PLLs - cpu_clk, > + ddr_clk and sys_clk. This clock controller generates and supplies > + clock to various peripherals within the SoC. > + > +properties: > + compatible: > + const: microchip,lan966x-gck > + > + reg: > + maxItems: 1 > + > + clocks: > + items: > + - description: CPU clock source > + - description: DDR clock source > + - description: System clock source > + > + clock-names: > + items: > + - const: cpu > + - const: ddr > + - const: sys > + > + '#clock-cells': > + const: 1 > + > +required: > + - compatible > + - reg > + - clocks > + - clock-names > + - '#clock-cells' > + > +additionalProperties: false > + > +examples: > + - | > + clks: clock-controller@e00c00a8 { > + compatible = "microchip,lan966x-gck"; > + #clock-cells = <1>; > + clocks = <&cpu_clk>, <&ddr_clk>, <&sys_clk>; > + clock-names = "cpu", "ddr", "sys"; > + reg = <0xe00c00a8 0x38>; > + }; > +... > -- Nicolas Ferre ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v8 3/3] clk: lan966x: Add lan966x SoC clock driver 2021-10-08 8:26 [PATCH v8 0/3] Add driver for lan966x Generic Clock Controller Kavyasree Kotagiri 2021-10-08 8:26 ` [PATCH v8 1/3] dt-bindings: clock: lan966x: Add binding includes for lan966x SoC clock IDs Kavyasree Kotagiri 2021-10-08 8:26 ` [PATCH v8 2/3] dt-bindings: clock: lan966x: Add LAN966X Clock Controller Kavyasree Kotagiri @ 2021-10-08 8:26 ` Kavyasree Kotagiri 2021-10-18 20:09 ` Horatiu Vultur 2 siblings, 1 reply; 7+ messages in thread From: Kavyasree Kotagiri @ 2021-10-08 8:26 UTC (permalink / raw) To: robh+dt, mturquette, sboyd, nicolas.ferre Cc: linux-kernel, devicetree, linux-clk, UNGLinuxDriver, Eugen.Hristev, Kavyasree.Kotagiri, Manohar.Puri This adds Generic Clock Controller driver for lan966x SoC. Lan966x clock controller contains 3 PLLs - cpu_clk, ddr_clk and sys_clk. It generates and supplies clock to various peripherals within SoC. Register settings required to provide GCK clocking to a peripheral is as below: GCK_SRC_SEL = Select clock source. GCK_PRESCALER = Set divider value. GCK_ENA = 1 - Enable GCK clock. Signed-off-by: Kavyasree Kotagiri <kavyasree.kotagiri@microchip.com> Co-developed-by: Horatiu Vultur <horatiu.vultur@microchip.com> Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com> Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com> --- v7 -> v8: - Defined new constant DIV_MAX. - Corrected and updated divider value condition check. - Added Acked-by. v6 -> v7: - Added Kconfig and Makefile entires for lan966x clock driver. v5 -> v6: - No changes. v4 -> v5: - Returning proper error - PTR_ERR. - Removed unused variable "ret" in probe function. v3 -> v4: - Used clk_parent_data instead of of_clk_get_parent_name(). v2 -> v3: - No changes. v1 -> v2: - No changes. drivers/clk/Kconfig | 7 ++ drivers/clk/Makefile | 1 + drivers/clk/clk-lan966x.c | 239 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 247 insertions(+) create mode 100644 drivers/clk/clk-lan966x.c diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig index c5b3dc97396a..1b992a554ff8 100644 --- a/drivers/clk/Kconfig +++ b/drivers/clk/Kconfig @@ -221,6 +221,13 @@ config COMMON_CLK_GEMINI This driver supports the SoC clocks on the Cortina Systems Gemini platform, also known as SL3516 or CS3516. +config COMMON_CLK_LAN966X + bool "Generic Clock Controller driver for LAN966X SoC" + help + This driver provides support for Generic Clock Controller(GCK) on + LAN966X SoC. GCK generates and supplies clock to various peripherals + within the SoC. + config COMMON_CLK_ASPEED bool "Clock driver for Aspeed BMC SoCs" depends on ARCH_ASPEED || COMPILE_TEST diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index e42312121e51..d8565ef01b34 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile @@ -37,6 +37,7 @@ obj-$(CONFIG_ARCH_HIGHBANK) += clk-highbank.o obj-$(CONFIG_CLK_HSDK) += clk-hsdk-pll.o obj-$(CONFIG_COMMON_CLK_K210) += clk-k210.o obj-$(CONFIG_LMK04832) += clk-lmk04832.o +obj-$(CONFIG_COMMON_CLK_LAN966X) += clk-lan966x.o obj-$(CONFIG_COMMON_CLK_LOCHNAGAR) += clk-lochnagar.o obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o obj-$(CONFIG_COMMON_CLK_MAX9485) += clk-max9485.o diff --git a/drivers/clk/clk-lan966x.c b/drivers/clk/clk-lan966x.c new file mode 100644 index 000000000000..bfca8ae7a912 --- /dev/null +++ b/drivers/clk/clk-lan966x.c @@ -0,0 +1,239 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Microchip LAN966x SoC Clock driver. + * + * Copyright (C) 2021 Microchip Technology, Inc. and its subsidiaries + * + * Author: Kavyasree Kotagiri <kavyasree.kotagiri@microchip.com> + */ + +#include <linux/bitfield.h> +#include <linux/clk-provider.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/slab.h> + +#include <dt-bindings/clock/microchip,lan966x.h> + +#define GCK_ENA BIT(0) +#define GCK_SRC_SEL GENMASK(9, 8) +#define GCK_PRESCALER GENMASK(23, 16) + +#define DIV_MAX 256 + +static const char *clk_names[N_CLOCKS] = { + "qspi0", "qspi1", "qspi2", "sdmmc0", + "pi", "mcan0", "mcan1", "flexcom0", + "flexcom1", "flexcom2", "flexcom3", + "flexcom4", "timer", "usb_refclk", +}; + +struct lan966x_gck { + struct clk_hw hw; + void __iomem *reg; +}; +#define to_lan966x_gck(hw) container_of(hw, struct lan966x_gck, hw) + +static const struct clk_parent_data lan966x_gck_pdata[] = { + { .fw_name = "cpu_clk", .name = "cpu_clk" }, + { .fw_name = "ddr_clk", .name = "ddr_clk" }, + { .fw_name = "sys_clk", .name = "sys_clk" }, +}; + +static struct clk_init_data init = { + .parent_data = lan966x_gck_pdata, + .num_parents = ARRAY_SIZE(lan966x_gck_pdata), +}; + +static void __iomem *base; + +static int lan966x_gck_enable(struct clk_hw *hw) +{ + struct lan966x_gck *gck = to_lan966x_gck(hw); + u32 val = readl(gck->reg); + + val |= GCK_ENA; + writel(val, gck->reg); + + return 0; +} + +static void lan966x_gck_disable(struct clk_hw *hw) +{ + struct lan966x_gck *gck = to_lan966x_gck(hw); + u32 val = readl(gck->reg); + + val &= ~GCK_ENA; + writel(val, gck->reg); +} + +static int lan966x_gck_set_rate(struct clk_hw *hw, + unsigned long rate, + unsigned long parent_rate) +{ + struct lan966x_gck *gck = to_lan966x_gck(hw); + u32 div, val = readl(gck->reg); + + if (rate == 0 || parent_rate == 0) + return -EINVAL; + + /* Set Prescalar */ + div = parent_rate / rate; + val &= ~GCK_PRESCALER; + val |= FIELD_PREP(GCK_PRESCALER, (div - 1)); + writel(val, gck->reg); + + return 0; +} + +static long lan966x_gck_round_rate(struct clk_hw *hw, unsigned long rate, + unsigned long *parent_rate) +{ + unsigned int div; + + if (rate == 0 || *parent_rate == 0) + return -EINVAL; + + if (rate >= *parent_rate) + return *parent_rate; + + div = DIV_ROUND_CLOSEST(*parent_rate, rate); + + return *parent_rate / div; +} + +static unsigned long lan966x_gck_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct lan966x_gck *gck = to_lan966x_gck(hw); + u32 div, val = readl(gck->reg); + + div = FIELD_GET(GCK_PRESCALER, val); + + return parent_rate / (div + 1); +} + +static int lan966x_gck_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + struct clk_hw *parent; + int i; + + for (i = 0; i < clk_hw_get_num_parents(hw); ++i) { + parent = clk_hw_get_parent_by_index(hw, i); + if (!parent) + continue; + + /* Maximum prescaler divider value is 256 */ + if (clk_hw_get_rate(parent) / req->rate <= DIV_MAX) { + req->best_parent_hw = parent; + req->best_parent_rate = clk_hw_get_rate(parent); + + return 0; + } + } + + return -EINVAL; +} + +static u8 lan966x_gck_get_parent(struct clk_hw *hw) +{ + struct lan966x_gck *gck = to_lan966x_gck(hw); + u32 val = readl(gck->reg); + + return FIELD_GET(GCK_SRC_SEL, val); +} + +static int lan966x_gck_set_parent(struct clk_hw *hw, u8 index) +{ + struct lan966x_gck *gck = to_lan966x_gck(hw); + u32 val = readl(gck->reg); + + val &= ~GCK_SRC_SEL; + val |= FIELD_PREP(GCK_SRC_SEL, index); + writel(val, gck->reg); + + return 0; +} + +static const struct clk_ops lan966x_gck_ops = { + .enable = lan966x_gck_enable, + .disable = lan966x_gck_disable, + .set_rate = lan966x_gck_set_rate, + .round_rate = lan966x_gck_round_rate, + .recalc_rate = lan966x_gck_recalc_rate, + .determine_rate = lan966x_gck_determine_rate, + .set_parent = lan966x_gck_set_parent, + .get_parent = lan966x_gck_get_parent, +}; + +static struct clk_hw *lan966x_gck_clk_register(struct device *dev, int i) +{ + struct lan966x_gck *priv; + int ret; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return ERR_PTR(-ENOMEM); + + priv->reg = base + (i * 4); + priv->hw.init = &init; + ret = devm_clk_hw_register(dev, &priv->hw); + if (ret) + return ERR_PTR(ret); + + return &priv->hw; +}; + +static int lan966x_clk_probe(struct platform_device *pdev) +{ + struct clk_hw_onecell_data *hw_data; + struct device *dev = &pdev->dev; + int i; + + hw_data = devm_kzalloc(dev, sizeof(*hw_data), GFP_KERNEL); + if (!hw_data) + return -ENOMEM; + + base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(base)) + return PTR_ERR(base); + + init.ops = &lan966x_gck_ops; + + hw_data->num = N_CLOCKS; + + for (i = 0; i < N_CLOCKS; i++) { + init.name = clk_names[i]; + hw_data->hws[i] = lan966x_gck_clk_register(dev, i); + if (IS_ERR(hw_data->hws[i])) { + dev_err(dev, "failed to register %s clock\n", + init.name); + return PTR_ERR(hw_data->hws[i]); + } + } + + return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, hw_data); +} + +static const struct of_device_id lan966x_clk_dt_ids[] = { + { .compatible = "microchip,lan966x-gck", }, + { } +}; +MODULE_DEVICE_TABLE(of, lan966x_clk_dt_ids); + +static struct platform_driver lan966x_clk_driver = { + .probe = lan966x_clk_probe, + .driver = { + .name = "lan966x-clk", + .of_match_table = lan966x_clk_dt_ids, + }, +}; +builtin_platform_driver(lan966x_clk_driver); + +MODULE_AUTHOR("Kavyasree Kotagiri <kavyasree.kotagiri@microchip.com>"); +MODULE_DESCRIPTION("LAN966X clock driver"); +MODULE_LICENSE("GPL v2"); -- 2.17.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v8 3/3] clk: lan966x: Add lan966x SoC clock driver 2021-10-08 8:26 ` [PATCH v8 3/3] clk: lan966x: Add lan966x SoC clock driver Kavyasree Kotagiri @ 2021-10-18 20:09 ` Horatiu Vultur 0 siblings, 0 replies; 7+ messages in thread From: Horatiu Vultur @ 2021-10-18 20:09 UTC (permalink / raw) To: Kavyasree Kotagiri Cc: robh+dt, mturquette, sboyd, nicolas.ferre, linux-kernel, devicetree, linux-clk, UNGLinuxDriver, Eugen.Hristev, Manohar.Puri The 10/08/2021 13:56, Kavyasree Kotagiri wrote: > This adds Generic Clock Controller driver for lan966x SoC. Hi Kavya, > > +#define DIV_MAX 256 > + > +static const char *clk_names[N_CLOCKS] = { > + "qspi0", "qspi1", "qspi2", "sdmmc0", > + "pi", "mcan0", "mcan1", "flexcom0", > + "flexcom1", "flexcom2", "flexcom3", > + "flexcom4", "timer", "usb_refclk", > +}; Aren't these names a little bit generic, especially 'timer'? The problem that I am seeing, if there is another clock driver that register a clock with the same name, then this will fail. Here is the check for this[1] > + > +static int lan966x_clk_probe(struct platform_device *pdev) > +{ > + struct clk_hw_onecell_data *hw_data; > + struct device *dev = &pdev->dev; > + int i; > + > + hw_data = devm_kzalloc(dev, sizeof(*hw_data), GFP_KERNEL); Is this correct? Shouldn't be devm_kzalloc(dev, struct_size(hw_data, hws, N_CLOCKS), GFP_KERNEL); > + if (!hw_data) > + return -ENOMEM; > + > + base = devm_platform_ioremap_resource(pdev, 0); > + if (IS_ERR(base)) > + return PTR_ERR(base); > + > + init.ops = &lan966x_gck_ops; > + > + hw_data->num = N_CLOCKS; > + > + for (i = 0; i < N_CLOCKS; i++) { > + init.name = clk_names[i]; > + hw_data->hws[i] = lan966x_gck_clk_register(dev, i); > + if (IS_ERR(hw_data->hws[i])) { > + dev_err(dev, "failed to register %s clock\n", > + init.name); > + return PTR_ERR(hw_data->hws[i]); > + } > + } > + > + return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, hw_data); > +} > + > +static const struct of_device_id lan966x_clk_dt_ids[] = { > + { .compatible = "microchip,lan966x-gck", }, > + { } > +}; > +MODULE_DEVICE_TABLE(of, lan966x_clk_dt_ids); > + > +static struct platform_driver lan966x_clk_driver = { > + .probe = lan966x_clk_probe, > + .driver = { > + .name = "lan966x-clk", > + .of_match_table = lan966x_clk_dt_ids, > + }, > +}; > +builtin_platform_driver(lan966x_clk_driver); > + > +MODULE_AUTHOR("Kavyasree Kotagiri <kavyasree.kotagiri@microchip.com>"); > +MODULE_DESCRIPTION("LAN966X clock driver"); > +MODULE_LICENSE("GPL v2"); > -- > 2.17.1 > [1] https://elixir.bootlin.com/linux/latest/source/drivers/clk/clk.c#L3423 -- /Horatiu ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-10-18 20:07 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-10-08 8:26 [PATCH v8 0/3] Add driver for lan966x Generic Clock Controller Kavyasree Kotagiri 2021-10-08 8:26 ` [PATCH v8 1/3] dt-bindings: clock: lan966x: Add binding includes for lan966x SoC clock IDs Kavyasree Kotagiri 2021-10-18 11:55 ` Nicolas Ferre 2021-10-08 8:26 ` [PATCH v8 2/3] dt-bindings: clock: lan966x: Add LAN966X Clock Controller Kavyasree Kotagiri 2021-10-18 11:55 ` Nicolas Ferre 2021-10-08 8:26 ` [PATCH v8 3/3] clk: lan966x: Add lan966x SoC clock driver Kavyasree Kotagiri 2021-10-18 20:09 ` Horatiu Vultur
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).