Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Helge Deller | e6cdd15 | 2008-04-02 00:42:42 -0400 | [diff] [blame] | 2 | * LoCoMo keyboard driver for Linux-based ARM PDAs: |
| 3 | * - SHARP Zaurus Collie (SL-5500) |
| 4 | * - SHARP Zaurus Poodle (SL-5600) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Helge Deller | e6cdd15 | 2008-04-02 00:42:42 -0400 | [diff] [blame] | 6 | * Copyright (c) 2005 John Lenz |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Based on from xtkbd.c |
Helge Deller | e6cdd15 | 2008-04-02 00:42:42 -0400 | [diff] [blame] | 8 | * |
| 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | * |
| 24 | */ |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/slab.h> |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/input.h> |
| 30 | #include <linux/delay.h> |
| 31 | #include <linux/device.h> |
| 32 | #include <linux/interrupt.h> |
| 33 | #include <linux/ioport.h> |
| 34 | |
| 35 | #include <asm/hardware/locomo.h> |
| 36 | #include <asm/irq.h> |
| 37 | |
| 38 | MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>"); |
| 39 | MODULE_DESCRIPTION("LoCoMo keyboard driver"); |
| 40 | MODULE_LICENSE("GPL"); |
| 41 | |
Dmitry Torokhov | d083e90 | 2005-05-29 02:28:42 -0500 | [diff] [blame] | 42 | #define LOCOMOKBD_NUMKEYS 128 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | #define KEY_ACTIVITY KEY_F16 |
| 45 | #define KEY_CONTACT KEY_F18 |
| 46 | #define KEY_CENTER KEY_F15 |
| 47 | |
Helge Deller | e6cdd15 | 2008-04-02 00:42:42 -0400 | [diff] [blame] | 48 | static const unsigned char |
| 49 | locomokbd_keycode[LOCOMOKBD_NUMKEYS] __devinitconst = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | 0, KEY_ESC, KEY_ACTIVITY, 0, 0, 0, 0, 0, 0, 0, /* 0 - 9 */ |
| 51 | 0, 0, 0, 0, 0, 0, 0, KEY_MENU, KEY_HOME, KEY_CONTACT, /* 10 - 19 */ |
| 52 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 20 - 29 */ |
| 53 | 0, 0, 0, KEY_CENTER, 0, KEY_MAIL, 0, 0, 0, 0, /* 30 - 39 */ |
| 54 | 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_RIGHT, /* 40 - 49 */ |
| 55 | KEY_UP, KEY_LEFT, 0, 0, KEY_P, 0, KEY_O, KEY_I, KEY_Y, KEY_T, /* 50 - 59 */ |
| 56 | KEY_E, KEY_W, 0, 0, 0, 0, KEY_DOWN, KEY_ENTER, 0, 0, /* 60 - 69 */ |
| 57 | KEY_BACKSPACE, 0, KEY_L, KEY_U, KEY_H, KEY_R, KEY_D, KEY_Q, 0, 0, /* 70 - 79 */ |
| 58 | 0, 0, 0, 0, 0, 0, KEY_ENTER, KEY_RIGHTSHIFT, KEY_K, KEY_J, /* 80 - 89 */ |
| 59 | KEY_G, KEY_F, KEY_X, KEY_S, 0, 0, 0, 0, 0, 0, /* 90 - 99 */ |
| 60 | 0, 0, KEY_DOT, 0, KEY_COMMA, KEY_N, KEY_B, KEY_C, KEY_Z, KEY_A, /* 100 - 109 */ |
| 61 | KEY_LEFTSHIFT, KEY_TAB, KEY_LEFTCTRL, 0, 0, 0, 0, 0, 0, 0, /* 110 - 119 */ |
Dmitry Torokhov | d083e90 | 2005-05-29 02:28:42 -0500 | [diff] [blame] | 62 | KEY_M, KEY_SPACE, KEY_V, KEY_APOSTROPHE, KEY_SLASH, 0, 0, 0 /* 120 - 128 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | #define KB_ROWS 16 |
| 66 | #define KB_COLS 8 |
| 67 | #define KB_ROWMASK(r) (1 << (r)) |
| 68 | #define SCANCODE(c,r) ( ((c)<<4) + (r) + 1 ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | #define KB_DELAY 8 |
| 71 | #define SCAN_INTERVAL (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | struct locomokbd { |
| 74 | unsigned char keycode[LOCOMOKBD_NUMKEYS]; |
Dmitry Torokhov | 438c9da | 2005-11-02 22:49:53 -0500 | [diff] [blame] | 75 | struct input_dev *input; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | char phys[32]; |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | unsigned long base; |
| 79 | spinlock_t lock; |
Dmitry Torokhov | d083e90 | 2005-05-29 02:28:42 -0500 | [diff] [blame] | 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | struct timer_list timer; |
Helge Deller | e6cdd15 | 2008-04-02 00:42:42 -0400 | [diff] [blame] | 82 | unsigned long suspend_jiffies; |
| 83 | unsigned int count_cancel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | /* helper functions for reading the keyboard matrix */ |
| 87 | static inline void locomokbd_charge_all(unsigned long membase) |
| 88 | { |
| 89 | locomo_writel(0x00FF, membase + LOCOMO_KSC); |
| 90 | } |
| 91 | |
| 92 | static inline void locomokbd_activate_all(unsigned long membase) |
| 93 | { |
| 94 | unsigned long r; |
Dmitry Torokhov | d083e90 | 2005-05-29 02:28:42 -0500 | [diff] [blame] | 95 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | locomo_writel(0, membase + LOCOMO_KSC); |
| 97 | r = locomo_readl(membase + LOCOMO_KIC); |
| 98 | r &= 0xFEFF; |
| 99 | locomo_writel(r, membase + LOCOMO_KIC); |
| 100 | } |
| 101 | |
| 102 | static inline void locomokbd_activate_col(unsigned long membase, int col) |
| 103 | { |
| 104 | unsigned short nset; |
| 105 | unsigned short nbset; |
| 106 | |
| 107 | nset = 0xFF & ~(1 << col); |
| 108 | nbset = (nset << 8) + nset; |
| 109 | locomo_writel(nbset, membase + LOCOMO_KSC); |
| 110 | } |
| 111 | |
| 112 | static inline void locomokbd_reset_col(unsigned long membase, int col) |
| 113 | { |
| 114 | unsigned short nbset; |
| 115 | |
| 116 | nbset = ((0xFF & ~(1 << col)) << 8) + 0xFF; |
| 117 | locomo_writel(nbset, membase + LOCOMO_KSC); |
| 118 | } |
| 119 | |
| 120 | /* |
| 121 | * The LoCoMo keyboard only generates interrupts when a key is pressed. |
| 122 | * So when a key is pressed, we enable a timer. This timer scans the |
| 123 | * keyboard, and this is how we detect when the key is released. |
| 124 | */ |
| 125 | |
| 126 | /* Scan the hardware keyboard and push any changes up through the input layer */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 127 | static void locomokbd_scankeyboard(struct locomokbd *locomokbd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { |
Helge Deller | e6cdd15 | 2008-04-02 00:42:42 -0400 | [diff] [blame] | 129 | unsigned int row, col, rowd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | unsigned long flags; |
| 131 | unsigned int num_pressed; |
| 132 | unsigned long membase = locomokbd->base; |
| 133 | |
| 134 | spin_lock_irqsave(&locomokbd->lock, flags); |
| 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | locomokbd_charge_all(membase); |
| 137 | |
| 138 | num_pressed = 0; |
| 139 | for (col = 0; col < KB_COLS; col++) { |
| 140 | |
| 141 | locomokbd_activate_col(membase, col); |
| 142 | udelay(KB_DELAY); |
Dmitry Torokhov | d083e90 | 2005-05-29 02:28:42 -0500 | [diff] [blame] | 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | rowd = ~locomo_readl(membase + LOCOMO_KIB); |
Dmitry Torokhov | d083e90 | 2005-05-29 02:28:42 -0500 | [diff] [blame] | 145 | for (row = 0; row < KB_ROWS; row++) { |
Helge Deller | e6cdd15 | 2008-04-02 00:42:42 -0400 | [diff] [blame] | 146 | unsigned int scancode, pressed, key; |
| 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | scancode = SCANCODE(col, row); |
Helge Deller | e6cdd15 | 2008-04-02 00:42:42 -0400 | [diff] [blame] | 149 | pressed = rowd & KB_ROWMASK(row); |
| 150 | key = locomokbd->keycode[scancode]; |
| 151 | |
| 152 | input_report_key(locomokbd->input, key, pressed); |
| 153 | if (likely(!pressed)) |
| 154 | continue; |
| 155 | |
| 156 | num_pressed++; |
| 157 | |
| 158 | /* The "Cancel/ESC" key is labeled "On/Off" on |
| 159 | * Collie and Poodle and should suspend the device |
| 160 | * if it was pressed for more than a second. */ |
| 161 | if (unlikely(key == KEY_ESC)) { |
| 162 | if (!time_after(jiffies, |
| 163 | locomokbd->suspend_jiffies + HZ)) |
| 164 | continue; |
| 165 | if (locomokbd->count_cancel++ |
| 166 | != (HZ/SCAN_INTERVAL + 1)) |
| 167 | continue; |
| 168 | input_event(locomokbd->input, EV_PWR, |
| 169 | KEY_SUSPEND, 1); |
| 170 | locomokbd->suspend_jiffies = jiffies; |
| 171 | } else |
| 172 | locomokbd->count_cancel = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | locomokbd_reset_col(membase, col); |
| 175 | } |
| 176 | locomokbd_activate_all(membase); |
| 177 | |
Dmitry Torokhov | 438c9da | 2005-11-02 22:49:53 -0500 | [diff] [blame] | 178 | input_sync(locomokbd->input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | /* if any keys are pressed, enable the timer */ |
| 181 | if (num_pressed) |
| 182 | mod_timer(&locomokbd->timer, jiffies + SCAN_INTERVAL); |
Helge Deller | e6cdd15 | 2008-04-02 00:42:42 -0400 | [diff] [blame] | 183 | else |
| 184 | locomokbd->count_cancel = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
| 186 | spin_unlock_irqrestore(&locomokbd->lock, flags); |
| 187 | } |
| 188 | |
Dmitry Torokhov | d083e90 | 2005-05-29 02:28:42 -0500 | [diff] [blame] | 189 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | * LoCoMo keyboard interrupt handler. |
| 191 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 192 | static irqreturn_t locomokbd_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
| 194 | struct locomokbd *locomokbd = dev_id; |
Eric Miao | da8065a | 2010-02-04 17:13:55 -0800 | [diff] [blame] | 195 | u16 r; |
| 196 | |
| 197 | r = locomo_readl(locomokbd->base + LOCOMO_KIC); |
| 198 | if ((r & 0x0001) == 0) |
| 199 | return IRQ_HANDLED; |
| 200 | |
| 201 | locomo_writel(r & ~0x0100, locomokbd->base + LOCOMO_KIC); /* Ack */ |
| 202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | /** wait chattering delay **/ |
| 204 | udelay(100); |
| 205 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 206 | locomokbd_scankeyboard(locomokbd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | return IRQ_HANDLED; |
| 208 | } |
| 209 | |
| 210 | /* |
| 211 | * LoCoMo timer checking for released keys |
| 212 | */ |
| 213 | static void locomokbd_timer_callback(unsigned long data) |
| 214 | { |
| 215 | struct locomokbd *locomokbd = (struct locomokbd *) data; |
Helge Deller | e6cdd15 | 2008-04-02 00:42:42 -0400 | [diff] [blame] | 216 | |
Russell King | 36bd262 | 2006-10-15 13:50:02 +0100 | [diff] [blame] | 217 | locomokbd_scankeyboard(locomokbd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Eric Miao | da8065a | 2010-02-04 17:13:55 -0800 | [diff] [blame] | 220 | static int locomokbd_open(struct input_dev *dev) |
| 221 | { |
| 222 | struct locomokbd *locomokbd = input_get_drvdata(dev); |
| 223 | u16 r; |
| 224 | |
| 225 | r = locomo_readl(locomokbd->base + LOCOMO_KIC) | 0x0010; |
| 226 | locomo_writel(r, locomokbd->base + LOCOMO_KIC); |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | static void locomokbd_close(struct input_dev *dev) |
| 231 | { |
| 232 | struct locomokbd *locomokbd = input_get_drvdata(dev); |
| 233 | u16 r; |
| 234 | |
| 235 | r = locomo_readl(locomokbd->base + LOCOMO_KIC) & ~0x0010; |
| 236 | locomo_writel(r, locomokbd->base + LOCOMO_KIC); |
| 237 | } |
| 238 | |
Helge Deller | e6cdd15 | 2008-04-02 00:42:42 -0400 | [diff] [blame] | 239 | static int __devinit locomokbd_probe(struct locomo_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | { |
| 241 | struct locomokbd *locomokbd; |
Dmitry Torokhov | 438c9da | 2005-11-02 22:49:53 -0500 | [diff] [blame] | 242 | struct input_dev *input_dev; |
Dmitry Torokhov | 2b03b60 | 2006-11-05 22:39:56 -0500 | [diff] [blame] | 243 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Dmitry Torokhov | 438c9da | 2005-11-02 22:49:53 -0500 | [diff] [blame] | 245 | locomokbd = kzalloc(sizeof(struct locomokbd), GFP_KERNEL); |
| 246 | input_dev = input_allocate_device(); |
| 247 | if (!locomokbd || !input_dev) { |
Dmitry Torokhov | 2b03b60 | 2006-11-05 22:39:56 -0500 | [diff] [blame] | 248 | err = -ENOMEM; |
| 249 | goto err_free_mem; |
Dmitry Torokhov | 438c9da | 2005-11-02 22:49:53 -0500 | [diff] [blame] | 250 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | /* try and claim memory region */ |
Dmitry Torokhov | d083e90 | 2005-05-29 02:28:42 -0500 | [diff] [blame] | 253 | if (!request_mem_region((unsigned long) dev->mapbase, |
| 254 | dev->length, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | LOCOMO_DRIVER_NAME(dev))) { |
Dmitry Torokhov | 2b03b60 | 2006-11-05 22:39:56 -0500 | [diff] [blame] | 256 | err = -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | printk(KERN_ERR "locomokbd: Can't acquire access to io memory for keyboard\n"); |
Dmitry Torokhov | 2b03b60 | 2006-11-05 22:39:56 -0500 | [diff] [blame] | 258 | goto err_free_mem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | locomo_set_drvdata(dev, locomokbd); |
| 262 | |
| 263 | locomokbd->base = (unsigned long) dev->mapbase; |
| 264 | |
| 265 | spin_lock_init(&locomokbd->lock); |
| 266 | |
| 267 | init_timer(&locomokbd->timer); |
| 268 | locomokbd->timer.function = locomokbd_timer_callback; |
| 269 | locomokbd->timer.data = (unsigned long) locomokbd; |
| 270 | |
Helge Deller | e6cdd15 | 2008-04-02 00:42:42 -0400 | [diff] [blame] | 271 | locomokbd->suspend_jiffies = jiffies; |
| 272 | |
Dmitry Torokhov | 438c9da | 2005-11-02 22:49:53 -0500 | [diff] [blame] | 273 | locomokbd->input = input_dev; |
| 274 | strcpy(locomokbd->phys, "locomokbd/input0"); |
Dmitry Torokhov | d083e90 | 2005-05-29 02:28:42 -0500 | [diff] [blame] | 275 | |
Dmitry Torokhov | 438c9da | 2005-11-02 22:49:53 -0500 | [diff] [blame] | 276 | input_dev->name = "LoCoMo keyboard"; |
| 277 | input_dev->phys = locomokbd->phys; |
Pavel Machek | d7a767d | 2005-11-02 22:52:33 -0500 | [diff] [blame] | 278 | input_dev->id.bustype = BUS_HOST; |
Dmitry Torokhov | 438c9da | 2005-11-02 22:49:53 -0500 | [diff] [blame] | 279 | input_dev->id.vendor = 0x0001; |
| 280 | input_dev->id.product = 0x0001; |
| 281 | input_dev->id.version = 0x0100; |
Eric Miao | da8065a | 2010-02-04 17:13:55 -0800 | [diff] [blame] | 282 | input_dev->open = locomokbd_open; |
| 283 | input_dev->close = locomokbd_close; |
Dmitry Torokhov | 469ba4d | 2007-04-12 01:34:58 -0400 | [diff] [blame] | 284 | input_dev->dev.parent = &dev->dev; |
Dmitry Torokhov | 438c9da | 2005-11-02 22:49:53 -0500 | [diff] [blame] | 285 | |
Helge Deller | e6cdd15 | 2008-04-02 00:42:42 -0400 | [diff] [blame] | 286 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | |
| 287 | BIT_MASK(EV_PWR); |
Dmitry Torokhov | 438c9da | 2005-11-02 22:49:53 -0500 | [diff] [blame] | 288 | input_dev->keycode = locomokbd->keycode; |
Helge Deller | e6cdd15 | 2008-04-02 00:42:42 -0400 | [diff] [blame] | 289 | input_dev->keycodesize = sizeof(locomokbd_keycode[0]); |
Dmitry Torokhov | 438c9da | 2005-11-02 22:49:53 -0500 | [diff] [blame] | 290 | input_dev->keycodemax = ARRAY_SIZE(locomokbd_keycode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
Eric Miao | da8065a | 2010-02-04 17:13:55 -0800 | [diff] [blame] | 292 | input_set_drvdata(input_dev, locomokbd); |
| 293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | memcpy(locomokbd->keycode, locomokbd_keycode, sizeof(locomokbd->keycode)); |
| 295 | for (i = 0; i < LOCOMOKBD_NUMKEYS; i++) |
Dmitry Torokhov | 438c9da | 2005-11-02 22:49:53 -0500 | [diff] [blame] | 296 | set_bit(locomokbd->keycode[i], input_dev->keybit); |
| 297 | clear_bit(0, input_dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
| 299 | /* attempt to get the interrupt */ |
Dmitry Torokhov | 2b03b60 | 2006-11-05 22:39:56 -0500 | [diff] [blame] | 300 | err = request_irq(dev->irq[0], locomokbd_interrupt, 0, "locomokbd", locomokbd); |
| 301 | if (err) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | printk(KERN_ERR "locomokbd: Can't get irq for keyboard\n"); |
Dmitry Torokhov | 2b03b60 | 2006-11-05 22:39:56 -0500 | [diff] [blame] | 303 | goto err_release_region; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Dmitry Torokhov | 2b03b60 | 2006-11-05 22:39:56 -0500 | [diff] [blame] | 306 | err = input_register_device(locomokbd->input); |
| 307 | if (err) |
| 308 | goto err_free_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
| 310 | return 0; |
| 311 | |
Dmitry Torokhov | 2b03b60 | 2006-11-05 22:39:56 -0500 | [diff] [blame] | 312 | err_free_irq: |
| 313 | free_irq(dev->irq[0], locomokbd); |
| 314 | err_release_region: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | release_mem_region((unsigned long) dev->mapbase, dev->length); |
| 316 | locomo_set_drvdata(dev, NULL); |
Dmitry Torokhov | 2b03b60 | 2006-11-05 22:39:56 -0500 | [diff] [blame] | 317 | err_free_mem: |
Dmitry Torokhov | 438c9da | 2005-11-02 22:49:53 -0500 | [diff] [blame] | 318 | input_free_device(input_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | kfree(locomokbd); |
| 320 | |
Dmitry Torokhov | 2b03b60 | 2006-11-05 22:39:56 -0500 | [diff] [blame] | 321 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Helge Deller | e6cdd15 | 2008-04-02 00:42:42 -0400 | [diff] [blame] | 324 | static int __devexit locomokbd_remove(struct locomo_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | { |
| 326 | struct locomokbd *locomokbd = locomo_get_drvdata(dev); |
Dmitry Torokhov | d083e90 | 2005-05-29 02:28:42 -0500 | [diff] [blame] | 327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | free_irq(dev->irq[0], locomokbd); |
| 329 | |
| 330 | del_timer_sync(&locomokbd->timer); |
Dmitry Torokhov | d083e90 | 2005-05-29 02:28:42 -0500 | [diff] [blame] | 331 | |
Dmitry Torokhov | 438c9da | 2005-11-02 22:49:53 -0500 | [diff] [blame] | 332 | input_unregister_device(locomokbd->input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | locomo_set_drvdata(dev, NULL); |
| 334 | |
| 335 | release_mem_region((unsigned long) dev->mapbase, dev->length); |
| 336 | |
| 337 | kfree(locomokbd); |
| 338 | |
| 339 | return 0; |
| 340 | } |
| 341 | |
| 342 | static struct locomo_driver keyboard_driver = { |
| 343 | .drv = { |
| 344 | .name = "locomokbd" |
| 345 | }, |
| 346 | .devid = LOCOMO_DEVID_KEYBOARD, |
| 347 | .probe = locomokbd_probe, |
Helge Deller | e6cdd15 | 2008-04-02 00:42:42 -0400 | [diff] [blame] | 348 | .remove = __devexit_p(locomokbd_remove), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | }; |
| 350 | |
| 351 | static int __init locomokbd_init(void) |
| 352 | { |
| 353 | return locomo_driver_register(&keyboard_driver); |
| 354 | } |
| 355 | |
| 356 | static void __exit locomokbd_exit(void) |
| 357 | { |
| 358 | locomo_driver_unregister(&keyboard_driver); |
| 359 | } |
| 360 | |
| 361 | module_init(locomokbd_init); |
| 362 | module_exit(locomokbd_exit); |