[PARISC] Convert soft power switch driver to kthread

And remove it's reference in time.c.
Allow lcd_print() to take a const char *.

Signed-off-by: Helge Deller <deller@gmx.de>
Signed-off-by: Kyle McMartin <kyle@parisc-linux.org>
This commit is contained in:
Helge Deller 2007-01-07 16:07:48 +01:00 committed by Kyle McMartin
parent 324c7e6545
commit 6e16d9409e
4 changed files with 88 additions and 115 deletions

View File

@ -148,10 +148,6 @@ irqreturn_t timer_interrupt(int irq, void *dev_id)
write_sequnlock(&xtime_lock); write_sequnlock(&xtime_lock);
} }
/* check soft power switch status */
if (cpu == 0 && !atomic_read(&power_tasklet.count))
tasklet_schedule(&power_tasklet);
return IRQ_HANDLED; return IRQ_HANDLED;
} }

View File

@ -631,7 +631,7 @@ void __init register_led_regions(void)
** avoid a race condition while writing the CMD/DATA register pair. ** avoid a race condition while writing the CMD/DATA register pair.
** **
*/ */
int lcd_print( char *str ) int lcd_print( const char *str )
{ {
int i; int i;

View File

@ -2,7 +2,7 @@
* linux/drivers/parisc/power.c * linux/drivers/parisc/power.c
* HP PARISC soft power switch support driver * HP PARISC soft power switch support driver
* *
* Copyright (c) 2001-2005 Helge Deller <deller@gmx.de> * Copyright (c) 2001-2007 Helge Deller <deller@gmx.de>
* All rights reserved. * All rights reserved.
* *
* *
@ -29,7 +29,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* *
* *
*
* HINT: * HINT:
* Support of the soft power switch button may be enabled or disabled at * Support of the soft power switch button may be enabled or disabled at
* runtime through the "/proc/sys/kernel/power" procfs entry. * runtime through the "/proc/sys/kernel/power" procfs entry.
@ -38,34 +37,28 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/string.h>
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/reboot.h> #include <linux/reboot.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/interrupt.h> #include <linux/kthread.h>
#include <linux/workqueue.h>
#include <asm/pdc.h> #include <asm/pdc.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/led.h> #include <asm/led.h>
#include <asm/uaccess.h>
#define DRIVER_NAME "powersw"
#define KTHREAD_NAME "kpowerswd"
#ifdef DEBUG /* how often should the power button be polled ? */
# define DPRINTK(x...) printk(x) #define POWERSWITCH_POLL_PER_SEC 2
#else
# define DPRINTK(x...)
#endif
/* filename in /proc which can be used to enable/disable the power switch */
#define SYSCTL_FILENAME "sys/kernel/power"
/* how long does the power button needs to be down until we react ? */
#define POWERSWITCH_DOWN_SEC 2
/* assembly code to access special registers */
/* taken from PCXL ERS page 82 */
#define DIAG_CODE(code) (0x14000000 + ((code)<<5)) #define DIAG_CODE(code) (0x14000000 + ((code)<<5))
/* this will go to processor.h or any other place... */
/* taken from PCXL ERS page 82 */
#define MFCPU_X(rDiagReg, t_ch, t_th, code) \ #define MFCPU_X(rDiagReg, t_ch, t_th, code) \
(DIAG_CODE(code) + ((rDiagReg)<<21) + ((t_ch)<<16) + ((t_th)<<0) ) (DIAG_CODE(code) + ((rDiagReg)<<21) + ((t_ch)<<16) + ((t_th)<<0) )
@ -76,111 +69,95 @@
#define __getDIAG(dr) ( { \ #define __getDIAG(dr) ( { \
register unsigned long __res asm("r28");\ register unsigned long __res asm("r28");\
__asm__ __volatile__ ( \ __asm__ __volatile__ ( \
".word %1\n nop\n" : "=&r" (__res) : "i" (MFCPU_T(dr,28)) \ ".word %1" : "=&r" (__res) : "i" (MFCPU_T(dr,28) ) \
); \ ); \
__res; \ __res; \
} ) } )
/* local shutdown counter */
static void deferred_poweroff(struct work_struct *unused)
{
if (kill_cad_pid(SIGINT, 1)) {
/* just in case killing init process failed */
machine_power_off();
}
}
/*
* This function gets called from interrupt context.
* As it's called within an interrupt, it wouldn't sync if we don't
* use schedule_work().
*/
static DECLARE_WORK(poweroff_work, deferred_poweroff);
static void poweroff(void)
{
static int powering_off __read_mostly;
if (powering_off)
return;
powering_off++;
schedule_work(&poweroff_work);
}
/* local time-counter for shutdown */
static int shutdown_timer __read_mostly; static int shutdown_timer __read_mostly;
/* check, give feedback and start shutdown after one second */ /* check, give feedback and start shutdown after one second */
static void process_shutdown(void) static void process_shutdown(void)
{ {
if (shutdown_timer == 0) if (shutdown_timer == 0)
DPRINTK(KERN_INFO "Shutdown requested...\n"); printk(KERN_ALERT KTHREAD_NAME ": Shutdown requested...\n");
shutdown_timer++; shutdown_timer++;
/* wait until the button was pressed for 1 second */ /* wait until the button was pressed for 1 second */
if (shutdown_timer == HZ) { if (shutdown_timer == (POWERSWITCH_DOWN_SEC*POWERSWITCH_POLL_PER_SEC)) {
#if defined (DEBUG) || defined(CONFIG_CHASSIS_LCD_LED) static const char msg[] = "Shutting down...";
static char msg[] = "Shutting down..."; printk(KERN_INFO KTHREAD_NAME ": %s\n", msg);
#endif
DPRINTK(KERN_INFO "%s\n", msg);
lcd_print(msg); lcd_print(msg);
poweroff();
/* send kill signal */
if (kill_cad_pid(SIGINT, 1)) {
/* just in case killing init process failed */
if (pm_power_off)
pm_power_off();
}
} }
} }
/* main power switch tasklet struct (scheduled from time.c) */ /* main power switch task struct */
DECLARE_TASKLET_DISABLED(power_tasklet, NULL, 0); static struct task_struct *power_task;
/* filename in /proc which can be used to enable/disable the power switch */
#define SYSCTL_FILENAME "sys/kernel/power"
/* soft power switch enabled/disabled */ /* soft power switch enabled/disabled */
int pwrsw_enabled __read_mostly = 1; int pwrsw_enabled __read_mostly = 1;
/* /* main kernel thread worker. It polls the button state */
* On gecko style machines (e.g. 712/xx and 715/xx) static int kpowerswd(void *param)
* the power switch status is stored in Bit 0 ("the highest bit")
* of CPU diagnose register 25.
*
*/
static void gecko_tasklet_func(unsigned long unused)
{ {
if (unlikely(!pwrsw_enabled)) __set_current_state(TASK_RUNNING);
return;
if (__getDIAG(25) & 0x80000000) { do {
/* power switch button not pressed or released again */ int button_not_pressed;
/* Warning: Some machines do never reset this DIAG flag! */ unsigned long soft_power_reg = (unsigned long) param;
shutdown_timer = 0;
} else { schedule_timeout_interruptible(pwrsw_enabled ? HZ : HZ/POWERSWITCH_POLL_PER_SEC);
process_shutdown(); __set_current_state(TASK_RUNNING);
}
} if (unlikely(!pwrsw_enabled))
continue;
if (soft_power_reg) {
/*
* Non-Gecko-style machines:
* Check the power switch status which is read from the
* real I/O location at soft_power_reg.
* Bit 31 ("the lowest bit) is the status of the power switch.
* This bit is "1" if the button is NOT pressed.
*/
button_not_pressed = (gsc_readl(soft_power_reg) & 0x1);
} else {
/*
* On gecko style machines (e.g. 712/xx and 715/xx)
* the power switch status is stored in Bit 0 ("the highest bit")
* of CPU diagnose register 25.
* Warning: Some machines never reset the DIAG flag, even if
* the button has been released again.
*/
button_not_pressed = (__getDIAG(25) & 0x80000000);
}
if (likely(button_not_pressed)) {
if (unlikely(shutdown_timer && /* avoid writing if not necessary */
shutdown_timer < (POWERSWITCH_DOWN_SEC*POWERSWITCH_POLL_PER_SEC))) {
shutdown_timer = 0;
printk(KERN_INFO KTHREAD_NAME ": Shutdown request aborted.\n");
}
} else
process_shutdown();
} while (!kthread_should_stop());
/* return 0;
* Check the power switch status which is read from the
* real I/O location at soft_power_reg.
* Bit 31 ("the lowest bit) is the status of the power switch.
*/
static void polling_tasklet_func(unsigned long soft_power_reg)
{
unsigned long current_status;
if (unlikely(!pwrsw_enabled))
return;
current_status = gsc_readl(soft_power_reg);
if (current_status & 0x1) {
/* power switch button not pressed */
shutdown_timer = 0;
} else {
process_shutdown();
}
} }
@ -220,7 +197,7 @@ static struct notifier_block parisc_panic_block = {
static int __init power_init(void) static int __init power_init(void)
{ {
unsigned long ret; unsigned long ret;
unsigned long soft_power_reg = 0; unsigned long soft_power_reg;
#if 0 #if 0
request_irq( IRQ_FROM_REGION(CPU_IRQ_REGION)+2, &powerfail_interrupt, request_irq( IRQ_FROM_REGION(CPU_IRQ_REGION)+2, &powerfail_interrupt,
@ -235,44 +212,44 @@ static int __init power_init(void)
soft_power_reg = -1UL; soft_power_reg = -1UL;
switch (soft_power_reg) { switch (soft_power_reg) {
case 0: printk(KERN_INFO "Gecko-style soft power switch enabled.\n"); case 0: printk(KERN_INFO DRIVER_NAME ": Gecko-style soft power switch enabled.\n");
power_tasklet.func = gecko_tasklet_func;
break; break;
case -1UL: printk(KERN_INFO "Soft power switch support not available.\n"); case -1UL: printk(KERN_INFO DRIVER_NAME ": Soft power switch support not available.\n");
return -ENODEV; return -ENODEV;
default: printk(KERN_INFO "Soft power switch enabled, polling @ 0x%08lx.\n", default: printk(KERN_INFO DRIVER_NAME ": Soft power switch at 0x%08lx enabled.\n",
soft_power_reg); soft_power_reg);
power_tasklet.data = soft_power_reg; }
power_tasklet.func = polling_tasklet_func;
power_task = kthread_run(kpowerswd, (void*)soft_power_reg, KTHREAD_NAME);
if (IS_ERR(power_task)) {
printk(KERN_ERR DRIVER_NAME ": thread creation failed. Driver not loaded.\n");
pdc_soft_power_button(0);
return -EIO;
} }
/* Register a call for panic conditions. */ /* Register a call for panic conditions. */
atomic_notifier_chain_register(&panic_notifier_list, atomic_notifier_chain_register(&panic_notifier_list,
&parisc_panic_block); &parisc_panic_block);
tasklet_enable(&power_tasklet);
return 0; return 0;
} }
static void __exit power_exit(void) static void __exit power_exit(void)
{ {
if (!power_tasklet.func) kthread_stop(power_task);
return;
tasklet_disable(&power_tasklet);
atomic_notifier_chain_unregister(&panic_notifier_list, atomic_notifier_chain_unregister(&panic_notifier_list,
&parisc_panic_block); &parisc_panic_block);
power_tasklet.func = NULL;
pdc_soft_power_button(0); pdc_soft_power_button(0);
} }
module_init(power_init); arch_initcall(power_init);
module_exit(power_exit); module_exit(power_exit);
MODULE_AUTHOR("Helge Deller"); MODULE_AUTHOR("Helge Deller <deller@gmx.de>");
MODULE_DESCRIPTION("Soft power switch driver"); MODULE_DESCRIPTION("Soft power switch driver");
MODULE_LICENSE("Dual BSD/GPL"); MODULE_LICENSE("Dual BSD/GPL");

View File

@ -31,7 +31,7 @@ void __init register_led_regions(void);
#ifdef CONFIG_CHASSIS_LCD_LED #ifdef CONFIG_CHASSIS_LCD_LED
/* writes a string to the LCD display (if possible on this h/w) */ /* writes a string to the LCD display (if possible on this h/w) */
int lcd_print(char *str); int lcd_print(const char *str);
#else #else
#define lcd_print(str) #define lcd_print(str)
#endif #endif