PSM(4)

NAME
psm - PS/2 mouse style pointing device driver

SYNOPSIS
options PSM_CHECKSYNC
options "PSM_ACCEL=N"
options "KBD_RESETDELAY=N"
options "KBD_MAXWAIT=N"
options "PSM_DEBUG=N"
options "KBDIO_DEBUG=N"
device psm0 at isa? port "IO_KBD" conflicts tty irq 12 vector psmintr

DESCRIPTION
The psm driver provides support for the PS/2 mouse style pointing device. port "IO_KBD" and conflicts are required, as the PS/2 mouse port is located at the auxiliary port of the keyboard controller, thus, the psm driver has to share the same I/O ports with the keyboard driver. Note also that there is currently no provision of changing the irq number.

A series of data packets is read from the psm driver. A data packet from the PS/2 mouse style pointing device is three bytes long:

Byte 1
    bit 7
        One indicates overflow in the vertical movement count.
    bit 6
        One indicates overflow in the horizontal movement count.
    bit 5
        Set if the vertical movement count is negative.
    bit 4
        Set if the horizontal movement count is negative.
    bit 3
        The ALPS GlidePoint clears this bit when the user `taps' the surface of the pad, otherwise the bit is set. Most, if not all, other devices always sets this bit.
    bit 2
        Middle button status; set if pressed. For devices without the middle button, this bit seems to be always zero.
    bit 1
        Right button status; set if pressed.
    bit 0
        Left button status; set if pressed.
Byte 2
    Horizontal movement count in two's compliment; -256 through 255. Note that the sign bit is in the first byte.
Byte 3
    Vertical movement count in two's compliment; -256 through 255. Note that the sign bit is in the first byte.

The minor device number of the psm is made up of:

    minor = (`unit' << 1) | `non-blocking'

where `unit' is the device number (usually 0) and the `non-blocking' bit is set to indicate ``don't block waiting for mouse input, return immediately''. The `non-blocking' bit should be set for XFree86, therefore the minor device number usually used for XFree86 is 1. See FILES for device node names.

KERNEL CONFIGURATION
There are following options to control the psm driver.

PSM_CHECKSYNC
    If this option is defined, the driver tries to detect the first byte of the three-byte data packet, by checking the bit pattern of that byte. This may be useful if you often experience wierd mouse movement cased by unsynchronization between the application program and the mouse. However, the PSM_CHECKSYNC code may not always work; some systems, mostly notebooks, set the bit pattern differently from the others. Note also that the `tapping' feature of the ALPS GlidePoint will be lost when this option is used.

