Modules/PS2KbMouse - Broke 8042 specific code out
[tpg/acess2.git] / Modules / Input / PS2KbMouse / pl050.c
1 /*
2  * Acess2
3  * - By thePowersGang (John Hodge)
4  *
5  * PL050 (or comaptible) Driver
6  */
7 #include <acess.h>
8 #include "common.h"
9
10 // TODO: Allow runtime/compile-time switching
11 //       Maybe PCI will have it?
12 // Integrator-CP
13 #if 0
14 #define KEYBOARD_IRQ    3
15 #define KEYBOARD_BASE   0x18000000
16 #define MOUSE_IRQ       4
17 #define MOUSE_BASE      0x19000000
18 #endif
19 // Realview
20 #if 1
21 #define KEYBOARD_IRQ    20
22 #define KEYBOARD_BASE   0x10006000
23 #define MOUSE_IRQ       21
24 #define MOUSE_BASE      0x10007000
25 #endif
26
27 #define PL050_TXBUSY    0x20
28
29 // === PROTOTYPES ===
30 void    PL050_Init(void);
31 void    PL050_KeyboardHandler(int IRQ);
32 void    PL050_MouseHandler(int IRQ);
33 void    PL050_EnableMouse(void);
34 static inline void      PL050_WriteMouseData(Uint8 data);
35 static inline void      PL050_WriteKeyboardData(Uint8 data);
36 static inline Uint8     PL050_ReadMouseData(void);
37 static inline Uint8     PL050_ReadKeyboardData(void);
38
39 // === CODE ===
40 void PL050_Init(void)
41 {
42         IRQ_AddHandler(KEYBOARD_IRQ, PL050_KeyboardHandler);
43         IRQ_AddHandler(MOUSE_IRQ, PL050_MouseHandler);  // Set IRQ
44 }
45
46 void PL050_KeyboardHandler(int IRQ)
47 {
48         Uint8   scancode;
49
50         scancode = PL050_ReadKeyboardData(0x60);
51         KB_HandleScancode( scancode );
52 }
53
54 void PL050_MouseHandler(int IRQ)
55 {
56         PS2Mouse_HandleInterrupt( PL050_ReadMouseData(0x60) );
57 }
58
59 void PL050_SetLEDs(Uint8 leds)
60 {
61         PL050_WriteKeyboardData(0xED);
62         PL050_WriteKeyboardData(leds);
63 }
64
65 void PL050_EnableMouse(void)
66 {
67         Uint8   status;
68         Log_Log("8042", "Enabling Mouse...");
69         
70         
71         //PL050_WriteMouseData(0xD4);
72         //PL050_WriteMouseData(0xF6);   // Set Default Settings
73         PL050_WriteMouseData(0xD4);
74         PL050_WriteMouseData(0xF4);     // Enable Packets
75 }
76
77 static inline void PL050_WriteMouseData(Uint8 Data)
78 {
79          int    timeout = 10000;
80         while( --timeout && *(Uint32*)(MOUSE_BASE+1) & PL050_TXBUSY );
81         if(timeout)
82                 *(Uint32*)(MOUSE_BASE+2) = Data;
83         else
84                 Log_Error("PL050", "Write to mouse timed out");
85 }
86
87 static inline Uint8 PL050_ReadMouseData(void)
88 {
89         return *(Uint32*)(MOUSE_BASE+2);
90 }
91 static inline void PL050_WriteKeyboardData(Uint8 data)
92 {
93          int    timeout = 10000;
94         while( --timeout && *(Uint32*)(KEYBOARD_BASE+1) & PL050_TXBUSY );
95         if(timeout)
96                 *(Uint32*)(KEYBOARD_BASE+2) = Data;
97         else
98                 Log_Error("PL050", "Write to keyboard timed out");
99 }
100 static inline Uint8 PL050_ReadKeyboardData(void)
101 {
102         return *(Uint32*)(MOUSE_BASE+2);
103 }
104

UCC git Repository :: git.ucc.asn.au