On Thu, Sep 30, 2010 at 02:50:54AM +0600, Alexandr Shadchin wrote:
> On Mon, Sep 27, 2010 at 11:42:35PM +0600, Alexandr Shadchin wrote:
> > On Fri, Sep 24, 2010 at 05:40:37PM +0400, Alexandr Shadchin wrote:
> > > Hi!
> > >
> > > Paul Irofti proposed to split the diff in a few easy steps.
> > > Step 1 - merge drivers pms and pmsi.
> > >
> >
> > Step 2 - cleanup, standardization of interfaces and preparation
> > for easy addition of new devices. Now the resume of work in polling mode.
> >
>
> Regen for -current. Also small improvements:
> 1) add function pms_dev_reset()
> 2) in struct pms_protocol add function sync() - for check synchronization,
> proc () - for processing packet.
>
That diff is way too big to commit in one piece. I'll try to split it into
several pieces.
Pieces 1 - cleanup code
--
Alexandr Shadchin
Index: pms.c
===================================================================
RCS file: /cvs/src/sys/dev/pckbc/pms.c,v
retrieving revision 1.5
diff -u -p -r1.5 pms.c
--- pms.c 27 Sep 2010 18:16:25 -0000 1.5
+++ pms.c 29 Sep 2010 16:05:58 -0000
@@ -57,15 +57,11 @@ struct pms_softc { /* driver status inf
struct device *sc_wsmousedev;
};
-int pmsprobe(struct device *, void *, void *);
-void pmsattach(struct device *, struct device *, void *);
-int pmsactivate(struct device *, int);
-void pmsinput(void *, int);
+int pmsprobe(struct device *, void *, void *);
+void pmsattach(struct device *, struct device *, void *);
+int pmsactivate(struct device *, int);
-struct cfattach pms_ca = {
- sizeof(struct pms_softc), pmsprobe, pmsattach, NULL,
- pmsactivate
-};
+void pmsinput(void *, int);
int pms_change_state(struct pms_softc *, int);
int pms_ioctl(void *, u_long, caddr_t, int, struct proc *);
@@ -74,6 +70,15 @@ void pms_disable(void *);
int pms_setintellimode(pckbc_tag_t, pckbc_slot_t);
+struct cfattach pms_ca = {
+ sizeof(struct pms_softc), pmsprobe, pmsattach, NULL,
+ pmsactivate
+};
+
+struct cfdriver pms_cd = {
+ NULL, "pms", DV_DULL
+};
+
const struct wsmouse_accessops pms_accessops = {
pms_enable,
pms_ioctl,
@@ -92,31 +97,28 @@ pms_setintellimode(pckbc_tag_t tag, pckb
cmd[1] = rates[i];
res = pckbc_enqueue_cmd(tag, slot, cmd, 2, 0, 0, NULL);
if (res)
- return (0);
+ return 0;
}
cmd[0] = PMS_SEND_DEV_ID;
res = pckbc_enqueue_cmd(tag, slot, cmd, 1, 1, 1, resp);
if (res || resp[0] != 3)
- return (0);
+ return 0;
- return (1);
+ return 1;
}
int
-pmsprobe(parent, match, aux)
- struct device *parent;
- void *match;
- void *aux;
+pmsprobe(struct device *parent, void *match, void *aux)
{
struct pckbc_attach_args *pa = aux;
u_char cmd[1], resp[2];
int res;
if (pa->pa_slot != PCKBC_AUX_SLOT)
- return (0);
+ return 0;
- /* Flush any garbage. */
+ /* flush any garbage */
pckbc_flush(pa->pa_tag, pa->pa_slot);
/* reset the device */
@@ -126,11 +128,11 @@ pmsprobe(parent, match, aux)
#ifdef DEBUG
printf("pmsprobe: reset error %d\n", res);
#endif
- return (0);
+ return 0;
}
if (resp[0] != PMS_RSTDONE) {
printf("pmsprobe: reset response 0x%x\n", resp[0]);
- return (0);
+ return 0;
}
/* get type number (0 = mouse) */
@@ -138,21 +140,19 @@ pmsprobe(parent, match, aux)
#ifdef DEBUG
printf("pmsprobe: type 0x%x\n", resp[1]);
#endif
- return (0);
+ return 0;
}
- return (10);
+ return 1;
}
void
-pmsattach(parent, self, aux)
- struct device *parent, *self;
- void *aux;
+pmsattach(struct device *parent, struct device *self, void *aux)
{
struct pms_softc *sc = (void *)self;
struct pckbc_attach_args *pa = aux;
struct wsmousedev_attach_args a;
- u_char cmd[1], resp[2];
+ u_char cmd[1];
int res;
sc->sc_kbctag = pa->pa_tag;
@@ -160,24 +160,8 @@ pmsattach(parent, self, aux)
printf("\n");
- /* Flush any garbage. */
- pckbc_flush(pa->pa_tag, pa->pa_slot);
-
- /* reset the device */
- cmd[0] = PMS_RESET;
- res = pckbc_poll_cmd(pa->pa_tag, pa->pa_slot, cmd, 1, 2, resp, 1);
-#ifdef DEBUG
- if (res || resp[0] != PMS_RSTDONE || resp[1] != 0) {
- printf("pmsattach: reset error\n");
- return;
- }
-#endif
-
- sc->inputstate = 0;
- sc->oldbuttons = 0;
-
pckbc_set_inputhandler(sc->sc_kbctag, sc->sc_kbcslot,
- pmsinput, sc, sc->sc_dev.dv_xname);
+ pmsinput, sc, sc->sc_dev.dv_xname);
a.accessops = &pms_accessops;
a.accesscookie = sc;
@@ -213,7 +197,7 @@ pmsactivate(struct device *self, int act
pms_change_state(sc, PMS_STATE_ENABLED);
break;
}
- return (0);
+ return 0;
}
int
@@ -226,6 +210,7 @@ pms_change_state(struct pms_softc *sc, i
case PMS_STATE_ENABLED:
if (sc->sc_state == PMS_STATE_ENABLED)
return EBUSY;
+
sc->inputstate = 0;
sc->oldbuttons = 0;
@@ -239,36 +224,8 @@ pms_change_state(struct pms_softc *sc, i
cmd, 1, 0, 1, 0);
if (res)
printf("pms_enable: command error\n");
-#if 0
- {
- u_char scmd[2];
-
- scmd[0] = PMS_SET_RES;
- scmd[1] = 3; /* 8 counts/mm */
- res = pckbc_enqueue_cmd(sc->sc_kbctag, sc->sc_kbcslot,
scmd,
- 2, 0, 1, 0);
- if (res)
- printf("pms_enable: setup error1 (%d)\n", res);
-
- scmd[0] = PMS_SET_SCALE21;
- res = pckbc_enqueue_cmd(sc->sc_kbctag, sc->sc_kbcslot,
scmd,
- 1, 0, 1, 0);
- if (res)
- printf("pms_enable: setup error2 (%d)\n", res);
-
- scmd[0] = PMS_SET_SAMPLE;
- scmd[1] = 100; /* 100 samples/sec */
- res = pckbc_enqueue_cmd(sc->sc_kbctag, sc->sc_kbcslot,
scmd,
- 2, 0, 1, 0);
- if (res)
- printf("pms_enable: setup error3 (%d)\n", res);
- }
-#endif
- sc->sc_state = newstate;
break;
case PMS_STATE_DISABLED:
-
- /* FALLTHROUGH */
case PMS_STATE_SUSPENDED:
cmd[0] = PMS_DEV_DISABLE;
res = pckbc_enqueue_cmd(sc->sc_kbctag, sc->sc_kbcslot,
@@ -276,39 +233,32 @@ pms_change_state(struct pms_softc *sc, i
if (res)
printf("pms_disable: command error\n");
pckbc_slot_enable(sc->sc_kbctag, sc->sc_kbcslot, 0);
- sc->sc_state = newstate;
break;
}
+ sc->sc_state = newstate;
return 0;
}
int
-pms_enable(v)
- void *v;
+pms_enable(void *vsc)
{
- struct pms_softc *sc = v;
+ struct pms_softc *sc = vsc;
return pms_change_state(sc, PMS_STATE_ENABLED);
}
void
-pms_disable(v)
- void *v;
+pms_disable(void *vsc)
{
- struct pms_softc *sc = v;
+ struct pms_softc *sc = vsc;
pms_change_state(sc, PMS_STATE_DISABLED);
}
int
-pms_ioctl(v, cmd, data, flag, p)
- void *v;
- u_long cmd;
- caddr_t data;
- int flag;
- struct proc *p;
+pms_ioctl(void *vsc, u_long cmd, caddr_t data, int flag, struct proc *p)
{
- struct pms_softc *sc = v;
+ struct pms_softc *sc = vsc;
u_char kbcmd[2];
int i;
@@ -316,28 +266,26 @@ pms_ioctl(v, cmd, data, flag, p)
case WSMOUSEIO_GTYPE:
*(u_int *)data = WSMOUSE_TYPE_PS2;
break;
-
case WSMOUSEIO_SRES:
- i = ((int) *(u_int *)data - 12) / 25;
+ i = ((int) *(u_int *)data - 12) / 25;
/* valid values are {0,1,2,3} */
if (i < 0)
i = 0;
if (i > 3)
i = 3;
-
+
kbcmd[0] = PMS_SET_RES;
- kbcmd[1] = (unsigned char) i;
- i = pckbc_enqueue_cmd(sc->sc_kbctag, sc->sc_kbcslot, kbcmd,
+ kbcmd[1] = (unsigned char) i;
+ i = pckbc_enqueue_cmd(sc->sc_kbctag, sc->sc_kbcslot, kbcmd,
2, 0, 1, 0);
-
+
if (i)
printf("pms_ioctl: SET_RES command error\n");
break;
-
default:
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
}
/* Masks for the first byte of a packet */
@@ -345,9 +293,8 @@ pms_ioctl(v, cmd, data, flag, p)
#define PS2RBUTMASK 0x02
#define PS2MBUTMASK 0x04
-void pmsinput(vsc, data)
-void *vsc;
-int data;
+void
+pmsinput(void *vsc, int data)
{
struct pms_softc *sc = vsc;
signed char dz = 0;
@@ -403,7 +350,3 @@ int data;
return;
}
-
-struct cfdriver pms_cd = {
- NULL, "pms", DV_DULL
-};
Index: pmsreg.h
===================================================================
RCS file: /cvs/src/sys/dev/pckbc/pmsreg.h,v
retrieving revision 1.1
diff -u -p -r1.1 pmsreg.h
--- pmsreg.h 1 Aug 2007 12:16:59 -0000 1.1
+++ pmsreg.h 29 Sep 2010 16:05:58 -0000
@@ -2,19 +2,21 @@
/* $NetBSD: psmreg.h,v 1.1 1998/03/22 15:41:28 drochner Exp $ */
/* mouse commands */
-#define PMS_SET_SCALE11 0xe6 /* set scaling 1:1 */
-#define PMS_SET_SCALE21 0xe7 /* set scaling 2:1 */
-#define PMS_SET_RES 0xe8 /* set resolution (0..3) */
-#define PMS_GET_SCALE 0xe9 /* get scaling factor */
-#define PMS_SEND_DEV_STATUS 0xe9
-#define PMS_SET_STREAM 0xea /* set streaming mode */
-#define PMS_SEND_DEV_DATA 0xeb
+#define PMS_SET_SCALE11 0xe6 /* set scaling 1:1 */
+#define PMS_SET_SCALE21 0xe7 /* set scaling 2:1 */
+#define PMS_SET_RES 0xe8 /* set resolution (0..3) */
+#define PMS_SEND_DEV_STATUS 0xe9 /* status request */
+#define PMS_SET_STREAM_MODE 0xea
+#define PMS_SEND_DEV_DATA 0xeb /* read data */
+#define PMS_RESET_WRAP_MODE 0xec
+#define PMS_SET_WRAP_MODE 0xed
#define PMS_SET_REMOTE_MODE 0xf0
-#define PMS_SEND_DEV_ID 0xf2
-#define PMS_SET_SAMPLE 0xf3 /* set sampling rate */
-#define PMS_DEV_ENABLE 0xf4 /* mouse on */
-#define PMS_DEV_DISABLE 0xf5 /* mouse off */
+#define PMS_SEND_DEV_ID 0xf2 /* read device type */
+#define PMS_SET_SAMPLE 0xf3 /* set sampling rate */
+#define PMS_DEV_ENABLE 0xf4 /* mouse on */
+#define PMS_DEV_DISABLE 0xf5 /* mouse off */
#define PMS_SET_DEFAULTS 0xf6
-#define PMS_RESET 0xff /* reset */
+#define PMS_RESEND 0xfe
+#define PMS_RESET 0xff /* reset */
-#define PMS_RSTDONE 0xaa
+#define PMS_RSTDONE 0xaa