From: Horatiu Vultur <horatiu.vultur@microchip.com> To: <davem@davemloft.net>, <kuba@kernel.org>, <robh+dt@kernel.org>, <andrew@lunn.ch>, <linux@armlinux.org.uk>, <f.fainelli@gmail.com>, <alexandre.belloni@bootlin.com>, <vladimir.oltean@nxp.com>, <UNGLinuxDriver@microchip.com>, <netdev@vger.kernel.org>, <devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <linux-phy@lists.infradead.org>, <linux-pm@vger.kernel.org> Cc: Horatiu Vultur <horatiu.vultur@microchip.com> Subject: [RFC PATCH net-next 05/12] reset: lan966x: Add switch reset driver Date: Mon, 20 Sep 2021 11:52:11 +0200 [thread overview] Message-ID: <20210920095218.1108151-6-horatiu.vultur@microchip.com> (raw) In-Reply-To: <20210920095218.1108151-1-horatiu.vultur@microchip.com> The lan966x switch SoC has a number of components that can be reset indiviually, but at least the switch core needs to be in a well defined state at power on, when any of the lan966x drivers starts to access the switch core, this reset driver is available. The reset driver is loaded early via the postcore_initcall interface, and will then be available for the other lan966x drivers (SGPIO, SwitchDev etc) that are loaded next, and the first of them to be loaded can perform the one-time switch core reset that is needed. Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com> --- drivers/reset/Kconfig | 8 +++ drivers/reset/Makefile | 1 + drivers/reset/reset-lan966x.c | 128 ++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 drivers/reset/reset-lan966x.c diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig index be799a5abf8a..93f19303ebac 100644 --- a/drivers/reset/Kconfig +++ b/drivers/reset/Kconfig @@ -108,6 +108,14 @@ config RESET_LANTIQ help This enables the reset controller driver for Lantiq / Intel XWAY SoCs. +config RESET_LAN966X + bool "Microchip LAN966X Reset Driver" + depends on HAS_IOMEM || COMPILE_TEST + default y if LAN966X_SWITCH + select MFD_SYSCON + help + This driver supports switch core reset for the Microchip LAN966X SoC. + config RESET_LPC18XX bool "LPC18xx/43xx Reset Driver" if COMPILE_TEST default ARCH_LPC18XX diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile index 21d46d8869ff..3358f491e617 100644 --- a/drivers/reset/Makefile +++ b/drivers/reset/Makefile @@ -14,6 +14,7 @@ obj-$(CONFIG_RESET_HSDK) += reset-hsdk.o obj-$(CONFIG_RESET_IMX7) += reset-imx7.o obj-$(CONFIG_RESET_INTEL_GW) += reset-intel-gw.o obj-$(CONFIG_RESET_K210) += reset-k210.o +obj-$(CONFIG_RESET_LAN966X) += reset-lan966x.o obj-$(CONFIG_RESET_LANTIQ) += reset-lantiq.o obj-$(CONFIG_RESET_LPC18XX) += reset-lpc18xx.o obj-$(CONFIG_RESET_MCHP_SPARX5) += reset-microchip-sparx5.o diff --git a/drivers/reset/reset-lan966x.c b/drivers/reset/reset-lan966x.c new file mode 100644 index 000000000000..3d4fe31653db --- /dev/null +++ b/drivers/reset/reset-lan966x.c @@ -0,0 +1,128 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (c) 2021 Microchip Technology Inc. and its subsidiaries. */ + +#include <linux/mfd/syscon.h> +#include <linux/of_device.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/reset-controller.h> + +#define PROTECT_REG 0x88 +#define PROTECT_BIT BIT(5) +#define SOFT_RESET_REG 0x00 +#define SOFT_RESET_BIT BIT(1) +#define CHIP_COMMON_REG 0x10 +#define CHIP_COMMON_BIT BIT(0) + +struct mchp_reset_context { + struct regmap *cpu_ctrl; + struct regmap *switch_ctrl; + struct regmap *chip_ctrl; + struct reset_controller_dev rcdev; +}; + +static int lan966x_switch_reset(struct reset_controller_dev *rcdev, + unsigned long id) +{ + struct mchp_reset_context *ctx = + container_of(rcdev, struct mchp_reset_context, rcdev); + u32 val; + int ret; + + /* Make sure the core is PROTECTED from reset */ + regmap_update_bits(ctx->cpu_ctrl, PROTECT_REG, PROTECT_BIT, PROTECT_BIT); + + /* Start soft reset */ + regmap_write(ctx->switch_ctrl, SOFT_RESET_REG, SOFT_RESET_BIT); + + /* Wait for soft reset done */ + ret = regmap_read_poll_timeout(ctx->switch_ctrl, SOFT_RESET_REG, val, + (val & SOFT_RESET_BIT) == 0, 1, 100); + if (ret) + return ret; + + /* Release the reset of internal PHY */ + regmap_update_bits(ctx->chip_ctrl, CHIP_COMMON_REG, CHIP_COMMON_BIT, + CHIP_COMMON_BIT); + + return 0; +} + +static const struct reset_control_ops lan966x_reset_ops = { + .reset = lan966x_switch_reset, +}; + +static int mchp_lan966x_map_syscon(struct platform_device *pdev, char *name, + struct regmap **target) +{ + struct device_node *syscon_np; + struct regmap *regmap; + int err; + + syscon_np = of_parse_phandle(pdev->dev.of_node, name, 0); + if (!syscon_np) + return -ENODEV; + regmap = syscon_node_to_regmap(syscon_np); + of_node_put(syscon_np); + if (IS_ERR(regmap)) { + err = PTR_ERR(regmap); + dev_err(&pdev->dev, "No '%s' map: %d\n", name, err); + return err; + } + + *target = regmap; + return 0; +} + +static int mchp_lan966x_reset_probe(struct platform_device *pdev) +{ + struct device_node *dn = pdev->dev.of_node; + struct mchp_reset_context *ctx; + int err; + + ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + err = mchp_lan966x_map_syscon(pdev, "cpu-syscon", &ctx->cpu_ctrl); + if (err) + return err; + + err = mchp_lan966x_map_syscon(pdev, "switch-syscon", &ctx->switch_ctrl); + if (err) + return err; + + err = mchp_lan966x_map_syscon(pdev, "chip-syscon", &ctx->chip_ctrl); + if (err) + return err; + + ctx->rcdev.owner = THIS_MODULE; + ctx->rcdev.nr_resets = 1; + ctx->rcdev.ops = &lan966x_reset_ops; + ctx->rcdev.of_node = dn; + + return devm_reset_controller_register(&pdev->dev, &ctx->rcdev); +} + +static const struct of_device_id mchp_lan966x_reset_of_match[] = { + { + .compatible = "microchip,lan966x-switch-reset", + }, + { } +}; + +static struct platform_driver mchp_lan966x_reset_driver = { + .probe = mchp_lan966x_reset_probe, + .driver = { + .name = "lan966x-switch-reset", + .of_match_table = mchp_lan966x_reset_of_match, + }, +}; + +static int __init mchp_lan966x_reset_init(void) +{ + return platform_driver_register(&mchp_lan966x_reset_driver); +} + +postcore_initcall(mchp_lan966x_reset_init); -- 2.31.1 -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy
WARNING: multiple messages have this Message-ID (diff)
From: Horatiu Vultur <horatiu.vultur@microchip.com> To: <davem@davemloft.net>, <kuba@kernel.org>, <robh+dt@kernel.org>, <andrew@lunn.ch>, <linux@armlinux.org.uk>, <f.fainelli@gmail.com>, <alexandre.belloni@bootlin.com>, <vladimir.oltean@nxp.com>, <UNGLinuxDriver@microchip.com>, <netdev@vger.kernel.org>, <devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <linux-phy@lists.infradead.org>, <linux-pm@vger.kernel.org> Cc: Horatiu Vultur <horatiu.vultur@microchip.com> Subject: [RFC PATCH net-next 05/12] reset: lan966x: Add switch reset driver Date: Mon, 20 Sep 2021 11:52:11 +0200 [thread overview] Message-ID: <20210920095218.1108151-6-horatiu.vultur@microchip.com> (raw) In-Reply-To: <20210920095218.1108151-1-horatiu.vultur@microchip.com> The lan966x switch SoC has a number of components that can be reset indiviually, but at least the switch core needs to be in a well defined state at power on, when any of the lan966x drivers starts to access the switch core, this reset driver is available. The reset driver is loaded early via the postcore_initcall interface, and will then be available for the other lan966x drivers (SGPIO, SwitchDev etc) that are loaded next, and the first of them to be loaded can perform the one-time switch core reset that is needed. Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com> --- drivers/reset/Kconfig | 8 +++ drivers/reset/Makefile | 1 + drivers/reset/reset-lan966x.c | 128 ++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 drivers/reset/reset-lan966x.c diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig index be799a5abf8a..93f19303ebac 100644 --- a/drivers/reset/Kconfig +++ b/drivers/reset/Kconfig @@ -108,6 +108,14 @@ config RESET_LANTIQ help This enables the reset controller driver for Lantiq / Intel XWAY SoCs. +config RESET_LAN966X + bool "Microchip LAN966X Reset Driver" + depends on HAS_IOMEM || COMPILE_TEST + default y if LAN966X_SWITCH + select MFD_SYSCON + help + This driver supports switch core reset for the Microchip LAN966X SoC. + config RESET_LPC18XX bool "LPC18xx/43xx Reset Driver" if COMPILE_TEST default ARCH_LPC18XX diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile index 21d46d8869ff..3358f491e617 100644 --- a/drivers/reset/Makefile +++ b/drivers/reset/Makefile @@ -14,6 +14,7 @@ obj-$(CONFIG_RESET_HSDK) += reset-hsdk.o obj-$(CONFIG_RESET_IMX7) += reset-imx7.o obj-$(CONFIG_RESET_INTEL_GW) += reset-intel-gw.o obj-$(CONFIG_RESET_K210) += reset-k210.o +obj-$(CONFIG_RESET_LAN966X) += reset-lan966x.o obj-$(CONFIG_RESET_LANTIQ) += reset-lantiq.o obj-$(CONFIG_RESET_LPC18XX) += reset-lpc18xx.o obj-$(CONFIG_RESET_MCHP_SPARX5) += reset-microchip-sparx5.o diff --git a/drivers/reset/reset-lan966x.c b/drivers/reset/reset-lan966x.c new file mode 100644 index 000000000000..3d4fe31653db --- /dev/null +++ b/drivers/reset/reset-lan966x.c @@ -0,0 +1,128 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (c) 2021 Microchip Technology Inc. and its subsidiaries. */ + +#include <linux/mfd/syscon.h> +#include <linux/of_device.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/reset-controller.h> + +#define PROTECT_REG 0x88 +#define PROTECT_BIT BIT(5) +#define SOFT_RESET_REG 0x00 +#define SOFT_RESET_BIT BIT(1) +#define CHIP_COMMON_REG 0x10 +#define CHIP_COMMON_BIT BIT(0) + +struct mchp_reset_context { + struct regmap *cpu_ctrl; + struct regmap *switch_ctrl; + struct regmap *chip_ctrl; + struct reset_controller_dev rcdev; +}; + +static int lan966x_switch_reset(struct reset_controller_dev *rcdev, + unsigned long id) +{ + struct mchp_reset_context *ctx = + container_of(rcdev, struct mchp_reset_context, rcdev); + u32 val; + int ret; + + /* Make sure the core is PROTECTED from reset */ + regmap_update_bits(ctx->cpu_ctrl, PROTECT_REG, PROTECT_BIT, PROTECT_BIT); + + /* Start soft reset */ + regmap_write(ctx->switch_ctrl, SOFT_RESET_REG, SOFT_RESET_BIT); + + /* Wait for soft reset done */ + ret = regmap_read_poll_timeout(ctx->switch_ctrl, SOFT_RESET_REG, val, + (val & SOFT_RESET_BIT) == 0, 1, 100); + if (ret) + return ret; + + /* Release the reset of internal PHY */ + regmap_update_bits(ctx->chip_ctrl, CHIP_COMMON_REG, CHIP_COMMON_BIT, + CHIP_COMMON_BIT); + + return 0; +} + +static const struct reset_control_ops lan966x_reset_ops = { + .reset = lan966x_switch_reset, +}; + +static int mchp_lan966x_map_syscon(struct platform_device *pdev, char *name, + struct regmap **target) +{ + struct device_node *syscon_np; + struct regmap *regmap; + int err; + + syscon_np = of_parse_phandle(pdev->dev.of_node, name, 0); + if (!syscon_np) + return -ENODEV; + regmap = syscon_node_to_regmap(syscon_np); + of_node_put(syscon_np); + if (IS_ERR(regmap)) { + err = PTR_ERR(regmap); + dev_err(&pdev->dev, "No '%s' map: %d\n", name, err); + return err; + } + + *target = regmap; + return 0; +} + +static int mchp_lan966x_reset_probe(struct platform_device *pdev) +{ + struct device_node *dn = pdev->dev.of_node; + struct mchp_reset_context *ctx; + int err; + + ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + err = mchp_lan966x_map_syscon(pdev, "cpu-syscon", &ctx->cpu_ctrl); + if (err) + return err; + + err = mchp_lan966x_map_syscon(pdev, "switch-syscon", &ctx->switch_ctrl); + if (err) + return err; + + err = mchp_lan966x_map_syscon(pdev, "chip-syscon", &ctx->chip_ctrl); + if (err) + return err; + + ctx->rcdev.owner = THIS_MODULE; + ctx->rcdev.nr_resets = 1; + ctx->rcdev.ops = &lan966x_reset_ops; + ctx->rcdev.of_node = dn; + + return devm_reset_controller_register(&pdev->dev, &ctx->rcdev); +} + +static const struct of_device_id mchp_lan966x_reset_of_match[] = { + { + .compatible = "microchip,lan966x-switch-reset", + }, + { } +}; + +static struct platform_driver mchp_lan966x_reset_driver = { + .probe = mchp_lan966x_reset_probe, + .driver = { + .name = "lan966x-switch-reset", + .of_match_table = mchp_lan966x_reset_of_match, + }, +}; + +static int __init mchp_lan966x_reset_init(void) +{ + return platform_driver_register(&mchp_lan966x_reset_driver); +} + +postcore_initcall(mchp_lan966x_reset_init); -- 2.31.1
next prev parent reply other threads:[~2021-09-20 9:51 UTC|newest] Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-09-20 9:52 [RFC PATCH net-next 00/12] Add lan966x driver Horatiu Vultur 2021-09-20 9:52 ` Horatiu Vultur 2021-09-20 9:52 ` [RFC PATCH net-next 01/12] net: mdio: mscc-miim: Fix the mdio controller Horatiu Vultur 2021-09-20 9:52 ` Horatiu Vultur 2021-09-20 11:52 ` Andrew Lunn 2021-09-20 11:52 ` Andrew Lunn 2021-09-22 8:24 ` Horatiu Vultur 2021-09-22 8:24 ` Horatiu Vultur 2021-09-20 9:52 ` [RFC PATCH net-next 02/12] net: phy: mchp: Add support for LAN8804 PHY Horatiu Vultur 2021-09-20 9:52 ` Horatiu Vultur 2021-09-20 10:00 ` Alexandre Belloni 2021-09-20 10:00 ` Alexandre Belloni 2021-09-20 11:59 ` Andrew Lunn 2021-09-20 11:59 ` Andrew Lunn 2021-09-22 8:35 ` Horatiu Vultur 2021-09-22 8:35 ` Horatiu Vultur 2021-09-20 9:52 ` [RFC PATCH net-next 03/12] phy: Add lan966x ethernet serdes PHY driver Horatiu Vultur 2021-09-20 9:52 ` Horatiu Vultur 2021-09-20 13:42 ` Russell King (Oracle) 2021-09-20 13:42 ` Russell King (Oracle) 2021-09-22 10:04 ` Horatiu Vultur 2021-09-22 10:04 ` Horatiu Vultur 2021-09-23 12:44 ` Rob Herring 2021-09-23 12:44 ` Rob Herring 2021-09-20 9:52 ` [RFC PATCH net-next 04/12] dt-bindings: reset: Add lan966x switch reset bindings Horatiu Vultur 2021-09-20 9:52 ` Horatiu Vultur 2021-09-23 12:49 ` Rob Herring 2021-09-23 12:49 ` Rob Herring 2021-09-20 9:52 ` Horatiu Vultur [this message] 2021-09-20 9:52 ` [RFC PATCH net-next 05/12] reset: lan966x: Add switch reset driver Horatiu Vultur 2021-09-20 12:11 ` Andrew Lunn 2021-09-20 12:11 ` Andrew Lunn 2021-09-22 9:59 ` Horatiu Vultur 2021-09-22 9:59 ` Horatiu Vultur 2021-09-20 9:52 ` [RFC PATCH net-next 06/12] dt-bindings: reset: Add lan966x power reset bindings Horatiu Vultur 2021-09-20 9:52 ` Horatiu Vultur 2021-09-20 9:52 ` [RFC PATCH net-next 07/12] power: reset: Add lan966x power reset driver Horatiu Vultur 2021-09-20 9:52 ` Horatiu Vultur 2021-09-20 12:15 ` Andrew Lunn 2021-09-20 12:15 ` Andrew Lunn 2021-09-20 9:52 ` [RFC PATCH net-next 08/12] dt-bindings: net: lan966x: Add lan966x-switch bindings Horatiu Vultur 2021-09-20 9:52 ` Horatiu Vultur 2021-09-23 12:53 ` Rob Herring 2021-09-23 12:53 ` Rob Herring 2021-09-20 9:52 ` [RFC PATCH net-next 09/12] net: lan966x: add the basic lan966x driver Horatiu Vultur 2021-09-20 9:52 ` Horatiu Vultur 2021-09-20 13:46 ` Russell King (Oracle) 2021-09-20 13:46 ` Russell King (Oracle) 2021-09-20 9:52 ` [RFC PATCH net-next 10/12] net: lan966x: add port module support Horatiu Vultur 2021-09-20 9:52 ` Horatiu Vultur 2021-09-20 13:54 ` Russell King (Oracle) 2021-09-20 13:54 ` Russell King (Oracle) 2021-09-23 8:02 ` Horatiu Vultur 2021-09-23 8:02 ` Horatiu Vultur 2021-09-20 9:52 ` [RFC PATCH net-next 11/12] net: lan966x: add mactable support Horatiu Vultur 2021-09-20 9:52 ` Horatiu Vultur 2021-09-20 9:52 ` [RFC PATCH net-next 12/12] net: lan966x: add ethtool configuration and statistics Horatiu Vultur 2021-09-20 9:52 ` Horatiu Vultur 2021-09-20 20:31 ` Jakub Kicinski 2021-09-20 20:31 ` Jakub Kicinski
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210920095218.1108151-6-horatiu.vultur@microchip.com \ --to=horatiu.vultur@microchip.com \ --cc=UNGLinuxDriver@microchip.com \ --cc=alexandre.belloni@bootlin.com \ --cc=andrew@lunn.ch \ --cc=davem@davemloft.net \ --cc=devicetree@vger.kernel.org \ --cc=f.fainelli@gmail.com \ --cc=kuba@kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-phy@lists.infradead.org \ --cc=linux-pm@vger.kernel.org \ --cc=linux@armlinux.org.uk \ --cc=netdev@vger.kernel.org \ --cc=robh+dt@kernel.org \ --cc=vladimir.oltean@nxp.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.