PSM_ACCEL=N
    The psm driver can somewhat `accelerate' the movement of the pointing device. That is, the faster you move the device, the further the pointer travels on the screen. This option controls the amount of acceleration. The smaller N is, more sensitive the movement becomes. The minimum value allowed, thus the value for the most sensitive setting, is 1. Setting this option to zero will completely disables the acceleration effect. The default value is 0 (acceleration disabled). The acceleration effect can also be controlled via the ioctl() command MOUSE_SETMODE.

KBD_RESETDELAY=X, KBD_MAXWAIT=Y
    The psm driver will attempt to reset the pointing device during the boot process. It sometimes takes a long while before the device will respond after reset. These options control how long the driver should wait before it eventually gives up waiting. The driver will wait X * Y msecs at most. If the driver seems unable to detect your pointing device, you may want to increase these values. The default values are 200 msec for X and 5 for Y.

PSM_DEBUG=N, KBDIO_DEBUG=N
    Sets the debug level to N. The default debug level is zero. See DIAGNOSTICS for debug logging.

IOCTL
There are only few ioctls for the psm driver. These are defined in <machine/mouse.h>.

MOUSEIOCREAD
    The MOUSEIOCREAD command did NOT work before and does NOT work now. It is obsolete. Use the MOUSE_GETSTATE command instead.

MOUSE_GETSTATE
    The command returns the current mouse state in the following structure and remove the state information from the internal queue.

        typedef struct mousestatus {
            int button;     /* button status */
            int obutton;    /* previous button status */
            int dx;         /* x movement */
            int dy;         /* y movement */
        } mousestatus_t;

    The button and the obutton fields hold the current and the previous state of the mouse buttons. When a button is pressed, the corresponding bit is set. These bits are defined as MOUSE_BUTTON1DOWN through MOUSE_BUTTON8DOWN. The first three buttons are left, middle and right buttons.

    Note that this command and read() operation on the psm driver uses the same internal queue. Therefore, interleaving the MOUSE_GETSTATE command and read() operation is not recommended.

MOUSE_GETINFO
    Returns the hardware information in the following structure.

        typedef struct mousehw {
            int buttons;    /* number of buttons */
            int iftype;     /* I/F type */
            int type;       /* mouse/track ball/pad... */
            int hwid;       /* I/F dependent hardware ID */
        } mousehw_t;

    The iftype is MOUSE_IF_PS2 for the psm driver. The type tells the device type: MOUSE_MOUSE, MOUSE_TRACKBALL, MOUSE_STICK, MOUSE_PAD, or MOUSE_UNKNOWN. The user should not heavily rely on this field, as the psm driver may not always, in fact it is very rarely able to, identify the device type. The hwid is the ID value returned by the pointing device. Known IDs include:
    0   Mouse (Microsoft, Logitech and many other manufacturers)
    2   Microsoft Ballpoint mouse

MOUSE_GETMODE, MOUSE_SETMODE
    The commands get and set the operation mode of the psm driver.

        typedef struct mousemode {
            int protocol;    /* MOUSE_PROTO_XXX */
            int rate;        /* report rate (per sec), -1 if unknown */
            int resolution;  /* 1:low, 2:medium low, 3:medium high
                              * 4:high, 0: default, -1 if unknown
                              */
            int accelfactor; /* acceleration factor (must be 1 or greater) */
        } mousemode_t;

    The protocol selects the format with which the device status is returned by read(). The default is MOUSE_PROTO_PS2, that is, the data byte from the pointing device is read by user programs as is. No other value is allowed at the moment.

    The rate is the status report rate (reports/sec) at which the device will send movement report to the host computer.

    The resolution of the pointing device must be zero through four. The higher the value is, the finer resolution the mouse will select. Zero selects the default resolution.

    The accelfactor holds a value to control acceleration feature (see description on PSM_ACCEL above). It must be zero or greater. If it is zero, acceleration is disabled.

DIAGNOSTICS

At debug level 0, little information is logged except for the following line during boot process:

    psm0: device ID X

where X the device ID code returned by the found pointing device. See MOUSE_GETINFO for known IDs.

At debug level 1 more information will be logged while the driver probes the auxiliary port (mouse port). Messages are logged with the LOG_KERN facility at the LOG_DEBUG level. (See syslogd(8).)

    psm0: current command byte:xxxx
    kbdio: new command byte:yyyy (set_controller...)
    kbdio: TEST_AUX_PORT status:0000
    kbdio: RESET_AUX return code:00fa
    kbdio: RESET_AUX status:00aa
    kbdio: RESET_AUX ID:0000
    psm0: status after reset 00 02 64
    psm: device ID: X
    psm: status xx yy zz (get_mouse_buttons)
    psm0: status 00 02 64
    kbdio: new command byte:zzzz (set_controller...)
    psm0 at 0x60-0x64 irq 12 on motherboard
    psm0: device ID X, N buttons

The first line shows the command byte value of the keyboard controller just before the auxiliary port is probed. It usually is 4D, 45, 47 or 65, depending on how the motherboard BIOS initialized the keyboard controller upon power-up.

The third line shows the result of the keyboard controller's test on the auxiliary port interface, with zero indicating no error; note that some controllers report no error even if the port does not exist in the system, however.

The forth to sixth lines show the reset status of the pointing device. The functioning device should return the sequence of FA AA <ID>. The ID code is described above.

The tenth line shows the current hardware settings; it consists of three bytes:

Byte 1
    bit 7
        Reserved.
    bit 6
        0 - stream mode, 1 - remote mode. In the stream mode, the pointing device sends the device status whenever its state changes. In the remote mode, the host computer must request the status to be sent.
    bit 5
        Set if the pointing device is currently enabled. Otherwise zero.
    bit 4
        0 - 1:1 scaling, 1 - 2:1 scaling.
    bit 3
        Reserved.
    bit 2
        Left button status; set if pressed.
    bit 1
        Middle button status; set if pressed.
    bit 0
        Right button status; set if pressed.
Byte 2
    bit 7
        Reserved.
    bit 6-0
        Resolution code: zero through three. The higher the number is, the finer resolution the device has. Actual resolution for the resolution code varies from one device to another. The typical values are:
        0   25 pulse per inch (ppi)
        1   50 ppi
        2   100 ppi
        3   200 ppi
Byte 3
    The status report rate (reports/sec) at which the device will send movement report to the host computer.

Note that the pointing device will not be enabled until the psm driver is opened by the user programs.

The last line shows the device ID code and the number of detected buttons. Currently the psm driver can detect the 3 button mouse from Logitech and report accordingly. The 3 button mouse from the other manufacturer may or may not be reported correctly. However, it will not affect the operation of the driver.

At debug level 2, much more detailed information is logged.

FILES
/dev/psm0
    `non-blocking' device node in the system without devfs, `blocking' under devfs.
/dev/npsm0
    `non-blocking' device node under devfs.

CAVEATS
There is not a guaranteed way to re-synchronize with the first byte of the packet once we are out of synchronization with the data stream. However, if you are using the XFree86 server and experiencing the problem, you may be able to make the X server synchronize with the mouse by switching away to a virtual terminal and getting back to the X server, unless the X server is accessing the mouse via moused(1). If you have specified the PSM_CHECKSYNC option, clicking any button without moving the mouse may also work.

BUGS
The ioctl() command MOUSEIOCREAD (see IOCTL above) was never functional and will not be. The command name still remains for compatibility reasons but may be removed in the future.

SEE ALSO
moused(1), syslog(3), mse(4), syslogd(8)