Linux Audio

Check our new training course

Loading...
v5.4
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
 
 
 
  3 *
  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>
  7 */
  8
  9#include <linux/pm.h>
 10#include <linux/io.h>
 11#include <linux/of.h>
 12#include <linux/delay.h>
 13#include <linux/reset-controller.h>
 14
 15#include <asm/reboot.h>
 16
 17#include <asm/mach-ralink/ralink_regs.h>
 18
 19/* Reset Control */
 20#define SYSC_REG_RESET_CTRL	0x034
 21
 22#define RSTCTL_RESET_PCI	BIT(26)
 23#define RSTCTL_RESET_SYSTEM	BIT(0)
 24
 25static int ralink_assert_device(struct reset_controller_dev *rcdev,
 26				unsigned long id)
 27{
 28	u32 val;
 29
 30	if (id < 8)
 31		return -1;
 32
 33	val = rt_sysc_r32(SYSC_REG_RESET_CTRL);
 34	val |= BIT(id);
 35	rt_sysc_w32(val, SYSC_REG_RESET_CTRL);
 36
 37	return 0;
 38}
 39
 40static int ralink_deassert_device(struct reset_controller_dev *rcdev,
 41				  unsigned long id)
 42{
 43	u32 val;
 44
 45	if (id < 8)
 46		return -1;
 47
 48	val = rt_sysc_r32(SYSC_REG_RESET_CTRL);
 49	val &= ~BIT(id);
 50	rt_sysc_w32(val, SYSC_REG_RESET_CTRL);
 51
 52	return 0;
 53}
 54
 55static int ralink_reset_device(struct reset_controller_dev *rcdev,
 56			       unsigned long id)
 57{
 58	ralink_assert_device(rcdev, id);
 59	return ralink_deassert_device(rcdev, id);
 60}
 61
 62static const struct reset_control_ops reset_ops = {
 63	.reset = ralink_reset_device,
 64	.assert = ralink_assert_device,
 65	.deassert = ralink_deassert_device,
 66};
 67
 68static struct reset_controller_dev reset_dev = {
 69	.ops			= &reset_ops,
 70	.owner			= THIS_MODULE,
 71	.nr_resets		= 32,
 72	.of_reset_n_cells	= 1,
 73};
 74
 75void ralink_rst_init(void)
 76{
 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");
 81	else
 82		reset_controller_register(&reset_dev);
 83}
 84
 85static void ralink_restart(char *command)
 86{
 87	if (IS_ENABLED(CONFIG_PCI)) {
 88		rt_sysc_m32(0, RSTCTL_RESET_PCI, SYSC_REG_RESET_CTRL);
 89		mdelay(50);
 90	}
 91
 92	local_irq_disable();
 93	rt_sysc_w32(RSTCTL_RESET_SYSTEM, SYSC_REG_RESET_CTRL);
 94	unreachable();
 95}
 96
 
 
 
 
 
 
 97static int __init mips_reboot_setup(void)
 98{
 99	_machine_restart = ralink_restart;
 
 
100
101	return 0;
102}
103
104arch_initcall(mips_reboot_setup);
v3.15
 
  1/*
  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.
  5 *
  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 <blogic@openwrt.org>
  9 */
 10
 11#include <linux/pm.h>
 12#include <linux/io.h>
 13#include <linux/of.h>
 
 14#include <linux/reset-controller.h>
 15
 16#include <asm/reboot.h>
 17
 18#include <asm/mach-ralink/ralink_regs.h>
 19
 20/* Reset Control */
 21#define SYSC_REG_RESET_CTRL     0x034
 22#define RSTCTL_RESET_SYSTEM     BIT(0)
 
 
 23
 24static int ralink_assert_device(struct reset_controller_dev *rcdev,
 25				unsigned long id)
 26{
 27	u32 val;
 28
 29	if (id < 8)
 30		return -1;
 31
 32	val = rt_sysc_r32(SYSC_REG_RESET_CTRL);
 33	val |= BIT(id);
 34	rt_sysc_w32(val, SYSC_REG_RESET_CTRL);
 35
 36	return 0;
 37}
 38
 39static int ralink_deassert_device(struct reset_controller_dev *rcdev,
 40				  unsigned long id)
 41{
 42	u32 val;
 43
 44	if (id < 8)
 45		return -1;
 46
 47	val = rt_sysc_r32(SYSC_REG_RESET_CTRL);
 48	val &= ~BIT(id);
 49	rt_sysc_w32(val, SYSC_REG_RESET_CTRL);
 50
 51	return 0;
 52}
 53
 54static int ralink_reset_device(struct reset_controller_dev *rcdev,
 55			       unsigned long id)
 56{
 57	ralink_assert_device(rcdev, id);
 58	return ralink_deassert_device(rcdev, id);
 59}
 60
 61static struct reset_control_ops reset_ops = {
 62	.reset = ralink_reset_device,
 63	.assert = ralink_assert_device,
 64	.deassert = ralink_deassert_device,
 65};
 66
 67static struct reset_controller_dev reset_dev = {
 68	.ops			= &reset_ops,
 69	.owner			= THIS_MODULE,
 70	.nr_resets		= 32,
 71	.of_reset_n_cells	= 1,
 72};
 73
 74void ralink_rst_init(void)
 75{
 76	reset_dev.of_node = of_find_compatible_node(NULL, NULL,
 77						"ralink,rt2880-reset");
 78	if (!reset_dev.of_node)
 79		pr_err("Failed to find reset controller node");
 80	else
 81		reset_controller_register(&reset_dev);
 82}
 83
 84static void ralink_restart(char *command)
 85{
 
 
 
 
 
 86	local_irq_disable();
 87	rt_sysc_w32(RSTCTL_RESET_SYSTEM, SYSC_REG_RESET_CTRL);
 88	unreachable();
 89}
 90
 91static void ralink_halt(void)
 92{
 93	local_irq_disable();
 94	unreachable();
 95}
 96
 97static int __init mips_reboot_setup(void)
 98{
 99	_machine_restart = ralink_restart;
100	_machine_halt = ralink_halt;
101	pm_power_off = ralink_halt;
102
103	return 0;
104}
105
106arch_initcall(mips_reboot_setup);