14 #include <linux/errno.h>
17 #include <linux/input.h>
20 #include <linux/kernel.h>
21 #include <linux/module.h>
25 #include <linux/slab.h>
26 #include <linux/types.h>
30 #define MODE_CTL_REG 0x00
31 #define STATUS_REG 0x0C
33 #define INTR_MASK 0x54
38 #define MODE_CTL_PCLK_FREQ_SHIFT 9
39 #define MODE_CTL_PCLK_FREQ_MSK 0x7F
41 #define MODE_CTL_KEYBOARD (0x2 << 0)
42 #define MODE_CTL_SCAN_RATE_10 (0x0 << 2)
43 #define MODE_CTL_SCAN_RATE_20 (0x1 << 2)
44 #define MODE_CTL_SCAN_RATE_40 (0x2 << 2)
45 #define MODE_CTL_SCAN_RATE_80 (0x3 << 2)
46 #define MODE_CTL_KEYNUM_SHIFT 6
47 #define MODE_CTL_START_SCAN (0x1 << 8)
49 #define STATUS_DATA_AVAIL (0x1 << 1)
51 #define DATA_ROW_MASK 0xF0
52 #define DATA_COLUMN_MASK 0x0F
82 input_report_key(input, kbd->
last_key, 0);
92 input_report_key(input, key, 1);
103 static int spear_kbd_open(
struct input_dev *
dev)
105 struct spear_kbd *kbd = input_get_drvdata(dev);
133 static void spear_kbd_close(
struct input_dev *dev)
135 struct spear_kbd *kbd = input_get_drvdata(dev);
161 if (of_property_read_bool(np,
"autorepeat"))
164 if (of_property_read_u32(np,
"suspended_rate", &suspended_rate))
167 error = of_property_read_u32(np,
"st,mode", &val);
169 dev_err(&pdev->
dev,
"DT: Invalid or missing mode\n");
189 struct input_dev *input_dev;
196 dev_err(&pdev->
dev,
"no keyboard resource defined\n");
202 dev_err(&pdev->
dev,
"not able to get irq for the device\n");
207 input_dev = input_allocate_device();
208 if (!kbd || !input_dev) {
214 kbd->
input = input_dev;
218 error = spear_kbd_parse_dt(pdev, kbd);
230 dev_err(&pdev->
dev,
"keyboard region already claimed\n");
237 dev_err(&pdev->
dev,
"ioremap failed for kbd_region\n");
239 goto err_release_mem_region;
243 if (IS_ERR(kbd->
clk)) {
244 error = PTR_ERR(kbd->
clk);
248 input_dev->name =
"Spear Keyboard";
249 input_dev->phys =
"keyboard/input0";
250 input_dev->dev.parent = &pdev->
dev;
252 input_dev->id.vendor = 0x0001;
253 input_dev->id.product = 0x0001;
254 input_dev->id.version = 0x0100;
255 input_dev->open = spear_kbd_open;
256 input_dev->close = spear_kbd_close;
261 dev_err(&pdev->
dev,
"Failed to build keymap\n");
269 input_set_drvdata(input_dev, kbd);
271 error =
request_irq(irq, spear_kbd_interrupt, 0,
"keyboard", kbd);
277 error = input_register_device(input_dev);
279 dev_err(&pdev->
dev,
"Unable to register keyboard device\n");
284 platform_set_drvdata(pdev, kbd);
294 err_release_mem_region:
297 input_free_device(input_dev);
305 struct spear_kbd *kbd = platform_get_drvdata(pdev);
308 input_unregister_device(kbd->
input);
315 platform_set_drvdata(pdev,
NULL);
321 static int spear_kbd_suspend(
struct device *dev)
324 struct spear_kbd *kbd = platform_get_drvdata(pdev);
325 struct input_dev *input_dev = kbd->
input;
326 unsigned int rate = 0, mode_ctl_reg,
val;
335 if (device_may_wakeup(&pdev->
dev)) {
336 enable_irq_wake(kbd->
irq);
354 if (input_dev->users) {
362 if (input_dev->users)
373 static int spear_kbd_resume(
struct device *dev)
376 struct spear_kbd *kbd = platform_get_drvdata(pdev);
377 struct input_dev *input_dev = kbd->
input;
381 if (device_may_wakeup(&pdev->
dev)) {
382 disable_irq_wake(kbd->
irq);
384 if (input_dev->users)
389 if (input_dev->users)
401 static const struct of_device_id spear_kbd_id_table[] = {
409 .probe = spear_kbd_probe,
414 .pm = &spear_kbd_pm_ops,