Linux Audio

Check our new training course

Loading...
v4.17
  1/*
  2 * This file is subject to the terms and conditions of the GNU General Public
  3 * License.  See the file "COPYING" in the main directory of this archive
  4 * for more details.
  5 *
  6 * Copyright (C) 2001 Keith M Wesolowski
  7 * Copyright (C) 2001 Paul Mundt
  8 * Copyright (C) 2003 Guido Guenther <agx@sigxcpu.org>
  9 */
 10
 11#include <linux/compiler.h>
 12#include <linux/init.h>
 13#include <linux/kernel.h>
 14#include <linux/module.h>
 
 15#include <linux/sched.h>
 16#include <linux/sched/signal.h>
 17#include <linux/notifier.h>
 18#include <linux/delay.h>
 19#include <linux/rtc/ds1685.h>
 20#include <linux/interrupt.h>
 21#include <linux/pm.h>
 22
 23#include <asm/addrspace.h>
 24#include <asm/irq.h>
 25#include <asm/reboot.h>
 26#include <asm/wbflush.h>
 27#include <asm/ip32/mace.h>
 28#include <asm/ip32/crime.h>
 29#include <asm/ip32/ip32_ints.h>
 30
 31#define POWERDOWN_TIMEOUT	120
 32/*
 33 * Blink frequency during reboot grace period and when panicked.
 34 */
 35#define POWERDOWN_FREQ		(HZ / 4)
 36#define PANIC_FREQ		(HZ / 8)
 37
 38extern struct platform_device ip32_rtc_device;
 39
 40static struct timer_list power_timer, blink_timer;
 41static unsigned long blink_timer_timeout;
 42static int has_panicked, shutting_down;
 43
 44static __noreturn void ip32_poweroff(void *data)
 45{
 46	void (*poweroff_func)(struct platform_device *) =
 47		symbol_get(ds1685_rtc_poweroff);
 48
 49#ifdef CONFIG_MODULES
 50	/* If the first __symbol_get failed, our module wasn't loaded. */
 51	if (!poweroff_func) {
 52		request_module("rtc-ds1685");
 53		poweroff_func = symbol_get(ds1685_rtc_poweroff);
 54	}
 55#endif
 56
 57	if (!poweroff_func)
 58		pr_emerg("RTC not available for power-off.  Spinning forever ...\n");
 59	else {
 60		(*poweroff_func)((struct platform_device *)data);
 61		symbol_put(ds1685_rtc_poweroff);
 62	}
 63
 64	unreachable();
 65}
 66
 67static void ip32_machine_restart(char *cmd) __noreturn;
 68static void ip32_machine_restart(char *cmd)
 69{
 70	msleep(20);
 71	crime->control = CRIME_CONTROL_HARD_RESET;
 72	unreachable();
 73}
 74
 75static void blink_timeout(struct timer_list *unused)
 76{
 77	unsigned long led = mace->perif.ctrl.misc ^ MACEISA_LED_RED;
 78	mace->perif.ctrl.misc = led;
 79	mod_timer(&blink_timer, jiffies + blink_timer_timeout);
 80}
 81
 82static void ip32_machine_halt(void)
 83{
 84	ip32_poweroff(&ip32_rtc_device);
 85}
 86
 87static void power_timeout(struct timer_list *unused)
 88{
 89	ip32_poweroff(&ip32_rtc_device);
 90}
 91
 92void ip32_prepare_poweroff(void)
 93{
 94	if (has_panicked)
 95		return;
 96
 97	if (shutting_down || kill_cad_pid(SIGINT, 1)) {
 98		/* No init process or button pressed twice.  */
 99		ip32_poweroff(&ip32_rtc_device);
100	}
101
102	shutting_down = 1;
103	blink_timer_timeout = POWERDOWN_FREQ;
104	blink_timeout(&blink_timer);
105
106	timer_setup(&power_timer, power_timeout, 0);
107	power_timer.expires = jiffies + POWERDOWN_TIMEOUT * HZ;
108	add_timer(&power_timer);
109}
110
111static int panic_event(struct notifier_block *this, unsigned long event,
112		       void *ptr)
113{
114	unsigned long led;
115
116	if (has_panicked)
117		return NOTIFY_DONE;
118	has_panicked = 1;
119
120	/* turn off the green LED */
121	led = mace->perif.ctrl.misc | MACEISA_LED_GREEN;
122	mace->perif.ctrl.misc = led;
123
124	blink_timer_timeout = PANIC_FREQ;
125	blink_timeout(&blink_timer);
126
127	return NOTIFY_DONE;
128}
129
130static struct notifier_block panic_block = {
131	.notifier_call = panic_event,
132};
133
134static __init int ip32_reboot_setup(void)
135{
136	/* turn on the green led only */
137	unsigned long led = mace->perif.ctrl.misc;
138	led |= MACEISA_LED_RED;
139	led &= ~MACEISA_LED_GREEN;
140	mace->perif.ctrl.misc = led;
141
142	_machine_restart = ip32_machine_restart;
143	_machine_halt = ip32_machine_halt;
144	pm_power_off = ip32_machine_halt;
145
146	timer_setup(&blink_timer, blink_timeout, 0);
147	atomic_notifier_chain_register(&panic_notifier_list, &panic_block);
148
149	return 0;
150}
151
152subsys_initcall(ip32_reboot_setup);
v6.2
  1/*
  2 * This file is subject to the terms and conditions of the GNU General Public
  3 * License.  See the file "COPYING" in the main directory of this archive
  4 * for more details.
  5 *
  6 * Copyright (C) 2001 Keith M Wesolowski
  7 * Copyright (C) 2001 Paul Mundt
  8 * Copyright (C) 2003 Guido Guenther <agx@sigxcpu.org>
  9 */
 10
 11#include <linux/compiler.h>
 12#include <linux/init.h>
 13#include <linux/kernel.h>
 14#include <linux/module.h>
 15#include <linux/panic_notifier.h>
 16#include <linux/sched.h>
 17#include <linux/sched/signal.h>
 18#include <linux/notifier.h>
 19#include <linux/delay.h>
 20#include <linux/rtc/ds1685.h>
 21#include <linux/interrupt.h>
 22#include <linux/pm.h>
 23
 24#include <asm/addrspace.h>
 25#include <asm/irq.h>
 26#include <asm/reboot.h>
 27#include <asm/wbflush.h>
 28#include <asm/ip32/mace.h>
 29#include <asm/ip32/crime.h>
 30#include <asm/ip32/ip32_ints.h>
 31
 32#define POWERDOWN_TIMEOUT	120
 33/*
 34 * Blink frequency during reboot grace period and when panicked.
 35 */
 36#define POWERDOWN_FREQ		(HZ / 4)
 37#define PANIC_FREQ		(HZ / 8)
 38
 39extern struct platform_device ip32_rtc_device;
 40
 41static struct timer_list power_timer, blink_timer;
 42static unsigned long blink_timer_timeout;
 43static int has_panicked, shutting_down;
 44
 45static __noreturn void ip32_poweroff(void *data)
 46{
 47	void (*poweroff_func)(struct platform_device *) =
 48		symbol_get(ds1685_rtc_poweroff);
 49
 50#ifdef CONFIG_MODULES
 51	/* If the first __symbol_get failed, our module wasn't loaded. */
 52	if (!poweroff_func) {
 53		request_module("rtc-ds1685");
 54		poweroff_func = symbol_get(ds1685_rtc_poweroff);
 55	}
 56#endif
 57
 58	if (!poweroff_func)
 59		pr_emerg("RTC not available for power-off.  Spinning forever ...\n");
 60	else {
 61		(*poweroff_func)((struct platform_device *)data);
 62		symbol_put(ds1685_rtc_poweroff);
 63	}
 64
 65	unreachable();
 66}
 67
 68static void ip32_machine_restart(char *cmd) __noreturn;
 69static void ip32_machine_restart(char *cmd)
 70{
 71	msleep(20);
 72	crime->control = CRIME_CONTROL_HARD_RESET;
 73	unreachable();
 74}
 75
 76static void blink_timeout(struct timer_list *unused)
 77{
 78	unsigned long led = mace->perif.ctrl.misc ^ MACEISA_LED_RED;
 79	mace->perif.ctrl.misc = led;
 80	mod_timer(&blink_timer, jiffies + blink_timer_timeout);
 81}
 82
 83static void ip32_machine_halt(void)
 84{
 85	ip32_poweroff(&ip32_rtc_device);
 86}
 87
 88static void power_timeout(struct timer_list *unused)
 89{
 90	ip32_poweroff(&ip32_rtc_device);
 91}
 92
 93void ip32_prepare_poweroff(void)
 94{
 95	if (has_panicked)
 96		return;
 97
 98	if (shutting_down || kill_cad_pid(SIGINT, 1)) {
 99		/* No init process or button pressed twice.  */
100		ip32_poweroff(&ip32_rtc_device);
101	}
102
103	shutting_down = 1;
104	blink_timer_timeout = POWERDOWN_FREQ;
105	blink_timeout(&blink_timer);
106
107	timer_setup(&power_timer, power_timeout, 0);
108	power_timer.expires = jiffies + POWERDOWN_TIMEOUT * HZ;
109	add_timer(&power_timer);
110}
111
112static int panic_event(struct notifier_block *this, unsigned long event,
113		       void *ptr)
114{
115	unsigned long led;
116
117	if (has_panicked)
118		return NOTIFY_DONE;
119	has_panicked = 1;
120
121	/* turn off the green LED */
122	led = mace->perif.ctrl.misc | MACEISA_LED_GREEN;
123	mace->perif.ctrl.misc = led;
124
125	blink_timer_timeout = PANIC_FREQ;
126	blink_timeout(&blink_timer);
127
128	return NOTIFY_DONE;
129}
130
131static struct notifier_block panic_block = {
132	.notifier_call = panic_event,
133};
134
135static __init int ip32_reboot_setup(void)
136{
137	/* turn on the green led only */
138	unsigned long led = mace->perif.ctrl.misc;
139	led |= MACEISA_LED_RED;
140	led &= ~MACEISA_LED_GREEN;
141	mace->perif.ctrl.misc = led;
142
143	_machine_restart = ip32_machine_restart;
144	_machine_halt = ip32_machine_halt;
145	pm_power_off = ip32_machine_halt;
146
147	timer_setup(&blink_timer, blink_timeout, 0);
148	atomic_notifier_chain_register(&panic_notifier_list, &panic_block);
149
150	return 0;
151}
152
153subsys_initcall(ip32_reboot_setup);