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 07/12] power: reset: Add lan966x power reset driver Date: Mon, 20 Sep 2021 11:52:13 +0200 [thread overview] Message-ID: <20210920095218.1108151-8-horatiu.vultur@microchip.com> (raw) In-Reply-To: <20210920095218.1108151-1-horatiu.vultur@microchip.com> This adds a driver for lan966x to allow a software reset. Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com> --- drivers/power/reset/Kconfig | 6 ++ drivers/power/reset/Makefile | 1 + drivers/power/reset/lan966x-reset.c | 90 +++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 drivers/power/reset/lan966x-reset.c diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index 4b563db3ab3e..755b60c143da 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig @@ -158,6 +158,12 @@ config POWER_RESET_PIIX4_POWEROFF southbridge SOff state is entered in response to a request to power off the system. +config POWER_RESET_LAN966X + bool "Microchip Lan966x reset driver" + select MFD_SYSCON + help + This driver supports restart for Microchip Lan966x. + config POWER_RESET_LTC2952 bool "LTC2952 PowerPath power-off driver" depends on OF_GPIO diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile index f606a2f60539..0fbc817c4eb6 100644 --- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile @@ -18,6 +18,7 @@ obj-$(CONFIG_POWER_RESET_OXNAS) += oxnas-restart.o obj-$(CONFIG_POWER_RESET_QCOM_PON) += qcom-pon.o obj-$(CONFIG_POWER_RESET_OCELOT_RESET) += ocelot-reset.o obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) += piix4-poweroff.o +obj-$(CONFIG_POWER_RESET_LAN966X) += lan966x-reset.o obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o obj-$(CONFIG_POWER_RESET_REGULATOR) += regulator-poweroff.o diff --git a/drivers/power/reset/lan966x-reset.c b/drivers/power/reset/lan966x-reset.c new file mode 100644 index 000000000000..612705b680fe --- /dev/null +++ b/drivers/power/reset/lan966x-reset.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: (GPL-2.0 OR MIT) +/* + * License: Dual MIT/GPL + * Copyright (c) 2020 Microchip Corporation + */ +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/notifier.h> +#include <linux/mfd/syscon.h> +#include <linux/of_address.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/reboot.h> +#include <linux/regmap.h> + +static const char *cpu_syscon = "microchip,lan966x-cpu-syscon"; +static const char *gcb_syscon = "microchip,lan966x-switch-syscon"; + +struct lan966x_reset_context { + struct regmap *gcb_ctrl; + struct regmap *cpu_ctrl; + struct notifier_block restart_handler; +}; + +#define PROTECT_REG 0x88 +#define PROTECT_BIT BIT(5) +#define SOFT_RESET_REG 0x00 +#define SOFT_RESET_BIT BIT(1) + +static int lan966x_restart_handle(struct notifier_block *this, + unsigned long mode, void *cmd) +{ + struct lan966x_reset_context *ctx = container_of(this, struct lan966x_reset_context, + restart_handler); + + /* Make sure the core is not protected from reset */ + regmap_update_bits(ctx->cpu_ctrl, PROTECT_REG, PROTECT_BIT, 0); + + pr_emerg("Resetting SoC\n"); + + regmap_write(ctx->gcb_ctrl, SOFT_RESET_REG, SOFT_RESET_BIT); + + pr_emerg("Unable to restart system\n"); + return NOTIFY_DONE; +} + +static int lan966x_reset_probe(struct platform_device *pdev) +{ + struct lan966x_reset_context *ctx; + struct device *dev = &pdev->dev; + int err; + + ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + ctx->gcb_ctrl = syscon_regmap_lookup_by_compatible(gcb_syscon); + if (IS_ERR(ctx->gcb_ctrl)) { + dev_err(dev, "No gcb_syscon map: %s\n", gcb_syscon); + return PTR_ERR(ctx->gcb_ctrl); + } + + ctx->cpu_ctrl = syscon_regmap_lookup_by_compatible(cpu_syscon); + if (IS_ERR(ctx->cpu_ctrl)) { + dev_err(dev, "No cpu_syscon map: %s\n", cpu_syscon); + return PTR_ERR(ctx->cpu_ctrl); + } + + ctx->restart_handler.notifier_call = lan966x_restart_handle; + ctx->restart_handler.priority = 192; + err = register_restart_handler(&ctx->restart_handler); + if (err) + dev_err(dev, "can't register restart notifier (err=%d)\n", err); + + return err; +} + +static const struct of_device_id lan966x_reset_of_match[] = { + { .compatible = "microchip,lan966x-chip-reset", }, + { /*sentinel*/ } +}; + +static struct platform_driver lan966x_reset_driver = { + .probe = lan966x_reset_probe, + .driver = { + .name = "lan966x-chip-reset", + .of_match_table = lan966x_reset_of_match, + }, +}; +builtin_platform_driver(lan966x_reset_driver); -- 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 07/12] power: reset: Add lan966x power reset driver Date: Mon, 20 Sep 2021 11:52:13 +0200 [thread overview] Message-ID: <20210920095218.1108151-8-horatiu.vultur@microchip.com> (raw) In-Reply-To: <20210920095218.1108151-1-horatiu.vultur@microchip.com> This adds a driver for lan966x to allow a software reset. Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com> --- drivers/power/reset/Kconfig | 6 ++ drivers/power/reset/Makefile | 1 + drivers/power/reset/lan966x-reset.c | 90 +++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 drivers/power/reset/lan966x-reset.c diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index 4b563db3ab3e..755b60c143da 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig @@ -158,6 +158,12 @@ config POWER_RESET_PIIX4_POWEROFF southbridge SOff state is entered in response to a request to power off the system. +config POWER_RESET_LAN966X + bool "Microchip Lan966x reset driver" + select MFD_SYSCON + help + This driver supports restart for Microchip Lan966x. + config POWER_RESET_LTC2952 bool "LTC2952 PowerPath power-off driver" depends on OF_GPIO diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile index f606a2f60539..0fbc817c4eb6 100644 --- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile @@ -18,6 +18,7 @@ obj-$(CONFIG_POWER_RESET_OXNAS) += oxnas-restart.o obj-$(CONFIG_POWER_RESET_QCOM_PON) += qcom-pon.o obj-$(CONFIG_POWER_RESET_OCELOT_RESET) += ocelot-reset.o obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) += piix4-poweroff.o +obj-$(CONFIG_POWER_RESET_LAN966X) += lan966x-reset.o obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o obj-$(CONFIG_POWER_RESET_REGULATOR) += regulator-poweroff.o diff --git a/drivers/power/reset/lan966x-reset.c b/drivers/power/reset/lan966x-reset.c new file mode 100644 index 000000000000..612705b680fe --- /dev/null +++ b/drivers/power/reset/lan966x-reset.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: (GPL-2.0 OR MIT) +/* + * License: Dual MIT/GPL + * Copyright (c) 2020 Microchip Corporation + */ +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/notifier.h> +#include <linux/mfd/syscon.h> +#include <linux/of_address.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/reboot.h> +#include <linux/regmap.h> + +static const char *cpu_syscon = "microchip,lan966x-cpu-syscon"; +static const char *gcb_syscon = "microchip,lan966x-switch-syscon"; + +struct lan966x_reset_context { + struct regmap *gcb_ctrl; + struct regmap *cpu_ctrl; + struct notifier_block restart_handler; +}; + +#define PROTECT_REG 0x88 +#define PROTECT_BIT BIT(5) +#define SOFT_RESET_REG 0x00 +#define SOFT_RESET_BIT BIT(1) + +static int lan966x_restart_handle(struct notifier_block *this, + unsigned long mode, void *cmd) +{ + struct lan966x_reset_context *ctx = container_of(this, struct lan966x_reset_context, + restart_handler); + + /* Make sure the core is not protected from reset */ + regmap_update_bits(ctx->cpu_ctrl, PROTECT_REG, PROTECT_BIT, 0); + + pr_emerg("Resetting SoC\n"); + + regmap_write(ctx->gcb_ctrl, SOFT_RESET_REG, SOFT_RESET_BIT); + + pr_emerg("Unable to restart system\n"); + return NOTIFY_DONE; +} + +static int lan966x_reset_probe(struct platform_device *pdev) +{ + struct lan966x_reset_context *ctx; + struct device *dev = &pdev->dev; + int err; + + ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + ctx->gcb_ctrl = syscon_regmap_lookup_by_compatible(gcb_syscon); + if (IS_ERR(ctx->gcb_ctrl)) { + dev_err(dev, "No gcb_syscon map: %s\n", gcb_syscon); + return PTR_ERR(ctx->gcb_ctrl); + } + + ctx->cpu_ctrl = syscon_regmap_lookup_by_compatible(cpu_syscon); + if (IS_ERR(ctx->cpu_ctrl)) { + dev_err(dev, "No cpu_syscon map: %s\n", cpu_syscon); + return PTR_ERR(ctx->cpu_ctrl); + } + + ctx->restart_handler.notifier_call = lan966x_restart_handle; + ctx->restart_handler.priority = 192; + err = register_restart_handler(&ctx->restart_handler); + if (err) + dev_err(dev, "can't register restart notifier (err=%d)\n", err); + + return err; +} + +static const struct of_device_id lan966x_reset_of_match[] = { + { .compatible = "microchip,lan966x-chip-reset", }, + { /*sentinel*/ } +}; + +static struct platform_driver lan966x_reset_driver = { + .probe = lan966x_reset_probe, + .driver = { + .name = "lan966x-chip-reset", + .of_match_table = lan966x_reset_of_match, + }, +}; +builtin_platform_driver(lan966x_reset_driver); -- 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 ` [RFC PATCH net-next 05/12] reset: lan966x: Add switch reset driver Horatiu Vultur 2021-09-20 9:52 ` 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 ` Horatiu Vultur [this message] 2021-09-20 9:52 ` [RFC PATCH net-next 07/12] power: reset: Add lan966x power reset driver 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-8-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.