1 /* 2 * drivers/input/serio/gscps2.c 3 * 4 * Copyright (c) 2004-2006 Helge Deller <deller@gmx.de> 5 * Copyright (c) 2002 Laurent Canet <canetl@esiee.fr> 6 * Copyright (c) 2002 Thibaut Varene <varenet@parisc-linux.org> 7 * 8 * Pieces of code based on linux-2.4's hp_mouse.c & hp_keyb.c 9 * Copyright (c) 1999 Alex deVries <alex@onefishtwo.ca> 10 * Copyright (c) 1999-2000 Philipp Rumpf <prumpf@tux.org> 11 * Copyright (c) 2000 Xavier Debacker <debackex@esiee.fr> 12 * Copyright (c) 2000-2001 Thomas Marteau <marteaut@esiee.fr> 13 * 14 * HP GSC PS/2 port driver, found in PA/RISC Workstations 15 * 16 * This file is subject to the terms and conditions of the GNU General Public 17 * License. See the file "COPYING" in the main directory of this archive 18 * for more details. 19 * 20 * TODO: 21 * - Dino testing (did HP ever shipped a machine on which this port 22 * was usable/enabled ?) 23 */ 24 25 #include <linux/delay.h> 26 #include <linux/input.h> 27 #include <linux/interrupt.h> 28 #include <linux/io.h> 29 #include <linux/ioport.h> 30 #include <linux/property.h> 31 #include <linux/serio.h> 32 33 #include <asm/irq.h> 34 #include <asm/parisc-device.h> 35 36 MODULE_AUTHOR("Laurent Canet <canetl@esiee.fr>, Thibaut Varene <varenet@parisc-linux.org>, Helge Deller <deller@gmx.de>"); 37 MODULE_DESCRIPTION("HP GSC PS2 port driver"); 38 MODULE_LICENSE("GPL"); 39 40 #define PFX "gscps2.c: " 41 42 /* 43 * Driver constants 44 */ 45 46 /* various constants */ 47 #define ENABLE 1 48 #define DISABLE 0 49 50 #define GSC_DINO_OFFSET 0x0800 /* offset for DINO controller versus LASI one */ 51 52 /* PS/2 IO port offsets */ 53 #define GSC_ID 0x00 /* device ID offset (see: GSC_ID_XXX) */ 54 #define GSC_RESET 0x00 /* reset port offset */ 55 #define GSC_RCVDATA 0x04 /* receive port offset */ 56 #define GSC_XMTDATA 0x04 /* transmit port offset */ 57 #define GSC_CONTROL 0x08 /* see: Control register bits */ 58 #define GSC_STATUS 0x0C /* see: Status register bits */ 59 60 /* Control register bits */ 61 #define GSC_CTRL_ENBL 0x01 /* enable interface */ 62 #define GSC_CTRL_LPBXR 0x02 /* loopback operation */ 63 #define GSC_CTRL_DIAG 0x20 /* directly control clock/data line */ 64 #define GSC_CTRL_DATDIR 0x40 /* data line direct control */ 65 #define GSC_CTRL_CLKDIR 0x80 /* clock line direct control */ 66 67 /* Status register bits */ 68 #define GSC_STAT_RBNE 0x01 /* Receive Buffer Not Empty */ 69 #define GSC_STAT_TBNE 0x02 /* Transmit Buffer Not Empty */ 70 #define GSC_STAT_TERR 0x04 /* Timeout Error */ 71 #define GSC_STAT_PERR 0x08 /* Parity Error */ 72 #define GSC_STAT_CMPINTR 0x10 /* Composite Interrupt = irq on any port */ 73 #define GSC_STAT_DATSHD 0x40 /* Data Line Shadow */ 74 #define GSC_STAT_CLKSHD 0x80 /* Clock Line Shadow */ 75 76 /* IDs returned by GSC_ID port register */ 77 #define GSC_ID_KEYBOARD 0 /* device ID values */ 78 #define GSC_ID_MOUSE 1 79 80 #ifndef CONFIG_SERIO_GSCPS2_RDI_KEYCODES 81 # define CONFLICT(x, y) x 82 #else 83 # define CONFLICT(x, y) y 84 #endif 85 86 /* 87 * Sadly RDI (Tadpole) decided to ship a different keyboard layout 88 * than HP for their PS/2 laptop keyboard which leads to conflicting 89 * keycodes between a normal HP PS/2 keyboard and a RDI PrecisionBook. 90 * HP: RDI: 91 */ 92 #define C_07 CONFLICT(KEY_F12, KEY_F1) 93 #define C_11 CONFLICT(KEY_LEFTALT, KEY_LEFTCTRL) 94 #define C_14 CONFLICT(KEY_LEFTCTRL, KEY_CAPSLOCK) 95 #define C_58 CONFLICT(KEY_CAPSLOCK, KEY_RIGHTCTRL) 96 #define C_61 CONFLICT(KEY_102ND, KEY_LEFT) 97 98 /* 99 * Special keycode value recognized by atkbd (ATKBD_KEY_NULL) to silently 100 * discard scancodes without generating input events or "unknown key" warnings. 101 */ 102 #define KEY_NULL 255 103 104 #define KEYMAP_ENTRY(scancode, keycode) (((scancode) << 16) | (keycode)) 105 106 static const u32 gscps2_keymap[] = { 107 KEYMAP_ENTRY(0x01, KEY_F9), KEYMAP_ENTRY(0x03, KEY_F5), 108 KEYMAP_ENTRY(0x04, KEY_F3), KEYMAP_ENTRY(0x05, KEY_F1), 109 KEYMAP_ENTRY(0x06, KEY_F2), KEYMAP_ENTRY(0x07, C_07), 110 KEYMAP_ENTRY(0x08, KEY_ESC), KEYMAP_ENTRY(0x09, KEY_F10), 111 KEYMAP_ENTRY(0x0a, KEY_F8), KEYMAP_ENTRY(0x0b, KEY_F6), 112 KEYMAP_ENTRY(0x0c, KEY_F4), KEYMAP_ENTRY(0x0d, KEY_TAB), 113 KEYMAP_ENTRY(0x0e, KEY_GRAVE), KEYMAP_ENTRY(0x0f, KEY_F2), 114 KEYMAP_ENTRY(0x11, C_11), KEYMAP_ENTRY(0x12, KEY_LEFTSHIFT), 115 KEYMAP_ENTRY(0x14, C_14), KEYMAP_ENTRY(0x15, KEY_Q), 116 KEYMAP_ENTRY(0x16, KEY_1), KEYMAP_ENTRY(0x17, KEY_F3), 117 KEYMAP_ENTRY(0x19, KEY_LEFTALT), KEYMAP_ENTRY(0x1a, KEY_Z), 118 KEYMAP_ENTRY(0x1b, KEY_S), KEYMAP_ENTRY(0x1c, KEY_A), 119 KEYMAP_ENTRY(0x1d, KEY_W), KEYMAP_ENTRY(0x1e, KEY_2), 120 KEYMAP_ENTRY(0x1f, KEY_F4), KEYMAP_ENTRY(0x21, KEY_C), 121 KEYMAP_ENTRY(0x22, KEY_X), KEYMAP_ENTRY(0x23, KEY_D), 122 KEYMAP_ENTRY(0x24, KEY_E), KEYMAP_ENTRY(0x25, KEY_4), 123 KEYMAP_ENTRY(0x26, KEY_3), KEYMAP_ENTRY(0x27, KEY_F5), 124 KEYMAP_ENTRY(0x29, KEY_SPACE), KEYMAP_ENTRY(0x2a, KEY_V), 125 KEYMAP_ENTRY(0x2b, KEY_F), KEYMAP_ENTRY(0x2c, KEY_T), 126 KEYMAP_ENTRY(0x2d, KEY_R), KEYMAP_ENTRY(0x2e, KEY_5), 127 KEYMAP_ENTRY(0x2f, KEY_F6), KEYMAP_ENTRY(0x31, KEY_N), 128 KEYMAP_ENTRY(0x32, KEY_B), KEYMAP_ENTRY(0x33, KEY_H), 129 KEYMAP_ENTRY(0x34, KEY_G), KEYMAP_ENTRY(0x35, KEY_Y), 130 KEYMAP_ENTRY(0x36, KEY_6), KEYMAP_ENTRY(0x37, KEY_F7), 131 KEYMAP_ENTRY(0x39, KEY_RIGHTALT), KEYMAP_ENTRY(0x3a, KEY_M), 132 KEYMAP_ENTRY(0x3b, KEY_J), KEYMAP_ENTRY(0x3c, KEY_U), 133 KEYMAP_ENTRY(0x3d, KEY_7), KEYMAP_ENTRY(0x3e, KEY_8), 134 KEYMAP_ENTRY(0x3f, KEY_F8), KEYMAP_ENTRY(0x41, KEY_COMMA), 135 KEYMAP_ENTRY(0x42, KEY_K), KEYMAP_ENTRY(0x43, KEY_I), 136 KEYMAP_ENTRY(0x44, KEY_O), KEYMAP_ENTRY(0x45, KEY_0), 137 KEYMAP_ENTRY(0x46, KEY_9), KEYMAP_ENTRY(0x47, KEY_F9), 138 KEYMAP_ENTRY(0x49, KEY_DOT), KEYMAP_ENTRY(0x4a, KEY_SLASH), 139 KEYMAP_ENTRY(0x4b, KEY_L), KEYMAP_ENTRY(0x4c, KEY_SEMICOLON), 140 KEYMAP_ENTRY(0x4d, KEY_P), KEYMAP_ENTRY(0x4e, KEY_MINUS), 141 KEYMAP_ENTRY(0x4f, KEY_F10), KEYMAP_ENTRY(0x52, KEY_APOSTROPHE), 142 KEYMAP_ENTRY(0x54, KEY_LEFTBRACE), KEYMAP_ENTRY(0x55, KEY_EQUAL), 143 KEYMAP_ENTRY(0x56, KEY_F11), KEYMAP_ENTRY(0x57, KEY_SYSRQ), 144 KEYMAP_ENTRY(0x58, C_58), KEYMAP_ENTRY(0x59, KEY_RIGHTSHIFT), 145 KEYMAP_ENTRY(0x5a, KEY_ENTER), KEYMAP_ENTRY(0x5b, KEY_RIGHTBRACE), 146 KEYMAP_ENTRY(0x5c, KEY_BACKSLASH), KEYMAP_ENTRY(0x5d, KEY_BACKSLASH), 147 KEYMAP_ENTRY(0x5e, KEY_F12), KEYMAP_ENTRY(0x5f, KEY_SCROLLLOCK), 148 KEYMAP_ENTRY(0x60, KEY_DOWN), KEYMAP_ENTRY(0x61, C_61), 149 KEYMAP_ENTRY(0x62, KEY_PAUSE), KEYMAP_ENTRY(0x63, KEY_UP), 150 KEYMAP_ENTRY(0x64, KEY_DELETE), KEYMAP_ENTRY(0x65, KEY_END), 151 KEYMAP_ENTRY(0x66, KEY_BACKSPACE), KEYMAP_ENTRY(0x67, KEY_INSERT), 152 KEYMAP_ENTRY(0x69, KEY_KP1), KEYMAP_ENTRY(0x6a, KEY_RIGHT), 153 KEYMAP_ENTRY(0x6b, KEY_KP4), KEYMAP_ENTRY(0x6c, KEY_KP7), 154 KEYMAP_ENTRY(0x6d, KEY_PAGEDOWN), KEYMAP_ENTRY(0x6e, KEY_HOME), 155 KEYMAP_ENTRY(0x6f, KEY_PAGEUP), KEYMAP_ENTRY(0x70, KEY_KP0), 156 KEYMAP_ENTRY(0x71, KEY_KPDOT), KEYMAP_ENTRY(0x72, KEY_KP2), 157 KEYMAP_ENTRY(0x73, KEY_KP5), KEYMAP_ENTRY(0x74, KEY_KP6), 158 KEYMAP_ENTRY(0x75, KEY_KP8), KEYMAP_ENTRY(0x76, KEY_ESC), 159 KEYMAP_ENTRY(0x77, KEY_NUMLOCK), KEYMAP_ENTRY(0x78, KEY_F11), 160 KEYMAP_ENTRY(0x79, KEY_KPPLUS), KEYMAP_ENTRY(0x7a, KEY_KP3), 161 KEYMAP_ENTRY(0x7b, KEY_KPMINUS), KEYMAP_ENTRY(0x7c, KEY_KPASTERISK), 162 KEYMAP_ENTRY(0x7d, KEY_KP9), KEYMAP_ENTRY(0x7e, KEY_SCROLLLOCK), 163 KEYMAP_ENTRY(0x7f, KEY_102ND), KEYMAP_ENTRY(0x91, KEY_RIGHTALT), 164 KEYMAP_ENTRY(0x92, KEY_NULL), KEYMAP_ENTRY(0x94, KEY_RIGHTCTRL), 165 KEYMAP_ENTRY(0x9d, KEY_CAPSLOCK), KEYMAP_ENTRY(0x9f, KEY_LEFTMETA), 166 KEYMAP_ENTRY(0xa7, KEY_RIGHTMETA), KEYMAP_ENTRY(0xaf, KEY_COMPOSE), 167 KEYMAP_ENTRY(0xca, KEY_KPSLASH), KEYMAP_ENTRY(0xda, KEY_KPENTER), 168 KEYMAP_ENTRY(0xe9, KEY_END), KEYMAP_ENTRY(0xeb, KEY_LEFT), 169 KEYMAP_ENTRY(0xec, KEY_HOME), KEYMAP_ENTRY(0xf0, KEY_INSERT), 170 KEYMAP_ENTRY(0xf1, KEY_DELETE), KEYMAP_ENTRY(0xf2, KEY_DOWN), 171 KEYMAP_ENTRY(0xf4, KEY_RIGHT), KEYMAP_ENTRY(0xf5, KEY_UP), 172 KEYMAP_ENTRY(0xf7, KEY_PAUSE), KEYMAP_ENTRY(0xfa, KEY_PAGEDOWN), 173 KEYMAP_ENTRY(0xfc, KEY_SYSRQ), KEYMAP_ENTRY(0xfd, KEY_PAGEUP), 174 175 /* Escaped keycodes */ 176 KEYMAP_ENTRY(0x103, KEY_F7), KEYMAP_ENTRY(0x10b, KEY_LEFTMETA), 177 KEYMAP_ENTRY(0x10c, KEY_RIGHTMETA), KEYMAP_ENTRY(0x111, KEY_RIGHTALT), 178 KEYMAP_ENTRY(0x114, KEY_RIGHTCTRL), 179 }; 180 181 static const struct property_entry gscps2_props[] = { 182 PROPERTY_ENTRY_U32_ARRAY("linux,keymap", gscps2_keymap), 183 { } 184 }; 185 186 static const struct software_node gscps2_keyboard_node = { 187 .name = "gscps2-keyboard", 188 .properties = gscps2_props, 189 }; 190 191 static irqreturn_t gscps2_interrupt(int irq, void *dev); 192 193 #define BUFFER_SIZE 0x0f 194 195 /* GSC PS/2 port device struct */ 196 struct gscps2port { 197 struct list_head node; 198 struct parisc_device *padev; 199 struct serio *port; 200 spinlock_t lock; 201 char __iomem *addr; 202 u8 act, append; /* position in buffer[] */ 203 struct { 204 u8 data; 205 u8 str; 206 } buffer[BUFFER_SIZE+1]; 207 int id; 208 }; 209 210 /* 211 * Various HW level routines 212 */ 213 214 #define gscps2_readb_input(x) readb((x)+GSC_RCVDATA) 215 #define gscps2_readb_control(x) readb((x)+GSC_CONTROL) 216 #define gscps2_readb_status(x) readb((x)+GSC_STATUS) 217 #define gscps2_writeb_control(x, y) writeb((x), (y)+GSC_CONTROL) 218 219 220 /* 221 * wait_TBE() - wait for Transmit Buffer Empty 222 */ 223 224 static int wait_TBE(char __iomem *addr) 225 { 226 int timeout = 25000; /* device is expected to react within 250 msec */ 227 while (gscps2_readb_status(addr) & GSC_STAT_TBNE) { 228 if (!--timeout) 229 return 0; /* This should not happen */ 230 udelay(10); 231 } 232 return 1; 233 } 234 235 236 /* 237 * gscps2_flush() - flush the receive buffer 238 */ 239 240 static void gscps2_flush(struct gscps2port *ps2port) 241 { 242 while (gscps2_readb_status(ps2port->addr) & GSC_STAT_RBNE) 243 gscps2_readb_input(ps2port->addr); 244 ps2port->act = ps2port->append = 0; 245 } 246 247 /* 248 * gscps2_writeb_output() - write a byte to the port 249 * 250 * returns 1 on success, 0 on error 251 */ 252 253 static inline int gscps2_writeb_output(struct gscps2port *ps2port, u8 data) 254 { 255 char __iomem *addr = ps2port->addr; 256 257 if (!wait_TBE(addr)) { 258 printk(KERN_DEBUG PFX "timeout - could not write byte %#x\n", data); 259 return 0; 260 } 261 262 while (gscps2_readb_status(addr) & GSC_STAT_RBNE) 263 /* wait */; 264 265 scoped_guard(spinlock_irqsave, &ps2port->lock) 266 writeb(data, addr+GSC_XMTDATA); 267 268 /* this is ugly, but due to timing of the port it seems to be necessary. */ 269 mdelay(6); 270 271 /* make sure any received data is returned as fast as possible */ 272 /* this is important e.g. when we set the LEDs on the keyboard */ 273 gscps2_interrupt(0, NULL); 274 275 return 1; 276 } 277 278 279 /* 280 * gscps2_enable() - enables or disables the port 281 */ 282 283 static void gscps2_enable(struct gscps2port *ps2port, int enable) 284 { 285 u8 data; 286 287 /* now enable/disable the port */ 288 scoped_guard(spinlock_irqsave, &ps2port->lock) { 289 gscps2_flush(ps2port); 290 data = gscps2_readb_control(ps2port->addr); 291 if (enable) 292 data |= GSC_CTRL_ENBL; 293 else 294 data &= ~GSC_CTRL_ENBL; 295 gscps2_writeb_control(data, ps2port->addr); 296 } 297 298 wait_TBE(ps2port->addr); 299 gscps2_flush(ps2port); 300 } 301 302 /* 303 * gscps2_reset() - resets the PS/2 port 304 */ 305 306 static void gscps2_reset(struct gscps2port *ps2port) 307 { 308 /* reset the interface */ 309 guard(spinlock_irqsave)(&ps2port->lock); 310 gscps2_flush(ps2port); 311 writeb(0xff, ps2port->addr + GSC_RESET); 312 gscps2_flush(ps2port); 313 } 314 315 static LIST_HEAD(ps2port_list); 316 317 static void gscps2_read_data(struct gscps2port *ps2port) 318 { 319 u8 status; 320 321 do { 322 status = gscps2_readb_status(ps2port->addr); 323 if (!(status & GSC_STAT_RBNE)) 324 break; 325 326 ps2port->buffer[ps2port->append].str = status; 327 ps2port->buffer[ps2port->append].data = 328 gscps2_readb_input(ps2port->addr); 329 ps2port->append = (ps2port->append + 1) & BUFFER_SIZE; 330 } while (true); 331 } 332 333 static bool gscps2_report_data(struct gscps2port *ps2port) 334 { 335 unsigned int rxflags; 336 u8 data, status; 337 338 while (ps2port->act != ps2port->append) { 339 /* 340 * Did new data arrived while we read existing data ? 341 * If yes, exit now and let the new irq handler start 342 * over again. 343 */ 344 if (gscps2_readb_status(ps2port->addr) & GSC_STAT_CMPINTR) 345 return true; 346 347 status = ps2port->buffer[ps2port->act].str; 348 data = ps2port->buffer[ps2port->act].data; 349 350 ps2port->act = (ps2port->act + 1) & BUFFER_SIZE; 351 rxflags = ((status & GSC_STAT_TERR) ? SERIO_TIMEOUT : 0 ) | 352 ((status & GSC_STAT_PERR) ? SERIO_PARITY : 0 ); 353 354 serio_interrupt(ps2port->port, data, rxflags); 355 } 356 357 return false; 358 } 359 360 /** 361 * gscps2_interrupt() - Interruption service routine 362 * @irq: interrupt number which triggered (unused) 363 * @dev: device pointer (unused) 364 * 365 * This function reads received PS/2 bytes and processes them on 366 * all interfaces. 367 * The problematic part here is, that the keyboard and mouse PS/2 port 368 * share the same interrupt and it's not possible to send data if any 369 * one of them holds input data. To solve this problem we try to receive 370 * the data as fast as possible and handle the reporting to the upper layer 371 * later. 372 */ 373 374 static irqreturn_t gscps2_interrupt(int irq, void *dev) 375 { 376 struct gscps2port *ps2port; 377 378 list_for_each_entry(ps2port, &ps2port_list, node) { 379 guard(spinlock_irqsave)(&ps2port->lock); 380 381 gscps2_read_data(ps2port); 382 } /* list_for_each_entry */ 383 384 /* all data was read from the ports - now report the data to upper layer */ 385 list_for_each_entry(ps2port, &ps2port_list, node) { 386 if (gscps2_report_data(ps2port)) { 387 /* More data ready - break early to restart interrupt */ 388 break; 389 } 390 } 391 392 return IRQ_HANDLED; 393 } 394 395 396 /* 397 * gscps2_write() - send a byte out through the aux interface. 398 */ 399 400 static int gscps2_write(struct serio *port, unsigned char data) 401 { 402 struct gscps2port *ps2port = port->port_data; 403 404 if (!gscps2_writeb_output(ps2port, data)) { 405 printk(KERN_DEBUG PFX "sending byte %#x failed.\n", data); 406 return -1; 407 } 408 return 0; 409 } 410 411 /* 412 * gscps2_open() is called when a port is opened by the higher layer. 413 * It resets and enables the port. 414 */ 415 416 static int gscps2_open(struct serio *port) 417 { 418 struct gscps2port *ps2port = port->port_data; 419 420 gscps2_reset(ps2port); 421 422 /* enable it */ 423 gscps2_enable(ps2port, ENABLE); 424 425 gscps2_interrupt(0, NULL); 426 427 return 0; 428 } 429 430 /* 431 * gscps2_close() disables the port 432 */ 433 434 static void gscps2_close(struct serio *port) 435 { 436 struct gscps2port *ps2port = port->port_data; 437 gscps2_enable(ps2port, DISABLE); 438 } 439 440 /** 441 * gscps2_probe() - Probes PS2 devices 442 * @dev: pointer to parisc_device struct which will be probed 443 * 444 * @return: success/error report 445 */ 446 447 static int __init gscps2_probe(struct parisc_device *dev) 448 { 449 struct gscps2port *ps2port; 450 struct serio *serio; 451 unsigned long hpa = dev->hpa.start; 452 int ret; 453 454 if (!dev->irq) 455 return -ENODEV; 456 457 /* Offset for DINO PS/2. Works with LASI even */ 458 if (dev->id.sversion == 0x96) 459 hpa += GSC_DINO_OFFSET; 460 461 ps2port = kzalloc_obj(*ps2port); 462 serio = kzalloc_obj(*serio); 463 if (!ps2port || !serio) { 464 ret = -ENOMEM; 465 goto fail_nomem; 466 } 467 468 dev_set_drvdata(&dev->dev, ps2port); 469 470 ps2port->port = serio; 471 ps2port->padev = dev; 472 ps2port->addr = ioremap(hpa, GSC_STATUS + 4); 473 if (!ps2port->addr) { 474 ret = -ENOMEM; 475 goto fail_nomem; 476 } 477 spin_lock_init(&ps2port->lock); 478 479 gscps2_reset(ps2port); 480 ps2port->id = readb(ps2port->addr + GSC_ID) & 0x0f; 481 482 snprintf(serio->name, sizeof(serio->name), "gsc-ps2-%s", 483 (ps2port->id == GSC_ID_KEYBOARD) ? "keyboard" : "mouse"); 484 strscpy(serio->phys, dev_name(&dev->dev), sizeof(serio->phys)); 485 serio->id.type = SERIO_8042; 486 serio->write = gscps2_write; 487 serio->open = gscps2_open; 488 serio->close = gscps2_close; 489 serio->port_data = ps2port; 490 serio->dev.parent = &dev->dev; 491 492 ret = -EBUSY; 493 if (request_irq(dev->irq, gscps2_interrupt, IRQF_SHARED, ps2port->port->name, ps2port)) 494 goto fail_miserably; 495 496 if (ps2port->id != GSC_ID_KEYBOARD && ps2port->id != GSC_ID_MOUSE) { 497 printk(KERN_WARNING PFX "Unsupported PS/2 port at 0x%08lx (id=%d) ignored\n", 498 hpa, ps2port->id); 499 ret = -ENODEV; 500 goto fail; 501 } 502 503 #if 0 504 if (!request_mem_region(hpa, GSC_STATUS + 4, ps2port->port.name)) 505 goto fail; 506 #endif 507 508 if (ps2port->id == GSC_ID_KEYBOARD) { 509 ret = device_add_software_node(&serio->dev, 510 &gscps2_keyboard_node); 511 if (ret) { 512 dev_err(&dev->dev, 513 "failed to add software node for keyboard: %d\n", 514 ret); 515 goto fail; 516 } 517 } 518 519 pr_info("serio: %s port at 0x%08lx irq %d @ %s\n", 520 ps2port->port->name, 521 hpa, 522 ps2port->padev->irq, 523 ps2port->port->phys); 524 525 serio_register_port(ps2port->port); 526 527 list_add_tail(&ps2port->node, &ps2port_list); 528 529 return 0; 530 531 fail: 532 if (ps2port->id == GSC_ID_KEYBOARD) 533 device_remove_software_node(&serio->dev); 534 535 free_irq(dev->irq, ps2port); 536 537 fail_miserably: 538 iounmap(ps2port->addr); 539 #if 0 540 release_mem_region(dev->hpa.start, GSC_STATUS + 4); 541 #endif 542 543 fail_nomem: 544 kfree(ps2port); 545 kfree(serio); 546 return ret; 547 } 548 549 /** 550 * gscps2_remove() - Removes PS2 devices 551 * @dev: pointer to parisc_device which shall be removed 552 * 553 * @return: success/error report 554 */ 555 556 static void __exit gscps2_remove(struct parisc_device *dev) 557 { 558 struct gscps2port *ps2port = dev_get_drvdata(&dev->dev); 559 560 if (ps2port->id == GSC_ID_KEYBOARD) 561 device_remove_software_node(&ps2port->port->dev); 562 563 serio_unregister_port(ps2port->port); 564 free_irq(dev->irq, ps2port); 565 gscps2_flush(ps2port); 566 list_del(&ps2port->node); 567 iounmap(ps2port->addr); 568 #if 0 569 release_mem_region(dev->hpa, GSC_STATUS + 4); 570 #endif 571 dev_set_drvdata(&dev->dev, NULL); 572 kfree(ps2port); 573 } 574 575 576 static const struct parisc_device_id gscps2_device_tbl[] __initconst = { 577 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00084 }, /* LASI PS/2 */ 578 #ifdef DINO_TESTED 579 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00096 }, /* DINO PS/2 */ 580 #endif 581 { 0, } /* 0 terminated list */ 582 }; 583 MODULE_DEVICE_TABLE(parisc, gscps2_device_tbl); 584 585 static struct parisc_driver parisc_ps2_driver __refdata = { 586 .name = "gsc_ps2", 587 .id_table = gscps2_device_tbl, 588 .probe = gscps2_probe, 589 .remove = __exit_p(gscps2_remove), 590 }; 591 592 static int __init gscps2_init(void) 593 { 594 int error; 595 596 error = software_node_register(&gscps2_keyboard_node); 597 if (error) 598 return error; 599 600 error = register_parisc_driver(&parisc_ps2_driver); 601 if (error) 602 software_node_unregister(&gscps2_keyboard_node); 603 604 return error; 605 } 606 607 static void __exit gscps2_exit(void) 608 { 609 unregister_parisc_driver(&parisc_ps2_driver); 610 software_node_unregister(&gscps2_keyboard_node); 611 } 612 613 614 module_init(gscps2_init); 615 module_exit(gscps2_exit); 616