2 * OpenCores Keyboard Controller Driver
3 * http://www.opencores.org/project,keyboardcontroller
5 * Copyright 2007-2009 HV Sistemas S.L.
7 * Licensed under the GPL-2 or later.
10 #include <linux/input.h>
11 #include <linux/interrupt.h>
13 #include <linux/ioport.h>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/platform_device.h>
17 #include <linux/slab.h>
19 struct opencores_kbd
{
20 struct input_dev
*input
;
23 unsigned short keycodes
[128];
26 static irqreturn_t
opencores_kbd_isr(int irq
, void *dev_id
)
28 struct opencores_kbd
*opencores_kbd
= dev_id
;
29 struct input_dev
*input
= opencores_kbd
->input
;
32 c
= readb(opencores_kbd
->addr
);
33 input_report_key(input
, c
& 0x7f, c
& 0x80 ? 0 : 1);
39 static int opencores_kbd_probe(struct platform_device
*pdev
)
41 struct input_dev
*input
;
42 struct opencores_kbd
*opencores_kbd
;
46 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
48 dev_err(&pdev
->dev
, "missing board memory resource\n");
52 irq
= platform_get_irq(pdev
, 0);
54 dev_err(&pdev
->dev
, "missing board IRQ resource\n");
58 opencores_kbd
= devm_kzalloc(&pdev
->dev
, sizeof(*opencores_kbd
),
63 input
= devm_input_allocate_device(&pdev
->dev
);
65 dev_err(&pdev
->dev
, "failed to allocate input device\n");
69 opencores_kbd
->input
= input
;
71 opencores_kbd
->addr
= devm_ioremap_resource(&pdev
->dev
, res
);
72 if (IS_ERR(opencores_kbd
->addr
))
73 return PTR_ERR(opencores_kbd
->addr
);
75 input
->name
= pdev
->name
;
76 input
->phys
= "opencores-kbd/input0";
78 input_set_drvdata(input
, opencores_kbd
);
80 input
->id
.bustype
= BUS_HOST
;
81 input
->id
.vendor
= 0x0001;
82 input
->id
.product
= 0x0001;
83 input
->id
.version
= 0x0100;
85 input
->keycode
= opencores_kbd
->keycodes
;
86 input
->keycodesize
= sizeof(opencores_kbd
->keycodes
[0]);
87 input
->keycodemax
= ARRAY_SIZE(opencores_kbd
->keycodes
);
89 __set_bit(EV_KEY
, input
->evbit
);
91 for (i
= 0; i
< ARRAY_SIZE(opencores_kbd
->keycodes
); i
++) {
93 * OpenCores controller happens to have scancodes match
94 * our KEY_* definitions.
96 opencores_kbd
->keycodes
[i
] = i
;
97 __set_bit(opencores_kbd
->keycodes
[i
], input
->keybit
);
99 __clear_bit(KEY_RESERVED
, input
->keybit
);
101 error
= devm_request_irq(&pdev
->dev
, irq
, &opencores_kbd_isr
,
103 pdev
->name
, opencores_kbd
);
105 dev_err(&pdev
->dev
, "unable to claim irq %d\n", irq
);
109 error
= input_register_device(input
);
111 dev_err(&pdev
->dev
, "unable to register input device\n");
115 platform_set_drvdata(pdev
, opencores_kbd
);
120 static struct platform_driver opencores_kbd_device_driver
= {
121 .probe
= opencores_kbd_probe
,
123 .name
= "opencores-kbd",
126 module_platform_driver(opencores_kbd_device_driver
);
128 MODULE_LICENSE("GPL");
129 MODULE_AUTHOR("Javier Herrero <jherrero@hvsistemas.es>");
130 MODULE_DESCRIPTION("Keyboard driver for OpenCores Keyboard Controller");