This repository has been archived on 2025-06-06. You can view files and clone it, but cannot push or open issues or pull requests.
Files
android-g900/kernel-2.6.33/arch/arm/mach-pxa/g900/input/g900_pwr_btn.c
2011-04-04 23:17:39 +06:00

130 lines
2.6 KiB
C
Executable File

/*
* Buttons support for Toshiba G900. GPIO buttons
* based on:
* Xiao Huang g900_button.c
*/
#include <linux/input.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/platform_device.h>
#include <linux/gpio_keys.h>
#include <asm/mach-types.h>
#include <mach/hardware.h>
#include <mach/pxa2xx-regs.h>
#include <mach/g900-gpio.h>
#include <mach/gpio.h>
#include <mach/regs-ost.h>
#include <mach/reset.h>
#define BTN_POWER GPIO3_BTN_nPower
static unsigned int noreset;
module_param(noreset, uint, 0);
MODULE_PARM_DESC(noreset, "Set 0 = reset, any = no action)"); /* TODO add pm suspend action */
static void cpu_hw_reset(void)
{
/* Initialize the watchdog and let it fire */
OWER = OWER_WME;
OSSR = OSSR_M3;
OSMR3 = OSCR + 368640; /* ... in 100 ms */
}
static irqreturn_t pwr_btn_irq(int irq, void *dev_id)
{
int state;
state = GET_GPIO(BTN_POWER);
if(state){
printk("g900-power-button: unpress");
}else{
if(noreset == 0 )
{
cpu_hw_reset();
}
}
printk("g900-power-button: state=%d\n", state);
return IRQ_HANDLED;
}
static int buttons_probe(struct platform_device *pdev)
{
int err;
int irqflag = IRQF_SAMPLE_RANDOM;
#ifdef CONFIG_PREEMPT_RT
irqflag |= IRQF_NODELAY;
#endif
if (!machine_is_g900())
return -ENODEV;
//assign irq and keybit
set_irq_type(IRQ_GPIO(BTN_POWER), IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING);
err = request_irq(IRQ_GPIO(BTN_POWER), pwr_btn_irq, irqflag, "g900-gpio-buttons", NULL);
if (err)
{
printk(KERN_ERR "g900-power-button: Cannot assign GPIO(%d) IRQ\n", BTN_POWER);
return err;
}
printk("g900-power-button: *****IRQ %d OK****", IRQ_GPIO(BTN_POWER));
return 0;
}
static int buttons_remove(struct platform_device *pdev)
{
free_irq(IRQ_GPIO(BTN_POWER), NULL);
return 0;
}
static int buttons_suspend(struct platform_device *pdev, pm_message_t state)
{
return 0;
}
static int buttons_resume(struct platform_device *pdev)
{
return 0;
}
static struct platform_driver buttons_driver = {
.driver = {
.name = "g900-power-button",
},
.probe = buttons_probe,
.remove = buttons_remove,
#ifdef CONFIG_PM
.suspend = buttons_suspend,
.resume = buttons_resume,
#endif
};
static int __init buttons_init(void)
{
return platform_driver_register(&buttons_driver);
}
static void __exit buttons_exit(void)
{
platform_driver_unregister(&buttons_driver);
}
module_init(buttons_init);
module_exit(buttons_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Angell FEar<angell@angellfear.ru>");
MODULE_DESCRIPTION("Power Button driver for Toshiba G900");