1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6 * Copyright (C) 2013 John Crispin <john@phrozen.org>
12 #include <linux/delay.h>
13 #include <linux/reset-controller.h>
15 #include <asm/reboot.h>
17 #include <asm/mach-ralink/ralink_regs.h>
20 #define SYSC_REG_RESET_CTRL 0x034
22 #define RSTCTL_RESET_PCI BIT(26)
23 #define RSTCTL_RESET_SYSTEM BIT(0)
25 static int ralink_assert_device(struct reset_controller_dev
*rcdev
,
33 val
= rt_sysc_r32(SYSC_REG_RESET_CTRL
);
35 rt_sysc_w32(val
, SYSC_REG_RESET_CTRL
);
40 static int ralink_deassert_device(struct reset_controller_dev
*rcdev
,
48 val
= rt_sysc_r32(SYSC_REG_RESET_CTRL
);
50 rt_sysc_w32(val
, SYSC_REG_RESET_CTRL
);
55 static int ralink_reset_device(struct reset_controller_dev
*rcdev
,
58 ralink_assert_device(rcdev
, id
);
59 return ralink_deassert_device(rcdev
, id
);
62 static const struct reset_control_ops reset_ops
= {
63 .reset
= ralink_reset_device
,
64 .assert = ralink_assert_device
,
65 .deassert
= ralink_deassert_device
,
68 static struct reset_controller_dev reset_dev
= {
72 .of_reset_n_cells
= 1,
75 void ralink_rst_init(void)
77 reset_dev
.of_node
= of_find_compatible_node(NULL
, NULL
,
78 "ralink,rt2880-reset");
79 if (!reset_dev
.of_node
)
80 pr_err("Failed to find reset controller node");
82 reset_controller_register(&reset_dev
);
85 static void ralink_restart(char *command
)
87 if (IS_ENABLED(CONFIG_PCI
)) {
88 rt_sysc_m32(0, RSTCTL_RESET_PCI
, SYSC_REG_RESET_CTRL
);
93 rt_sysc_w32(RSTCTL_RESET_SYSTEM
, SYSC_REG_RESET_CTRL
);
97 static int __init
mips_reboot_setup(void)
99 _machine_restart
= ralink_restart
;
104 arch_initcall(mips_reboot_setup
);