@@ -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
@@ -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
@@ -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);