Commit 409e1544 authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: q40kbd - convert driver to the split model

Convert the driver to standard spilt model arch-specific code registers
platform device to which driver code can bind later.

Also request IRQ immediately upon binding to the device instead of doing
this when serio port is being opened.
Acked-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent 3e8040b0
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/vt_kern.h> #include <linux/vt_kern.h>
#include <linux/bcd.h> #include <linux/bcd.h>
#include <linux/platform_device.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/rtc.h> #include <asm/rtc.h>
...@@ -329,3 +330,15 @@ static int q40_set_rtc_pll(struct rtc_pll_info *pll) ...@@ -329,3 +330,15 @@ static int q40_set_rtc_pll(struct rtc_pll_info *pll)
} else } else
return -EINVAL; return -EINVAL;
} }
static __init int q40_add_kbd_device(void)
{
struct platform_device *pdev;
pdev = platform_device_register_simple("q40kbd", -1, NULL, 0);
if (IS_ERR(pdev))
return PTR_ERR(pdev);
return 0;
}
arch_initcall(q40_add_kbd_device);
...@@ -44,26 +44,31 @@ ...@@ -44,26 +44,31 @@
#include <asm/irq.h> #include <asm/irq.h>
#include <asm/q40ints.h> #include <asm/q40ints.h>
#define DRV_NAME "q40kbd"
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
MODULE_DESCRIPTION("Q40 PS/2 keyboard controller driver"); MODULE_DESCRIPTION("Q40 PS/2 keyboard controller driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:" DRV_NAME);
static DEFINE_SPINLOCK(q40kbd_lock); struct q40kbd {
static struct serio *q40kbd_port; struct serio *port;
static struct platform_device *q40kbd_device; spinlock_t lock;
};
static irqreturn_t q40kbd_interrupt(int irq, void *dev_id) static irqreturn_t q40kbd_interrupt(int irq, void *dev_id)
{ {
struct q40kbd *q40kbd = dev_id;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&q40kbd_lock, flags); spin_lock_irqsave(&q40kbd->lock, flags);
if (Q40_IRQ_KEYB_MASK & master_inb(INTERRUPT_REG)) if (Q40_IRQ_KEYB_MASK & master_inb(INTERRUPT_REG))
serio_interrupt(q40kbd_port, master_inb(KEYCODE_REG), 0); serio_interrupt(q40kbd->port, master_inb(KEYCODE_REG), 0);
master_outb(-1, KEYBOARD_UNLOCK_REG); master_outb(-1, KEYBOARD_UNLOCK_REG);
spin_unlock_irqrestore(&q40kbd_lock, flags); spin_unlock_irqrestore(&q40kbd->lock, flags);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -72,17 +77,23 @@ static irqreturn_t q40kbd_interrupt(int irq, void *dev_id) ...@@ -72,17 +77,23 @@ static irqreturn_t q40kbd_interrupt(int irq, void *dev_id)
* q40kbd_flush() flushes all data that may be in the keyboard buffers * q40kbd_flush() flushes all data that may be in the keyboard buffers
*/ */
static void q40kbd_flush(void) static void q40kbd_flush(struct q40kbd *q40kbd)
{ {
int maxread = 100; int maxread = 100;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&q40kbd_lock, flags); spin_lock_irqsave(&q40kbd->lock, flags);
while (maxread-- && (Q40_IRQ_KEYB_MASK & master_inb(INTERRUPT_REG))) while (maxread-- && (Q40_IRQ_KEYB_MASK & master_inb(INTERRUPT_REG)))
master_inb(KEYCODE_REG); master_inb(KEYCODE_REG);
spin_unlock_irqrestore(&q40kbd_lock, flags); spin_unlock_irqrestore(&q40kbd->lock, flags);
}
static void q40kbd_stop(void)
{
master_outb(0, KEY_IRQ_ENABLE_REG);
master_outb(-1, KEYBOARD_UNLOCK_REG);
} }
/* /*
...@@ -92,12 +103,9 @@ static void q40kbd_flush(void) ...@@ -92,12 +103,9 @@ static void q40kbd_flush(void)
static int q40kbd_open(struct serio *port) static int q40kbd_open(struct serio *port)
{ {
q40kbd_flush(); struct q40kbd *q40kbd = port->port_data;
if (request_irq(Q40_IRQ_KEYBOARD, q40kbd_interrupt, 0, "q40kbd", NULL)) { q40kbd_flush(q40kbd);
printk(KERN_ERR "q40kbd.c: Can't get irq %d.\n", Q40_IRQ_KEYBOARD);
return -EBUSY;
}
/* off we go */ /* off we go */
master_outb(-1, KEYBOARD_UNLOCK_REG); master_outb(-1, KEYBOARD_UNLOCK_REG);
...@@ -108,36 +116,72 @@ static int q40kbd_open(struct serio *port) ...@@ -108,36 +116,72 @@ static int q40kbd_open(struct serio *port)
static void q40kbd_close(struct serio *port) static void q40kbd_close(struct serio *port)
{ {
master_outb(0, KEY_IRQ_ENABLE_REG); struct q40kbd *q40kbd = port->port_data;
master_outb(-1, KEYBOARD_UNLOCK_REG);
free_irq(Q40_IRQ_KEYBOARD, NULL);
q40kbd_flush(); q40kbd_stop();
q40kbd_flush(q40kbd);
} }
static int __devinit q40kbd_probe(struct platform_device *dev) static int __devinit q40kbd_probe(struct platform_device *pdev)
{ {
q40kbd_port = kzalloc(sizeof(struct serio), GFP_KERNEL); struct q40kbd *q40kbd;
if (!q40kbd_port) struct serio *port;
return -ENOMEM; int error;
q40kbd_port->id.type = SERIO_8042; q40kbd = kzalloc(sizeof(struct q40kbd), GFP_KERNEL);
q40kbd_port->open = q40kbd_open; port = kzalloc(sizeof(struct serio), GFP_KERNEL);
q40kbd_port->close = q40kbd_close; if (!q40kbd || !port) {
q40kbd_port->dev.parent = &dev->dev; error = -ENOMEM;
strlcpy(q40kbd_port->name, "Q40 Kbd Port", sizeof(q40kbd_port->name)); goto err_free_mem;
strlcpy(q40kbd_port->phys, "Q40", sizeof(q40kbd_port->phys)); }
serio_register_port(q40kbd_port); q40kbd->port = port;
spin_lock_init(&q40kbd->lock);
port->id.type = SERIO_8042;
port->open = q40kbd_open;
port->close = q40kbd_close;
port->port_data = q40kbd;
port->dev.parent = &pdev->dev;
strlcpy(port->name, "Q40 Kbd Port", sizeof(port->name));
strlcpy(port->phys, "Q40", sizeof(port->phys));
q40kbd_stop();
error = request_irq(Q40_IRQ_KEYBOARD, q40kbd_interrupt, 0,
DRV_NAME, q40kbd);
if (error) {
dev_err(&pdev->dev, "Can't get irq %d.\n", Q40_IRQ_KEYBOARD);
goto err_free_mem;
}
serio_register_port(q40kbd->port);
platform_set_drvdata(pdev, q40kbd);
printk(KERN_INFO "serio: Q40 kbd registered\n"); printk(KERN_INFO "serio: Q40 kbd registered\n");
return 0; return 0;
err_free_mem:
kfree(port);
kfree(q40kbd);
return error;
} }
static int __devexit q40kbd_remove(struct platform_device *dev) static int __devexit q40kbd_remove(struct platform_device *pdev)
{ {
serio_unregister_port(q40kbd_port); struct q40kbd *q40kbd = platform_get_drvdata(pdev);
/*
* q40kbd_close() will be called as part of unregistering
* and will ensure that IRQ is turned off, so it is safe
* to unregister port first and free IRQ later.
*/
serio_unregister_port(q40kbd->port);
free_irq(Q40_IRQ_KEYBOARD, q40kbd);
kfree(q40kbd);
platform_set_drvdata(pdev, NULL);
return 0; return 0;
} }
...@@ -146,41 +190,16 @@ static struct platform_driver q40kbd_driver = { ...@@ -146,41 +190,16 @@ static struct platform_driver q40kbd_driver = {
.name = "q40kbd", .name = "q40kbd",
.owner = THIS_MODULE, .owner = THIS_MODULE,
}, },
.probe = q40kbd_probe,
.remove = __devexit_p(q40kbd_remove), .remove = __devexit_p(q40kbd_remove),
}; };
static int __init q40kbd_init(void) static int __init q40kbd_init(void)
{ {
int error; return platform_driver_probe(&q40kbd_driver, q40kbd_probe);
if (!MACH_IS_Q40)
return -ENODEV;
error = platform_driver_register(&q40kbd_driver);
if (error)
return error;
q40kbd_device = platform_device_alloc("q40kbd", -1);
if (!q40kbd_device)
goto err_unregister_driver;
error = platform_device_add(q40kbd_device);
if (error)
goto err_free_device;
return 0;
err_free_device:
platform_device_put(q40kbd_device);
err_unregister_driver:
platform_driver_unregister(&q40kbd_driver);
return error;
} }
static void __exit q40kbd_exit(void) static void __exit q40kbd_exit(void)
{ {
platform_device_unregister(q40kbd_device);
platform_driver_unregister(&q40kbd_driver); platform_driver_unregister(&q40kbd_driver);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment