Subversion Repositories HelenOS

Rev

Rev 4153 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4153 Rev 4263
1
/*
1
/*
2
 * Copyright (c) 2009 Jakub Jermar
2
 * Copyright (c) 2009 Jakub Jermar
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
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
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.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
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
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
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
 
39
#include <genarch/drivers/i8042/i8042.h>
40
#include <genarch/drivers/i8042/i8042.h>
40
#include <genarch/drivers/legacy/ia32/io.h>
41
#include <genarch/drivers/legacy/ia32/io.h>
41
#include <arch/asm.h>
42
#include <arch/asm.h>
42
#include <console/chardev.h>
43
#include <console/chardev.h>
43
#include <mm/slab.h>
44
#include <mm/slab.h>
44
#include <ddi/device.h>
45
#include <ddi/device.h>
45
 
46
 
46
static indev_operations_t kbrdin_ops = {
47
static indev_operations_t kbrdin_ops = {
47
    .poll = NULL
48
    .poll = NULL
48
};
49
};
49
 
50
 
50
#define i8042_SET_COMMAND  0x60
51
#define i8042_SET_COMMAND  0x60
51
#define i8042_COMMAND      0x69
52
#define i8042_COMMAND      0x69
-
 
53
#define i8042_CPU_RESET    0xfe
52
 
54
 
53
#define i8042_BUFFER_FULL_MASK  0x01
55
#define i8042_BUFFER_FULL_MASK  0x01
54
#define i8042_WAIT_MASK         0x02
56
#define i8042_WAIT_MASK         0x02
55
 
57
 
56
static irq_ownership_t i8042_claim(irq_t *irq)
58
static irq_ownership_t i8042_claim(irq_t *irq)
57
{
59
{
58
    i8042_instance_t *i8042_instance = irq->instance;
60
    i8042_instance_t *i8042_instance = irq->instance;
59
    i8042_t *dev = i8042_instance->i8042;
61
    i8042_t *dev = i8042_instance->i8042;
60
   
62
   
61
    if (pio_read_8(&dev->status) & i8042_BUFFER_FULL_MASK)
63
    if (pio_read_8(&dev->status) & i8042_BUFFER_FULL_MASK)
62
        return IRQ_ACCEPT;
64
        return IRQ_ACCEPT;
63
    else
65
    else
64
        return IRQ_DECLINE;
66
        return IRQ_DECLINE;
65
}
67
}
66
 
68
 
67
static void i8042_irq_handler(irq_t *irq)
69
static void i8042_irq_handler(irq_t *irq)
68
{
70
{
69
    i8042_instance_t *instance = irq->instance;
71
    i8042_instance_t *instance = irq->instance;
70
    i8042_t *dev = instance->i8042;
72
    i8042_t *dev = instance->i8042;
71
    uint8_t status;
73
    uint8_t status;
72
   
74
   
73
    if (((status = pio_read_8(&dev->status)) & i8042_BUFFER_FULL_MASK)) {
75
    if (((status = pio_read_8(&dev->status)) & i8042_BUFFER_FULL_MASK)) {
74
        uint8_t data = pio_read_8(&dev->data);
76
        uint8_t data = pio_read_8(&dev->data);
75
        indev_push_character(&instance->kbrdin, data);
77
        indev_push_character(&instance->kbrdin, data);
76
    }
78
    }
77
}
79
}
78
 
80
 
79
/** Initialize i8042. */
81
/** Initialize i8042. */
80
indev_t *i8042_init(i8042_t *dev, inr_t inr)
82
indev_t *i8042_init(i8042_t *dev, inr_t inr)
81
{
83
{
82
    i8042_instance_t *instance
84
    i8042_instance_t *instance
83
        = malloc(sizeof(i8042_instance_t), FRAME_ATOMIC);
85
        = malloc(sizeof(i8042_instance_t), FRAME_ATOMIC);
84
    if (!instance)
86
    if (!instance)
85
        return NULL;
87
        return NULL;
86
   
88
   
87
    indev_initialize("i8042", &instance->kbrdin, &kbrdin_ops);
89
    indev_initialize("i8042", &instance->kbrdin, &kbrdin_ops);
88
   
90
   
89
    instance->i8042 = dev;
91
    instance->i8042 = dev;
90
   
92
   
91
    irq_initialize(&instance->irq);
93
    irq_initialize(&instance->irq);
92
    instance->irq.devno = device_assign_devno();
94
    instance->irq.devno = device_assign_devno();
93
    instance->irq.inr = inr;
95
    instance->irq.inr = inr;
94
    instance->irq.claim = i8042_claim;
96
    instance->irq.claim = i8042_claim;
95
    instance->irq.handler = i8042_irq_handler;
97
    instance->irq.handler = i8042_irq_handler;
96
    instance->irq.instance = instance;
98
    instance->irq.instance = instance;
97
    irq_register(&instance->irq);
99
    irq_register(&instance->irq);
98
   
100
   
99
    /*
-
 
100
     * Clear input buffer.
101
    /* Clear input buffer */
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 &instance->kbrdin;
105
    return &instance->kbrdin;
106
}
106
}
-
 
107
 
-
 
108
/* Reset CPU by pulsing pin 0 */
-
 
109
void i8042_cpu_reset(i8042_t *dev)
-
 
110
{
-
 
111
    interrupts_disable();
-
 
112
   
-
 
113
    /* Clear input buffer */
-
 
114
    while (pio_read_8(&dev->status) & i8042_BUFFER_FULL_MASK)
-
 
115
        (void) pio_read_8(&dev->data);
-
 
116
   
-
 
117
    /* Reset CPU */
-
 
118
    pio_write_8(&dev->status, i8042_CPU_RESET);
-
 
119
}
107
 
120
 
108
/** @}
121
/** @}
109
 */
122
 */
110
 
123