196 lines
4.5 KiB
C
Executable File
196 lines
4.5 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>
|
|
|
|
|
|
|
|
#ifdef CONFIG_SWITCH_GPIO
|
|
|
|
#include <linux/switch.h>
|
|
#include "../generic.h"
|
|
/*
|
|
static struct gpio_switch_platform_data headset_switch_data = {
|
|
.name = "h2w",
|
|
.gpio = GPIO51_BTN_nJackInsert,
|
|
};
|
|
|
|
static struct platform_device headset_switch_device = {
|
|
.name = "switch-gpio",
|
|
.dev = {
|
|
.platform_data = &headset_switch_data,
|
|
}
|
|
};
|
|
*/
|
|
static struct gpio_switch_platform_data kbr_switch_data = {
|
|
.name = "kbr",
|
|
.gpio = GPIO9_BTN_nKBOpen,
|
|
};
|
|
|
|
static struct platform_device kbr_switch_device = {
|
|
.name = "switch-gpio",
|
|
.dev = {
|
|
.platform_data = &kbr_switch_data,
|
|
}
|
|
};
|
|
static struct platform_device *switch_device[] __initdata = {
|
|
//&headset_switch_device,
|
|
&kbr_switch_device,
|
|
};
|
|
|
|
#endif
|
|
|
|
static struct gpio_keys_button gpio_buttons[] = {
|
|
#ifndef CONFIG_G900_POWER_BUTTON
|
|
{KEY_POWER, GPIO3_BTN_nPower, 0, "Power button"},
|
|
#endif
|
|
|
|
#ifndef CONFIG_SWITCH_GPIO
|
|
{99 , GPIO9_BTN_nKBOpen, 0, "Keyboard open"},
|
|
{SW_HEADPHONE_INSERT, GPIO51_BTN_nJackInsert, 0, "HeadPhone insert"},
|
|
#endif
|
|
{KEY_PLAY, GPIO10_BTN_nHeadSet, 0, "HeadSet button"},
|
|
};
|
|
|
|
static struct input_dev *input_dev = NULL;
|
|
|
|
static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
|
|
{
|
|
int i, state;
|
|
int gpiovalue;
|
|
for (i = 0; i < ARRAY_SIZE(gpio_buttons); i++)
|
|
{
|
|
if (IRQ_GPIO(gpio_buttons[i].gpio) == irq)
|
|
{
|
|
gpiovalue = GET_GPIO(gpio_buttons[i].gpio);
|
|
//printk("gpio=%d, active_low=%d\n", gpiovalue, gpio_buttons[i].active_low );
|
|
|
|
state = (gpiovalue ? 1 : 0) ^ (gpio_buttons[i].active_low);
|
|
/*state = (gpio_buttons[i].active_low ? !state : state);*/
|
|
input_report_key(input_dev, gpio_buttons[i].code, state);
|
|
input_sync(input_dev);
|
|
//printk("code=%d, state=%d\n", gpio_buttons[i].code, state);
|
|
}
|
|
}
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
|
|
static int buttons_probe(struct platform_device *pdev)
|
|
{
|
|
int i, err;
|
|
int irqflag = IRQF_SAMPLE_RANDOM;
|
|
#ifdef CONFIG_PREEMPT_RT
|
|
irqflag |= IRQF_NODELAY;
|
|
#endif
|
|
|
|
if (!machine_is_g900())
|
|
return -ENODEV;
|
|
|
|
|
|
#ifdef CONFIG_SWITCH_GPIO
|
|
err=platform_add_devices(ARRAY_AND_SIZE(switch_device));
|
|
|
|
#endif
|
|
|
|
if (!(input_dev = input_allocate_device())) return -ENOMEM;
|
|
|
|
input_dev->name = "g900_buttons";
|
|
set_bit(EV_KEY, input_dev->evbit);
|
|
|
|
for (i = 0; i < ARRAY_SIZE(gpio_buttons); i++)
|
|
{
|
|
set_bit(gpio_buttons[i].code, input_dev->keybit);
|
|
}
|
|
err=input_register_device(input_dev);
|
|
if (err) {
|
|
printk(KERN_ERR "Could not input_register_device \n");
|
|
return err;
|
|
}
|
|
|
|
for (i = 0; i < ARRAY_SIZE(gpio_buttons); i++)
|
|
{
|
|
//assign irq and keybit
|
|
set_irq_type(IRQ_GPIO(gpio_buttons[i].gpio), IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING);
|
|
err = request_irq(IRQ_GPIO(gpio_buttons[i].gpio), gpio_irq_handler, irqflag, "g900-gpio-buttons", NULL);
|
|
if (err)
|
|
{
|
|
printk(KERN_ERR "%s: Cannot assign GPIO(%d) IRQ\n", __FUNCTION__, gpio_buttons[i].gpio);
|
|
return err;
|
|
}
|
|
//printk("*****IRQ %d OK****", IRQ_GPIO(gpio_buttons[i].gpio));
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int buttons_remove(struct platform_device *pdev)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(gpio_buttons); i++)
|
|
{
|
|
free_irq(IRQ_GPIO(gpio_buttons[i].gpio), NULL);
|
|
}
|
|
|
|
input_unregister_device(input_dev);
|
|
input_free_device(input_dev);
|
|
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-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("El Tuba<tuba.linux@gmail.com>");
|
|
MODULE_DESCRIPTION("Buttons driver for Toshiba G900");
|