msm.c revision 613b28719c10e84c1202c1045df44d77767de21d
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Microsoft Bus Mouse Module - Streams
*/
/*
*
* Local Static Data
*
*/
#define MSM_MAXUNIT 1
static struct driver_minor_data {
char *name;
int minor;
int type;
} msm_minor_data[] = {
{"l", 0, S_IFCHR},
{0}
};
int msmdevflag = 0;
int msm_debug = 0;
/*
* static struct strmseinfo *msmptr = 0;
*/
static char mousepresent;
static char mouseinuse;
static char mousemode;
static char mousestatus;
int mouse_base = 0x23c;
void **result);
char msmclosing = 0;
static int xmotion, /* current position and .. */
ymotion; /* button status, used .. */
/*
* Local Function Declarations
*/
struct cb_ops msm_cb_ops = {
nodev, /* open */
nodev, /* close */
nodev, /* strategy */
nodev, /* print */
nodev, /* dump */
nodev, /* read */
nodev, /* write */
nodev, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
ddi_prop_op, /* cb_prop_op */
(&msm_info), /* streamtab */
};
DEVO_REV, /* devo_rev, */
0, /* refcnt */
msminfo, /* info */
nulldev, /* identify */
msmprobe, /* probe */
msmattach, /* attach */
msmdetach, /* detach */
nodev, /* reset */
&msm_cb_ops, /* driver operations */
(struct bus_ops *)0 /* bus operations */
};
/*
* Module linkage information for the kernel.
*/
&mod_driverops, /* Type of module. This one is a driver */
"Microsoft Mouse driver",
&msm_ops, /* driver ops */
};
static struct modlinkage modlinkage = {
&modldrv,
};
/*
* This is the driver initialization routine.
*/
int
_init(void)
{
int rv;
return (rv);
}
#ifdef SUNDEV
int
_fini(void)
{
return (EBUSY);
}
#else
int
_fini(void)
{
return (mod_remove(&modlinkage));
}
extern struct modctl *mod_getctl();
extern char *kobj_getmodname();
#endif
int
{
}
static int
{
int unit;
#ifdef MSM_DEBUG
if (msm_debug) {
PRF("msmprobe: entry\n");
}
#endif
#ifdef MSM_DEBUG
if (msm_debug)
#endif
return (DDI_PROBE_FAILURE);
}
/*ARGSUSED*/
static int
{
int unit;
struct driver_minor_data *dmdp;
struct strmseinfo *msmptr = 0;
#ifdef MSM_DEBUG
if (msm_debug) {
PRF("msmattach entry\n");
}
#endif
if (cmd != DDI_ATTACH)
return (DDI_FAILURE);
#ifdef MSM_DEBUG
if (msm_debug)
PRF("msmattach: ddi_create_minor_node failed\n");
#endif
return (DDI_FAILURE);
}
}
/* allocate and initialize state structure */
!= DDI_SUCCESS) {
#ifdef MSM_DEBUG
if (msm_debug)
PRF("msmattach: ddi_add_intr failed\n");
#endif
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* msmdetach:
*/
/*ARGSUSED*/
static int
{
struct strmseinfo *msmptr;
int instance;
switch (cmd) {
case DDI_DETACH:
/*
* check if every instance can be unloaded before actually
* starting to unload this one; this prevents the needless
*/
continue;
}
}
/*
* Undo what we did in msmattach & msmprobe, freeing resources
* and removing things we installed. The system
* framework guarantees we are not active with this devinfo
* node in any other entry points at this time.
*/
if ((instance >= MSM_MAXUNIT) ||
return (DDI_FAILURE);
return (DDI_SUCCESS);
default:
#ifdef MSM_DEBUG
if (msm_debug) {
}
#endif
return (DDI_FAILURE);
}
}
/* ARGSUSED */
static int
{
int unit;
#ifdef MSM_DEBUG
if (msm_debug)
PRF("msminfo: call\n");
#endif
return (DDI_FAILURE);
switch (infocmd) {
case DDI_INFO_DEVT2DEVINFO:
break;
case DDI_INFO_DEVT2INSTANCE:
break;
default:
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static int
{
unsigned char id1,
id2;
int ioaddr;
int old_probe;
#ifdef MSM_DEBUG
if (msm_debug)
#endif
"ignore-hardware-nodes", 0);
if (old_probe) {
int len = sizeof (int);
/*
* Check if ioaddr is set in .conf file, it should be. If it
* isn't then try the default i/o addr
*/
&len) == DDI_PROP_SUCCESS) {
mouse_base = ioaddr;
}
} else {
int i;
struct {
int bustype;
int base;
int size;
} *reglist;
/* new probe */
return (DDI_PROBE_FAILURE);
for (i = 0; i < nregs; i++)
mouse_base = ioaddr;
break;
}
}
/*
* Try reading the InPort identification register. It should
* alternate between a signature and a version number.
*/
mousepresent = 1;
else
return (DDI_PROBE_FAILURE);
/* Reset the mouse to make sure it does not interrupt */
#ifdef MSM_DEBUG
if (msm_debug)
PRF("msminit: succeeded\n");
#endif
return (DDI_SUCCESS);
}
/*ARGSUSED2*/
static int
{
struct strmseinfo *msmptr;
int unit;
#ifdef MSM_DEBUG
if (msm_debug)
printf("msmopen:entered\n");
#endif
return (DDI_FAILURE);
if (mousepresent == 0) {
return (EIO);
}
if (mouseinuse) {
return (EBUSY);
}
#ifdef MSM_DEBUG
if (msm_debug)
printf("msmopen:already open\n");
#endif
return (0); /* already attached */
}
qprocson(q);
#ifdef MSM_DEBUG
if (msm_debug)
printf("msmopen:leaving\n");
#endif
mouseinuse = 1;
mousestatus = 0;
/* Set appropriate modes for mouse and enable interrupts */
return (0);
}
/*ARGSUSED1*/
static int
{
struct strmseinfo *msmptr;
qprocsoff(q);
#ifdef MSM_DEBUG
if (msm_debug)
printf("msmclose:entered\n");
#endif
/*
* Use to reset the mouse to make sure it does not interrupt
* Now just turn off interrupts, as ATI VGA Wonder XL24
* appeared to get in a mode where it thought an interrupt was
* delivered, and wouldn't deliver any more after this was done.
*/
mousemode = 0;
mouseinuse = 0;
#ifdef MSM_DEBUG
if (msm_debug)
printf("msmclose:leaving\n");
#endif
return (0);
}
static int
{
struct strmseinfo *msmptr;
#ifdef MSM_DEBUG
if (msm_debug)
printf("msm_wput:entered\n");
#endif
if (msmptr == 0) {
#ifdef MSM_DEBUG
if (msm_debug)
printf("msm_wput:msmptr == NULL\n");
#endif
return (0);
}
case M_FLUSH:
#ifdef MSM_DEBUG
if (msm_debug)
printf("msm_wput:M_FLUSH\n");
#endif
break;
case M_IOCTL:
#ifdef MSM_DEBUG
if (msm_debug)
printf("msm_wput:M_IOCTL\n");
#endif
break;
case M_IOCDATA:
#ifdef MSM_DEBUG
if (msm_debug)
printf("msm_wput:M_IOCDATA\n");
#endif
break;
default:
break;
}
#ifdef MSM_DEBUG
if (msm_debug)
printf("msm_wput:leaving\n");
#endif
return (0);
}
static uint_t
{
char status,
x,
y;
#ifdef MSM_DEBUG
if (msm_debug > 5)
PRF("msmintr:\n");
#endif
return (DDI_INTR_UNCLAIMED);
}
if (!mouseinuse) {
return (DDI_INTR_UNCLAIMED);
}
/* Select mode register and turn on the HOLD data bit */
/* Select and read the status register */
/* if mouse moved, save the motion */
xmotion += x;
ymotion += y;
} else
x = y = 0;
/* Select mode register and turn off the HOLD data bit */
char c;
c = (char)0x80; /* MSC sync value */
c |= 0x04; /* left button up */
c |= 0x02; /* middle button up */
c |= 0x01; /* right button up */
return (DDI_INTR_UNCLAIMED);
}
}
return (DDI_INTR_UNCLAIMED);
}