revert between 56095 -> 55830 in arch
[AROS.git] / rom / hidds / i8042 / mouseclass.c
blobf96dd446cad871ee62dcee4bdc9904df13739984
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: The PS/2 mouse driver class.
6 Lang: English.
7 */
9 /*
10 Please keep code clean from all .bss and .data sections. .rodata may exist
11 as it will be connected together with .text section during linking. In near
12 future this driver will be compiled as elf executable (instead of object)
13 with -fPIC flag.
16 #include <proto/exec.h>
17 #include <proto/kernel.h>
18 #include <proto/utility.h>
19 #include <proto/oop.h>
20 #include <oop/oop.h>
21 #include <hidd/hidd.h>
22 #include <hidd/mouse.h>
23 #include <devices/inputevent.h>
24 #include <string.h>
26 #include "mouse.h"
28 #define DEBUG 0
29 #include <aros/debug.h>
31 /* Prototypes */
33 int test_mouse_ps2(OOP_Class *, OOP_Object *);
34 void dispose_mouse_ps2(OOP_Class *, OOP_Object *);
35 void getps2State(OOP_Class *, OOP_Object *, struct pHidd_Mouse_Event *);
37 /* defines for buttonstate */
39 /***** Mouse::New() ***************************************/
40 OOP_Object * PCMouse__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
42 EnterFunc(bug("_Mouse::New()\n"));
44 if (XSD(cl)->mousehidd) /* Cannot open twice */
45 ReturnPtr("_Mouse::New", OOP_Object *, NULL); /* Should have some error code here */
47 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
48 if (o)
50 struct mouse_data *data = OOP_INST_DATA(cl, o);
51 struct TagItem *tag, *tstate;
53 tstate = msg->attrList;
55 /* Search for all mouse attrs */
57 while ((tag = NextTagItem(&tstate)))
59 ULONG idx;
61 if (IS_HIDDMOUSE_ATTR(tag->ti_Tag, idx))
63 switch (idx)
65 case aoHidd_Mouse_IrqHandler:
66 data->mouse_callback = (APTR)tag->ti_Data;
67 break;
69 case aoHidd_Mouse_IrqHandlerData:
70 data->callbackdata = (APTR)tag->ti_Data;
71 break;
75 } /* while (tags to process) */
77 /* Search for PS/2 mouse */
78 if (!test_mouse_ps2(cl, o))
81 * No mouse found. What we can do now is just Dispose() :(
82 * Note that we use OOP_DoSuperMethod() in order not to call
83 * our own dispose_mouse_ps2().
85 OOP_MethodID disp_mid = msg->mID - moRoot_New + moRoot_Dispose;
87 OOP_DoSuperMethod(cl, o, &disp_mid);
88 o = NULL;
90 XSD(cl)->mousehidd = o;
93 return o;
96 VOID PCMouse__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
98 struct mouse_data *data = OOP_INST_DATA(cl, o);
100 XSD(cl)->mousehidd = NULL;
101 KrnRemIRQHandler(data->irq);
102 OOP_DoSuperMethod(cl, o, msg);
105 /***** Mouse::Get() ***************************************/
107 static const char *mice_str[] =
109 "Generic PS/2 mouse",
110 "IntelliMouse(tm)-compatible PS/2 mouse"
113 VOID PCMouse__Root__Get(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
115 struct mouse_data *data = OOP_INST_DATA(cl, o);
116 ULONG idx;
118 if (IS_HIDDMOUSE_ATTR(msg->attrID, idx))
120 switch (idx)
122 case aoHidd_Mouse_State:
123 getps2State(cl, o, (struct pHidd_Mouse_Event *)msg->storage);
124 return;
126 case aoHidd_Mouse_RelativeCoords:
127 *msg->storage = TRUE;
128 return;
131 else if (IS_IF_ATTR(msg->attrID, idx, HiddAttrBase, num_Hidd_Attrs))
134 * Since we have some knowledge of mouse type, we can
135 * reflect this in hardware description.
136 * A well-designed driver would first probe for hardware,
137 * then create its objects. This code is very old, and it has
138 * long story. Refactoring inner working of PS/2 driver can break
139 * something and reveal some controller quirks, so we leave
140 * everything as it is. First installing interrupt handler, then
141 * mouse detection. It may be important.
142 * Of course i could modify hiddclass to have setable attributes,
143 * but this is not good and can be easily abused by bad code. So here
144 * we do another thing, and just overload the respective attribute.
146 switch (idx)
148 case aoHidd_Name:
149 *msg->storage = (IPTR)"i8042.hidd";
150 return;
152 case aoHidd_HardwareName:
153 *msg->storage = (IPTR)mice_str[data->mouse_protocol];
154 return;
158 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);