Subversion Repositories HelenOS

Rev

Rev 4042 | Rev 4148 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4042 Rev 4094
Line 24... Line 24...
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup genarch
29
/** @addtogroup genarch
30
 * @{
30
 * @{
31
 */
31
 */
32
/**
32
/**
33
 * @file
33
 * @file
34
 * @brief   i8042 processor driver
34
 * @brief i8042 processor driver
35
 *
35
 *
36
 * It takes care of the i8042 serial communication.
36
 * It takes care of the i8042 serial communication.
37
 */
37
 */
38
 
38
 
39
#include <genarch/drivers/i8042/i8042.h>
39
#include <genarch/drivers/i8042/i8042.h>
40
#include <genarch/drivers/legacy/ia32/io.h>
40
#include <genarch/drivers/legacy/ia32/io.h>
41
#include <arch/asm.h>
41
#include <arch/asm.h>
42
#include <console/chardev.h>
42
#include <console/chardev.h>
43
#include <mm/slab.h>
43
#include <mm/slab.h>
44
 
44
 
45
#define i8042_SET_COMMAND   0x60
45
indev_operations_t kbrdin_ops = {
46
#define i8042_COMMAND       0x69
46
    .poll = NULL
-
 
47
};
47
 
48
 
-
 
49
#define i8042_SET_COMMAND  0x60
-
 
50
#define i8042_COMMAND      0x69
-
 
51
 
48
#define i8042_BUFFER_FULL_MASK  0x01
52
#define i8042_BUFFER_FULL_MASK  0x01
49
#define i8042_WAIT_MASK     0x02
53
#define i8042_WAIT_MASK         0x02
50
 
54
 
51
static irq_ownership_t i8042_claim(irq_t *irq)
55
static irq_ownership_t i8042_claim(irq_t *irq)
52
{
56
{
53
    i8042_instance_t *i8042_instance = irq->instance;
57
    i8042_instance_t *i8042_instance = irq->instance;
54
    i8042_t *dev = i8042_instance->i8042;
58
    i8042_t *dev = i8042_instance->i8042;
-
 
59
   
55
    if (pio_read_8(&dev->status) & i8042_BUFFER_FULL_MASK)
60
    if (pio_read_8(&dev->status) & i8042_BUFFER_FULL_MASK)
56
        return IRQ_ACCEPT;
61
        return IRQ_ACCEPT;
57
    else
62
    else
58
        return IRQ_DECLINE;
63
        return IRQ_DECLINE;
59
}
64
}
60
 
65
 
61
static void i8042_irq_handler(irq_t *irq)
66
static void i8042_irq_handler(irq_t *irq)
62
{
67
{
63
    i8042_instance_t *instance = irq->instance;
68
    i8042_instance_t *instance = irq->instance;
64
    i8042_t *dev = instance->i8042;
69
    i8042_t *dev = instance->i8042;
65
 
-
 
66
    uint8_t data;
-
 
67
    uint8_t status;
70
    uint8_t status;
68
       
71
   
69
    if (((status = pio_read_8(&dev->status)) & i8042_BUFFER_FULL_MASK)) {
72
    if (((status = pio_read_8(&dev->status)) & i8042_BUFFER_FULL_MASK)) {
70
        data = pio_read_8(&dev->data);
73
        uint8_t data = pio_read_8(&dev->data);
71
           
-
 
72
        if (instance->devout)
-
 
73
            chardev_push_character(instance->devout, data);
74
        indev_push_character(&instance->kbrdin, data);
74
    }
75
    }
75
}
76
}
76
 
77
 
77
/** Initialize i8042. */
78
/** Initialize i8042. */
78
bool
-
 
79
i8042_init(i8042_t *dev, devno_t devno, inr_t inr, chardev_t *devout)
79
indev_t *i8042_init(i8042_t *dev, devno_t devno, inr_t inr)
80
{
80
{
81
    i8042_instance_t *instance;
81
    i8042_instance_t *instance
82
 
-
 
83
    instance = malloc(sizeof(i8042_instance_t), FRAME_ATOMIC);
82
        = malloc(sizeof(i8042_instance_t), FRAME_ATOMIC);
84
    if (!instance)
83
    if (!instance)
85
        return false;
84
        return NULL;
-
 
85
   
-
 
86
    indev_initialize("i8042", &instance->kbrdin, &kbrdin_ops);
86
   
87
   
87
    instance->devno = devno;
88
    instance->devno = devno;
88
    instance->i8042 = dev;
89
    instance->i8042 = dev;
89
    instance->devout = devout;
-
 
90
   
90
   
91
    irq_initialize(&instance->irq);
91
    irq_initialize(&instance->irq);
92
    instance->irq.devno = devno;
92
    instance->irq.devno = devno;
93
    instance->irq.inr = inr;
93
    instance->irq.inr = inr;
94
    instance->irq.claim = i8042_claim;
94
    instance->irq.claim = i8042_claim;
Line 100... Line 100...
100
     * Clear input buffer.
100
     * Clear input buffer.
101
     */
101
     */
102
    while (pio_read_8(&dev->status) & i8042_BUFFER_FULL_MASK)
102
    while (pio_read_8(&dev->status) & i8042_BUFFER_FULL_MASK)
103
        (void) pio_read_8(&dev->data);
103
        (void) pio_read_8(&dev->data);
104
   
104
   
105
    return true;
105
    return &instance->kbrdin;
106
}
106
}
107
 
107
 
108
/** @}
108
/** @}
109
 */
109
 */