2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU General Public License version 2 as published
4 * by the Free Software Foundation.
6 * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
7 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
8 * Copyright (C) 2013 John Crispin <john@phrozen.org>
14 #include <linux/delay.h>
15 #include <linux/reset-controller.h>
17 #include <asm/reboot.h>
19 #include <asm/mach-ralink/ralink_regs.h>
22 #define SYSC_REG_RESET_CTRL 0x034
24 #define RSTCTL_RESET_PCI BIT(26)
25 #define RSTCTL_RESET_SYSTEM BIT(0)
27 static int ralink_assert_device(struct reset_controller_dev
*rcdev
,
35 val
= rt_sysc_r32(SYSC_REG_RESET_CTRL
);
37 rt_sysc_w32(val
, SYSC_REG_RESET_CTRL
);
42 static int ralink_deassert_device(struct reset_controller_dev
*rcdev
,
50 val
= rt_sysc_r32(SYSC_REG_RESET_CTRL
);
52 rt_sysc_w32(val
, SYSC_REG_RESET_CTRL
);
57 static int ralink_reset_device(struct reset_controller_dev
*rcdev
,
60 ralink_assert_device(rcdev
, id
);
61 return ralink_deassert_device(rcdev
, id
);
64 static const struct reset_control_ops reset_ops
= {
65 .reset
= ralink_reset_device
,
66 .assert = ralink_assert_device
,
67 .deassert
= ralink_deassert_device
,
70 static struct reset_controller_dev reset_dev
= {
74 .of_reset_n_cells
= 1,
77 void ralink_rst_init(void)
79 reset_dev
.of_node
= of_find_compatible_node(NULL
, NULL
,
80 "ralink,rt2880-reset");
81 if (!reset_dev
.of_node
)
82 pr_err("Failed to find reset controller node");
84 reset_controller_register(&reset_dev
);
87 static void ralink_restart(char *command
)
89 if (IS_ENABLED(CONFIG_PCI
)) {
90 rt_sysc_m32(0, RSTCTL_RESET_PCI
, SYSC_REG_RESET_CTRL
);
95 rt_sysc_w32(RSTCTL_RESET_SYSTEM
, SYSC_REG_RESET_CTRL
);
99 static void ralink_halt(void)
105 static int __init
mips_reboot_setup(void)
107 _machine_restart
= ralink_restart
;
108 _machine_halt
= ralink_halt
;
113 arch_initcall(mips_reboot_setup
);