Subversion Repositories HelenOS

Rev

Rev 4148 | Rev 4251 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 jermar 1
/*
3982 jermar 2
 * Copyright (c) 2009 Jakub Jermar
1 jermar 3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
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
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
4094 decky 29
/** @addtogroup genarch
1702 cejka 30
 * @{
31
 */
1754 jermar 32
/**
1757 jermar 33
 * @file
4094 decky 34
 * @brief i8042 processor driver
1754 jermar 35
 *
4042 jermar 36
 * It takes care of the i8042 serial communication.
4223 decky 37
 *
1702 cejka 38
 */
39
 
4042 jermar 40
#include <genarch/drivers/i8042/i8042.h>
3932 jermar 41
#include <genarch/drivers/legacy/ia32/io.h>
1 jermar 42
#include <arch/asm.h>
511 jermar 43
#include <console/chardev.h>
4042 jermar 44
#include <mm/slab.h>
4148 decky 45
#include <ddi/device.h>
1 jermar 46
 
4119 decky 47
static indev_operations_t kbrdin_ops = {
4094 decky 48
    .poll = NULL
49
};
894 jermar 50
 
4094 decky 51
#define i8042_SET_COMMAND  0x60
52
#define i8042_COMMAND      0x69
670 vana 53
 
4094 decky 54
#define i8042_BUFFER_FULL_MASK  0x01
55
#define i8042_WAIT_MASK         0x02
56
 
3941 jermar 57
static irq_ownership_t i8042_claim(irq_t *irq)
1474 palkovsky 58
{
3941 jermar 59
    i8042_instance_t *i8042_instance = irq->instance;
3931 jermar 60
    i8042_t *dev = i8042_instance->i8042;
4094 decky 61
 
3931 jermar 62
    if (pio_read_8(&dev->status) & i8042_BUFFER_FULL_MASK)
63
        return IRQ_ACCEPT;
64
    else
65
        return IRQ_DECLINE;
1956 decky 66
}
1474 palkovsky 67
 
3906 jermar 68
static void i8042_irq_handler(irq_t *irq)
1956 decky 69
{
3931 jermar 70
    i8042_instance_t *instance = irq->instance;
71
    i8042_t *dev = instance->i8042;
72
    uint8_t status;
4094 decky 73
 
3931 jermar 74
    if (((status = pio_read_8(&dev->status)) & i8042_BUFFER_FULL_MASK)) {
4094 decky 75
        uint8_t data = pio_read_8(&dev->data);
76
        indev_push_character(&instance->kbrdin, data);
1956 decky 77
    }
78
}
1474 palkovsky 79
 
1956 decky 80
/** Initialize i8042. */
4148 decky 81
indev_t *i8042_init(i8042_t *dev, inr_t inr)
1956 decky 82
{
4094 decky 83
    i8042_instance_t *instance
84
        = malloc(sizeof(i8042_instance_t), FRAME_ATOMIC);
3963 jermar 85
    if (!instance)
4094 decky 86
        return NULL;
1956 decky 87
 
4094 decky 88
    indev_initialize("i8042", &instance->kbrdin, &kbrdin_ops);
89
 
3963 jermar 90
    instance->i8042 = dev;
3877 decky 91
 
3963 jermar 92
    irq_initialize(&instance->irq);
4148 decky 93
    instance->irq.devno = device_assign_devno();
3963 jermar 94
    instance->irq.inr = inr;
95
    instance->irq.claim = i8042_claim;
96
    instance->irq.handler = i8042_irq_handler;
97
    instance->irq.instance = instance;
98
    irq_register(&instance->irq);
3877 decky 99
 
1194 vana 100
    /*
1195 jermar 101
     * Clear input buffer.
102
     */
3958 jermar 103
    while (pio_read_8(&dev->status) & i8042_BUFFER_FULL_MASK)
3931 jermar 104
        (void) pio_read_8(&dev->data);
1956 decky 105
 
4094 decky 106
    return &instance->kbrdin;
1 jermar 107
}
508 jermar 108
 
1754 jermar 109
/** @}
1702 cejka 110
 */