Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S266418AbUAIGue (ORCPT ); Fri, 9 Jan 2004 01:50:34 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S266420AbUAIGue (ORCPT ); Fri, 9 Jan 2004 01:50:34 -0500 Received: from colo.lackof.org ([198.49.126.79]:32923 "EHLO colo.lackof.org") by vger.kernel.org with ESMTP id S266418AbUAIGuF (ORCPT ); Fri, 9 Jan 2004 01:50:05 -0500 Date: Thu, 8 Jan 2004 23:50:01 -0700 From: Grant Grundler To: marcelo.tosatti@cyclades.com Cc: rubini@linux.it, linux-kernel@vger.kernel.org, omnibook@zurich.ai.mit.edu Subject: Re: [PATCH] 2.4.24-pre3 obmouse driver for HP OB600 C/CT laptop Message-ID: <20040109065001.GB5393@colo.lackof.org> References: <20040105052059.GA612@colo.lackof.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040105052059.GA612@colo.lackof.org> User-Agent: Mutt/1.3.28i X-Home-Page: http://www.parisc-linux.org/ Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 14108 Lines: 434 On Sun, Jan 04, 2004 at 10:20:59PM -0700, Grant Grundler wrote: > Over Christmas break I got obmouse driver working with XF86 4.2.x and > properly integrated into the linux-2.4 kernel tree. At Helge Deller's suggestion, I converted obmouse to use /dev/input instead of busmouse support. v0.7 obmouse.c patch appended below. Works with 2.4.25-pre4 fine. Marcelo, can you please include obmouse driver patch? Documentation/Configure.help | 10 MAINTAINERS | 6 drivers/char/Config.in | 1 drivers/char/Makefile | 1 drivers/char/obmouse.c | 321 ++++++++++++++++++++++++++++++ 6 files changed, 342 insertions(+), 3 deletions(-) I've added myself to MAINTAINERS. Fixed some typos in input-programming.txt. The rest is new driver and integration. > A minor number needs to be officially assigned/blessed and entered > into Documentation/devices.txt. Whee! Not a problem anymore. :^) > Also, one "unfixable" bug is the lack of a probe routine. > Without documentation, I have no clue if it's possible to probe for > a pop-up mouse or not. Maybe it will be obvious to someone else based > on the 4 defined registers. Still a problem. :^( > XF86Config-4 file and prebuilt 2.4.24-preX kernel bits suitable for > OB600CT (486, 75Mhz, 24MB RAM) are available from: > ftp://gsyprf10.external.hp.com/kernels/ob600/ 2.4.25-pre4.tgz is now available which includes obmouse v0.7. thanks, grant diff -Nur --exclude=RCS --exclude=CVS --exclude=SCCS --exclude=BitKeeper --exclude=ChangeSet linux-2.4/Documentation/Configure.help input-linux-2.4/Documentation/Configure.help --- linux-2.4/Documentation/Configure.help Thu Jan 8 08:03:01 2004 +++ input-linux-2.4/Documentation/Configure.help Thu Jan 8 08:10:53 2004 @@ -14879,6 +14879,16 @@ If unsure, say Y. +HP OB600 C/CT Pop-Up Mouse +CONFIG_OBMOUSE + Only add this driver if you have an Omnibook 600C or 600CT laptop. + This driver has no probe routine and must assume ports 0x238-23b + belong to the Pop-Up mouse. Depends on CONFIG_INPUT_MOUSEDEV. + + Best is to use a module and load the obmouse driver at runtime. + Say M here and read . + + Input core support CONFIG_INPUT Say Y here if you want to enable any of the following options for diff -Nur --exclude=RCS --exclude=CVS --exclude=SCCS --exclude=BitKeeper --exclude=ChangeSet linux-2.4/MAINTAINERS input-linux-2.4/MAINTAINERS --- linux-2.4/MAINTAINERS Sun Jan 4 18:22:45 2004 +++ input-linux-2.4/MAINTAINERS Thu Jan 8 21:47:10 2004 @@ -436,6 +436,12 @@ L: iss_storagedev@hp.com S: Odd Fixes +HP OMNIBOOK 600 C/CT POP-UP MOUSE DRIVER +P: Grant Grundler +M: grundler@parisc-linux.org +L: omnibook@zurich.ai.mit.edu +S: Maintained + HP SMART2 RAID DRIVER P: Francis Wiran diff -Nur --exclude=RCS --exclude=CVS --exclude=SCCS --exclude=BitKeeper --exclude=ChangeSet linux-2.4/drivers/char/Config.in input-linux-2.4/drivers/char/Config.in --- linux-2.4/drivers/char/Config.in Sun Jan 4 18:23:06 2004 +++ input-linux-2.4/drivers/char/Config.in Thu Jan 8 08:20:09 2004 @@ -399,6 +399,7 @@ if [ "$CONFIG_X86" = "y" ]; then tristate 'ACP Modem (Mwave) support' CONFIG_MWAVE + dep_tristate 'HP OB600 C/CT Pop-up mouse support' CONFIG_OBMOUSE $CONFIG_INPUT_MOUSEDEV fi endmenu diff -Nur --exclude=RCS --exclude=CVS --exclude=SCCS --exclude=BitKeeper --exclude=ChangeSet linux-2.4/drivers/char/Makefile input-linux-2.4/drivers/char/Makefile --- linux-2.4/drivers/char/Makefile Sun Jan 4 18:23:06 2004 +++ input-linux-2.4/drivers/char/Makefile Thu Jan 8 11:38:20 2004 @@ -228,6 +228,7 @@ obj-$(CONFIG_LOGIBUSMOUSE) += logibusmouse.o obj-$(CONFIG_PRINTER) += lp.o obj-$(CONFIG_TIPAR) += tipar.o +obj-$(CONFIG_OBMOUSE) += obmouse.o ifeq ($(CONFIG_INPUT),y) obj-y += joystick/js.o diff -Nur --exclude=RCS --exclude=CVS --exclude=SCCS --exclude=BitKeeper --exclude=ChangeSet linux-2.4/drivers/char/obmouse.c input-linux-2.4/drivers/char/obmouse.c --- linux-2.4/drivers/char/obmouse.c Wed Dec 31 16:00:00 1969 +++ input-linux-2.4/drivers/char/obmouse.c Thu Jan 8 21:40:20 2004 @@ -0,0 +1,321 @@ +/* obmouse.c -- HP omnibook 600C/CT pop-up mouse driver + * + * Copyright (C) 1999 Olivier Florent + * Copyright (C) 1999 Chuck Slivkoff + * Copyright (C) 1999-2004 Grant Grundler + * + * OB600C/CT mouse can be compared to a tablet, as absolute coordinates + * are given by the hardware. This driver emulates a basic serial mouse + * protocol by translating absolute coordinates to relative moves. + * This works with gpm -t pnp and Xfree86 as a standard Micro$oft mouse. + * + * FIXME: This driver lacks a detection routine. + * i.e you must know that you have a 600C/CT before using it. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + * 0.7 January 2004 grant + * convert to /dev/input + * + * 0.6 2 January 2004 grant + * converted to busmouse + * + * 0.5 27 december 2003 grant + * fix "built-in" code - added module_* calls + * + * 0.4 27 december 2002 grant grundler + * Add MODULES_ stuff (author, license, etc) + * fix read to return 0 if no change. + * + * 0.3 26 november 1999 grant grundler + * removed ifdefs for EMULATE_SERIAL_MOUSE and EMULATE_NCR_PEN. + * Only support "basic serial mouse protocol (gpm -t pnp)" which + * is also supported directly by Xfree. + * + * Moved delta(x,y) calculations into ob_interrupt. + * If we only get interrupts when the mouse moves, + * then only need to update delta(x,y) then too. + * + * 0.2 22 november 1999, grant grundler + * "man 4 mouse" explains really well how PNP mouse works. Read it. + * + * Fixed algorithm which generated delta(x,y) from current-last + * position reported. Now handles "roll-over" properly and + * speed scales _inversely_ (ie bigger number is slower). + * "speed" parameter can be set with "insmod obmouse speed=5" (default). + * + * 0.1a 16 november 1999, charles_slivkoff_at_hp.com + * File did not compile as received. + * Modified ob_write,ob_read parameters to match 2.2.x kernel. + * Added uaccess.h. Tried to fix ob_interrupt. + * + * 0.1 17 february 1999, olivier_florent_AT_hp.com + * original author. + */ + +#include + +#include +#include +#include +#include +#include + +#include +#include + +#undef OBMOUSE_DEBUG /* define to enable lots of printf */ + +#define OBMOUSE_NAME "HP omnibook 600C/CT pop-up mouse" +#define OBMOUSE_DEV_NAME "obmouse" +#define OBMOUSE_VERSION "v0.7" + + +/* +** "speed" of the mouse. Determines how "fast" the mouse "moves". +** Similar (but not the same) as acceleration. Using slower acceleration +** together with lower speed value might result in better mouse control. +** I've only used the default acceleration. +*/ +int speed = 4; /* my personal preference */ + +/* +** OB 600 mouse doesn't completely act like a tablet. +** The xy-coordinates do in fact roll over which would +** not happen on a tablet. +*/ +#define OB_ROLL_LIMIT 0xd00 + +/* +** obmouse HW specific data +*/ +#define OBMOUSE_BASE (0x238) /* base address of the hardware */ +#define OBMOUSE_EXTENT (3) /* from 0x238 to 0x23b */ +#define OBMOUSE_IRQ (12) /* irq 12 */ + +/* The 4 high bits of OBMOUSE_INTR_CTL */ +#define OBMOUSE_BTN_IRQ_MASK (0x10) /* WR: enable/disable button irq */ +#define OBMOUSE_MOV_IRQ_MASK (0x20) /* WR: enable/disable movement irq */ +#define OBMOUSE_BUTTON1_MASK (0x40) /* RD: status of button 1 */ +#define OBMOUSE_BUTTON2_MASK (0x80) /* RD: status of button 2 */ + +#define OBMOUSE_COORD_ONLY(v) ((v) & 0xfff) /* ignore high 4 bits */ + +#define OBMOUSE_INTR_CTL (OBMOUSE_BASE+3) +#define OBMOUSE_INTR_BITS (OBMOUSE_BTN_IRQ_MASK | OBMOUSE_MOV_IRQ_MASK) + +/* Enable/disable both button and movement interrupt */ +#define OBMOUSE_ENABLE_INTR() outb(OBMOUSE_INTR_BITS, OBMOUSE_INTR_CTL) +#define OBMOUSE_DISABLE_INTR() outb(~OBMOUSE_INTR_BITS, OBMOUSE_INTR_CTL) + +/* Amount mouse has to move before the hardware launchs a new +** interrupt (I think). 0x08 is the standard value. +** Write value to OBMOUSE_BASE each time an interrupt is handled to +** enable the next one. +*/ +#define OBMOUSE_SENSITIVITY (0x08) + +/* reset the sensitivity to enable next interrupt */ +#define OBMOUSE_ENABLE_SENSE() outb(OBMOUSE_SENSITIVITY,OBMOUSE_BASE) +#define OBMOUSE_DISABLE_SENSE() outb(0,OBMOUSE_BASE) + + +static unsigned short lastx; /* last reported normalized coords */ +static unsigned short lasty; +static unsigned char ob_opened = 0; /* 0=closed, 1=opened */ +static struct input_dev obdev; + + +/* +** Omnibook 600 mouse ISR. +** Read the HW state and resets "SENSITIVITY" in order to re-arm +** the interrupt. +*/ +static void +ob_interrupt(int irq, void *dev_id, struct pt_regs *regs) +{ + short dx, dy; + unsigned short rawx, rawy; + + rawx = inb(OBMOUSE_BASE+0) + (inb(OBMOUSE_BASE+1) << 8); + rawy = inb(OBMOUSE_BASE+2) + (inb(OBMOUSE_BASE+3) << 8); + +#ifdef OBMOUSE_DEBUG +/* This printk is really useful for learning how the mouse actually behaves. */ +printk("ob_intr: %4x,%4x\n", rawx, rawy); +#endif + + /* reset the sensitivity */ + OBMOUSE_ENABLE_SENSE(); + + /* ------------------------------------ + ** update delta(x,y) values. + ** ------------------------------------ + */ + dx = (short) rawx - (short) lastx ; + lastx = rawx; + + { + register unsigned short coordY = OBMOUSE_COORD_ONLY(rawy); + dy = (short) coordY - (short) lasty ; + lasty = coordY; + } + + /* + ** determine if the reading "rolled" over. + ** Not fool-proof but should be good enough. + */ + if (dx > OB_ROLL_LIMIT) { + /* 0xf80 - 0x80 = 0xf00 (and we want 0x100) */ + dx = 0x1000 - dx; + } else if (-dx > OB_ROLL_LIMIT) { + /* + ** 0x80 - 0xf80 = -0xf00 (and we want -0x100) + ** -0x1000 - (-0xf00) = -0x1000 + 0xf00 = -0x100 + */ + dx = -0x1000 - dx; + } + + /* Same story with the Y-coordinate */ + if ( dy > OB_ROLL_LIMIT) dy = 0x1000 - dy; + else if (-dy > OB_ROLL_LIMIT) dy = -0x1000 - dy; + + dx /= speed; /* scale */ + dy /= speed; + + rawy = ~rawy; /* invert mouse buttons */ + input_report_key(&obdev, BTN_LEFT, (rawy & 0x8000)); + input_report_key(&obdev, BTN_RIGHT, (rawy & 0x4000)); + + /* obmouse acts like a table *EXCEPT* for the "roll-over". */ + if (dx) input_report_rel(&obdev, REL_X, -dx); + if (dy) input_report_rel(&obdev, REL_Y, dy); +} + + +static int ob_open(struct input_dev *dev) +{ + /* device is already opened */ + if (ob_opened) + return -EBUSY; + +#ifdef OBMOUSE_DEBUG +printk(OBMOUSE_DEV_NAME ": attempt request irq %d\n",OBMOUSE_IRQ); +#endif + + /* Try to get the interrupt */ + if (request_irq(OBMOUSE_IRQ,ob_interrupt,0,OBMOUSE_DEV_NAME,NULL)) { + printk (OBMOUSE_DEV_NAME ": request_irq failed for %d\n",OBMOUSE_IRQ); + return -EBUSY; + } + +#ifdef OBMOUSE_DEBUG +printk(OBMOUSE_DEV_NAME ": irq %d registered\n",OBMOUSE_IRQ); +#endif + + OBMOUSE_ENABLE_INTR() ; + OBMOUSE_ENABLE_SENSE() ; + + MOD_INC_USE_COUNT; + ob_opened = 1 ; + return 0; +} + + +void ob_close(struct input_dev *dev) +{ + /* device has never been opened */ + if (!ob_opened) + return; + + OBMOUSE_DISABLE_INTR() ; + free_irq(OBMOUSE_IRQ, NULL); + + MOD_DEC_USE_COUNT; + ob_opened = 0 ; +} + + +#ifndef MODULE +static int __init obmouse_setup(char *str) +{ + int ints[4]; + + str = get_options(str, ARRAY_SIZE(ints), ints); + if (ints[0] > 0) + speed=ints[1]; + + return 1; +} + +__setup("speed=", obmouse_setup); +#endif /* !MODULE */ + + +static int obmouse_init(void) +{ + /* Get the IO Port region first */ + if (request_region(OBMOUSE_BASE,OBMOUSE_EXTENT,OBMOUSE_DEV_NAME) < 0) { + printk(KERN_ERR OBMOUSE_DEV_NAME ": IO Port 0x%d not available!\n", OBMOUSE_BASE); + return -ENODEV; + + } + + OBMOUSE_DISABLE_INTR() ; + OBMOUSE_DISABLE_SENSE() ; + + memset(&obdev, 0, sizeof(obdev)); + + obdev.name = OBMOUSE_NAME " " OBMOUSE_VERSION; + obdev.idbus = BUS_ISA; + obdev.idvendor = 0x103c; /* PCI_VENDOR_ID_HP */ + obdev.idproduct = 0x0001; + obdev.idversion = 0x0100; + + obdev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL); + obdev.keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT); + obdev.relbit[0] = BIT(REL_X) | BIT(REL_Y); + obdev.open = ob_open; + obdev.close = ob_close; + + input_register_device(&obdev); + printk( OBMOUSE_NAME " " OBMOUSE_VERSION + " (0x%x, IRQ %d), Grant Grundler\n", OBMOUSE_BASE, OBMOUSE_IRQ); + + return 0; +} + +static void obmouse_exit(void) +{ + OBMOUSE_DISABLE_INTR() ; + OBMOUSE_DISABLE_SENSE() ; + + input_unregister_device(&obdev); + release_region(OBMOUSE_BASE,OBMOUSE_EXTENT); + printk(OBMOUSE_DEV_NAME ": closed\n"); +} + +module_init(obmouse_init); +module_exit(obmouse_exit); + +EXPORT_NO_SYMBOLS; + +MODULE_AUTHOR("Grant Grundler "); +MODULE_DESCRIPTION(OBMOUSE_NAME); +MODULE_PARM(speed, "i"); +MODULE_PARM_DESC(speed, "obmouse speed (not accel) control"); +MODULE_LICENSE("GPL"); - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/