Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *
0004  * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
0005  * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
0006  * Copyright (C) 2013 John Crispin <john@phrozen.org>
0007  */
0008 
0009 #include <linux/pm.h>
0010 #include <linux/io.h>
0011 #include <linux/of.h>
0012 #include <linux/delay.h>
0013 #include <linux/reset-controller.h>
0014 
0015 #include <asm/reboot.h>
0016 
0017 #include <asm/mach-ralink/ralink_regs.h>
0018 
0019 /* Reset Control */
0020 #define SYSC_REG_RESET_CTRL 0x034
0021 
0022 #define RSTCTL_RESET_PCI    BIT(26)
0023 #define RSTCTL_RESET_SYSTEM BIT(0)
0024 
0025 static int ralink_assert_device(struct reset_controller_dev *rcdev,
0026                 unsigned long id)
0027 {
0028     u32 val;
0029 
0030     if (id == 0)
0031         return -1;
0032 
0033     val = rt_sysc_r32(SYSC_REG_RESET_CTRL);
0034     val |= BIT(id);
0035     rt_sysc_w32(val, SYSC_REG_RESET_CTRL);
0036 
0037     return 0;
0038 }
0039 
0040 static int ralink_deassert_device(struct reset_controller_dev *rcdev,
0041                   unsigned long id)
0042 {
0043     u32 val;
0044 
0045     if (id == 0)
0046         return -1;
0047 
0048     val = rt_sysc_r32(SYSC_REG_RESET_CTRL);
0049     val &= ~BIT(id);
0050     rt_sysc_w32(val, SYSC_REG_RESET_CTRL);
0051 
0052     return 0;
0053 }
0054 
0055 static int ralink_reset_device(struct reset_controller_dev *rcdev,
0056                    unsigned long id)
0057 {
0058     ralink_assert_device(rcdev, id);
0059     return ralink_deassert_device(rcdev, id);
0060 }
0061 
0062 static const struct reset_control_ops reset_ops = {
0063     .reset = ralink_reset_device,
0064     .assert = ralink_assert_device,
0065     .deassert = ralink_deassert_device,
0066 };
0067 
0068 static struct reset_controller_dev reset_dev = {
0069     .ops            = &reset_ops,
0070     .owner          = THIS_MODULE,
0071     .nr_resets      = 32,
0072     .of_reset_n_cells   = 1,
0073 };
0074 
0075 void ralink_rst_init(void)
0076 {
0077     reset_dev.of_node = of_find_compatible_node(NULL, NULL,
0078                         "ralink,rt2880-reset");
0079     if (!reset_dev.of_node)
0080         pr_err("Failed to find reset controller node");
0081     else
0082         reset_controller_register(&reset_dev);
0083 }
0084 
0085 static void ralink_restart(char *command)
0086 {
0087     if (IS_ENABLED(CONFIG_PCI)) {
0088         rt_sysc_m32(0, RSTCTL_RESET_PCI, SYSC_REG_RESET_CTRL);
0089         mdelay(50);
0090     }
0091 
0092     local_irq_disable();
0093     rt_sysc_w32(RSTCTL_RESET_SYSTEM, SYSC_REG_RESET_CTRL);
0094     unreachable();
0095 }
0096 
0097 static int __init mips_reboot_setup(void)
0098 {
0099     _machine_restart = ralink_restart;
0100 
0101     return 0;
0102 }
0103 
0104 arch_initcall(mips_reboot_setup);