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