Kristoffer Ericson | b0a4e1a | 2007-09-26 00:02:49 -0400 | [diff] [blame] | 1 | /* |
| 2 | * drivers/input/keyboard/jornada720_kbd.c |
| 3 | * |
| 4 | * HP Jornada 720 keyboard platform driver |
| 5 | * |
| 6 | * Copyright (C) 2006/2007 Kristoffer Ericson <Kristoffer.Ericson@Gmail.com> |
| 7 | * |
| 8 | * Copyright (C) 2006 jornada 720 kbd driver by |
| 9 | Filip Zyzniewsk <Filip.Zyzniewski@tefnet.plX |
| 10 | * based on (C) 2004 jornada 720 kbd driver by |
| 11 | Alex Lange <chicken@handhelds.org> |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License version 2 as |
| 15 | * published by the Free Software Foundation. |
| 16 | * |
| 17 | */ |
| 18 | #include <linux/device.h> |
| 19 | #include <linux/errno.h> |
Kristoffer Ericson | b0a4e1a | 2007-09-26 00:02:49 -0400 | [diff] [blame] | 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/input.h> |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/platform_device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Kristoffer Ericson | b0a4e1a | 2007-09-26 00:02:49 -0400 | [diff] [blame] | 27 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 28 | #include <mach/jornada720.h> |
| 29 | #include <mach/hardware.h> |
Rob Herring | 3638dd2 | 2012-02-23 14:28:36 +0100 | [diff] [blame] | 30 | #include <mach/irqs.h> |
Kristoffer Ericson | b0a4e1a | 2007-09-26 00:02:49 -0400 | [diff] [blame] | 31 | |
| 32 | MODULE_AUTHOR("Kristoffer Ericson <Kristoffer.Ericson@gmail.com>"); |
| 33 | MODULE_DESCRIPTION("HP Jornada 710/720/728 keyboard driver"); |
Al Viro | 839cd31 | 2008-05-21 06:32:11 +0100 | [diff] [blame] | 34 | MODULE_LICENSE("GPL v2"); |
Kristoffer Ericson | b0a4e1a | 2007-09-26 00:02:49 -0400 | [diff] [blame] | 35 | |
| 36 | static unsigned short jornada_std_keymap[128] = { /* ROW */ |
| 37 | 0, KEY_ESC, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, /* #1 */ |
| 38 | KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_VOLUMEUP, KEY_VOLUMEDOWN, KEY_MUTE, /* -> */ |
| 39 | 0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, /* #2 */ |
| 40 | KEY_0, KEY_MINUS, KEY_EQUAL,0, 0, 0, /* -> */ |
| 41 | 0, KEY_Q, KEY_W, KEY_E, KEY_R, KEY_T, KEY_Y, KEY_U, KEY_I, KEY_O, /* #3 */ |
| 42 | KEY_P, KEY_BACKSLASH, KEY_BACKSPACE, 0, 0, 0, /* -> */ |
| 43 | 0, KEY_A, KEY_S, KEY_D, KEY_F, KEY_G, KEY_H, KEY_J, KEY_K, KEY_L, /* #4 */ |
| 44 | KEY_SEMICOLON, KEY_LEFTBRACE, KEY_RIGHTBRACE, 0, 0, 0, /* -> */ |
| 45 | 0, KEY_Z, KEY_X, KEY_C, KEY_V, KEY_B, KEY_N, KEY_M, KEY_COMMA, /* #5 */ |
| 46 | KEY_DOT, KEY_KPMINUS, KEY_APOSTROPHE, KEY_ENTER, 0, 0,0, /* -> */ |
| 47 | 0, KEY_TAB, 0, KEY_LEFTSHIFT, 0, KEY_APOSTROPHE, 0, 0, 0, 0, /* #6 */ |
| 48 | KEY_UP, 0, KEY_RIGHTSHIFT, 0, 0, 0,0, 0, 0, 0, 0, KEY_LEFTALT, KEY_GRAVE, /* -> */ |
| 49 | 0, 0, KEY_LEFT, KEY_DOWN, KEY_RIGHT, 0, 0, 0, 0,0, KEY_KPASTERISK, /* -> */ |
| 50 | KEY_LEFTCTRL, 0, KEY_SPACE, 0, 0, 0, KEY_SLASH, KEY_DELETE, 0, 0, /* -> */ |
| 51 | 0, 0, 0, KEY_POWER, /* -> */ |
| 52 | }; |
| 53 | |
| 54 | struct jornadakbd { |
| 55 | unsigned short keymap[ARRAY_SIZE(jornada_std_keymap)]; |
| 56 | struct input_dev *input; |
| 57 | }; |
| 58 | |
| 59 | static irqreturn_t jornada720_kbd_interrupt(int irq, void *dev_id) |
| 60 | { |
| 61 | struct platform_device *pdev = dev_id; |
| 62 | struct jornadakbd *jornadakbd = platform_get_drvdata(pdev); |
Dmitry Torokhov | 72f9df4 | 2007-10-11 00:48:48 -0400 | [diff] [blame] | 63 | struct input_dev *input = jornadakbd->input; |
| 64 | u8 count, kbd_data, scan_code; |
Kristoffer Ericson | b0a4e1a | 2007-09-26 00:02:49 -0400 | [diff] [blame] | 65 | |
| 66 | /* startup ssp with spinlock */ |
| 67 | jornada_ssp_start(); |
| 68 | |
| 69 | if (jornada_ssp_inout(GETSCANKEYCODE) != TXDUMMY) { |
| 70 | printk(KERN_DEBUG |
| 71 | "jornada720_kbd: " |
| 72 | "GetKeycode command failed with ETIMEDOUT, " |
| 73 | "flushed bus\n"); |
| 74 | } else { |
| 75 | /* How many keycodes are waiting for us? */ |
| 76 | count = jornada_ssp_byte(TXDUMMY); |
| 77 | |
| 78 | /* Lets drag them out one at a time */ |
| 79 | while (count--) { |
| 80 | /* Exchange TxDummy for location (keymap[kbddata]) */ |
| 81 | kbd_data = jornada_ssp_byte(TXDUMMY); |
Dmitry Torokhov | 72f9df4 | 2007-10-11 00:48:48 -0400 | [diff] [blame] | 82 | scan_code = kbd_data & 0x7f; |
Kristoffer Ericson | b0a4e1a | 2007-09-26 00:02:49 -0400 | [diff] [blame] | 83 | |
Dmitry Torokhov | 72f9df4 | 2007-10-11 00:48:48 -0400 | [diff] [blame] | 84 | input_event(input, EV_MSC, MSC_SCAN, scan_code); |
| 85 | input_report_key(input, jornadakbd->keymap[scan_code], |
Kristoffer Ericson | b0a4e1a | 2007-09-26 00:02:49 -0400 | [diff] [blame] | 86 | !(kbd_data & 0x80)); |
Dmitry Torokhov | 72f9df4 | 2007-10-11 00:48:48 -0400 | [diff] [blame] | 87 | input_sync(input); |
Kristoffer Ericson | b0a4e1a | 2007-09-26 00:02:49 -0400 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
| 91 | /* release spinlock and turn off ssp */ |
| 92 | jornada_ssp_end(); |
| 93 | |
| 94 | return IRQ_HANDLED; |
| 95 | }; |
| 96 | |
| 97 | static int __devinit jornada720_kbd_probe(struct platform_device *pdev) |
| 98 | { |
| 99 | struct jornadakbd *jornadakbd; |
| 100 | struct input_dev *input_dev; |
| 101 | int i, err; |
| 102 | |
| 103 | jornadakbd = kzalloc(sizeof(struct jornadakbd), GFP_KERNEL); |
| 104 | input_dev = input_allocate_device(); |
| 105 | if (!jornadakbd || !input_dev) { |
| 106 | err = -ENOMEM; |
| 107 | goto fail1; |
| 108 | } |
| 109 | |
| 110 | platform_set_drvdata(pdev, jornadakbd); |
| 111 | |
| 112 | memcpy(jornadakbd->keymap, jornada_std_keymap, |
| 113 | sizeof(jornada_std_keymap)); |
| 114 | jornadakbd->input = input_dev; |
| 115 | |
| 116 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP); |
| 117 | input_dev->name = "HP Jornada 720 keyboard"; |
| 118 | input_dev->phys = "jornadakbd/input0"; |
| 119 | input_dev->keycode = jornadakbd->keymap; |
| 120 | input_dev->keycodesize = sizeof(unsigned short); |
| 121 | input_dev->keycodemax = ARRAY_SIZE(jornada_std_keymap); |
| 122 | input_dev->id.bustype = BUS_HOST; |
| 123 | input_dev->dev.parent = &pdev->dev; |
| 124 | |
| 125 | for (i = 0; i < ARRAY_SIZE(jornadakbd->keymap); i++) |
| 126 | __set_bit(jornadakbd->keymap[i], input_dev->keybit); |
| 127 | __clear_bit(KEY_RESERVED, input_dev->keybit); |
| 128 | |
Dmitry Torokhov | 72f9df4 | 2007-10-11 00:48:48 -0400 | [diff] [blame] | 129 | input_set_capability(input_dev, EV_MSC, MSC_SCAN); |
| 130 | |
Kristoffer Ericson | b0a4e1a | 2007-09-26 00:02:49 -0400 | [diff] [blame] | 131 | err = request_irq(IRQ_GPIO0, |
| 132 | jornada720_kbd_interrupt, |
Yong Zhang | ec4665c | 2011-09-07 14:04:16 -0700 | [diff] [blame] | 133 | IRQF_TRIGGER_FALLING, |
Kristoffer Ericson | b0a4e1a | 2007-09-26 00:02:49 -0400 | [diff] [blame] | 134 | "jornadakbd", pdev); |
| 135 | if (err) { |
| 136 | printk(KERN_INFO "jornadakbd720_kbd: Unable to grab IRQ\n"); |
| 137 | goto fail1; |
| 138 | } |
| 139 | |
| 140 | err = input_register_device(jornadakbd->input); |
| 141 | if (err) |
| 142 | goto fail2; |
| 143 | |
| 144 | return 0; |
| 145 | |
| 146 | fail2: /* IRQ, DEVICE, MEMORY */ |
| 147 | free_irq(IRQ_GPIO0, pdev); |
| 148 | fail1: /* DEVICE, MEMORY */ |
| 149 | platform_set_drvdata(pdev, NULL); |
| 150 | input_free_device(input_dev); |
| 151 | kfree(jornadakbd); |
| 152 | return err; |
| 153 | }; |
| 154 | |
| 155 | static int __devexit jornada720_kbd_remove(struct platform_device *pdev) |
| 156 | { |
| 157 | struct jornadakbd *jornadakbd = platform_get_drvdata(pdev); |
| 158 | |
| 159 | free_irq(IRQ_GPIO0, pdev); |
| 160 | platform_set_drvdata(pdev, NULL); |
| 161 | input_unregister_device(jornadakbd->input); |
| 162 | kfree(jornadakbd); |
| 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
Kay Sievers | d7b5247 | 2008-04-18 00:24:42 -0400 | [diff] [blame] | 167 | /* work with hotplug and coldplug */ |
| 168 | MODULE_ALIAS("platform:jornada720_kbd"); |
| 169 | |
Kristoffer Ericson | b0a4e1a | 2007-09-26 00:02:49 -0400 | [diff] [blame] | 170 | static struct platform_driver jornada720_kbd_driver = { |
| 171 | .driver = { |
| 172 | .name = "jornada720_kbd", |
Kay Sievers | d7b5247 | 2008-04-18 00:24:42 -0400 | [diff] [blame] | 173 | .owner = THIS_MODULE, |
Kristoffer Ericson | b0a4e1a | 2007-09-26 00:02:49 -0400 | [diff] [blame] | 174 | }, |
| 175 | .probe = jornada720_kbd_probe, |
| 176 | .remove = __devexit_p(jornada720_kbd_remove), |
| 177 | }; |
JJ Ding | 5146c84 | 2011-11-29 11:08:39 -0800 | [diff] [blame] | 178 | module_platform_driver(jornada720_kbd_driver); |