Rev 4347 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4347 | Rev 4348 | ||
---|---|---|---|
Line 32... | Line 32... | ||
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 | .poll = NULL |
- | |
48 | }; |
- | |
49 | - | ||
50 | #define i8042_SET_COMMAND 0x60 |
47 | #define i8042_SET_COMMAND 0x60 |
51 | #define i8042_COMMAND 0x69 |
48 | #define i8042_COMMAND 0x69 |
- | 49 | #define i8042_CPU_RESET 0xfe |
|
52 | 50 | ||
53 | #define i8042_BUFFER_FULL_MASK 0x01 |
51 | #define i8042_BUFFER_FULL_MASK 0x01 |
54 | #define i8042_WAIT_MASK 0x02 |
52 | #define i8042_WAIT_MASK 0x02 |
55 | 53 | ||
56 | static irq_ownership_t i8042_claim(irq_t *irq) |
54 | static irq_ownership_t i8042_claim(irq_t *irq) |
Line 70... | Line 68... | ||
70 | i8042_t *dev = instance->i8042; |
68 | i8042_t *dev = instance->i8042; |
71 | uint8_t status; |
69 | uint8_t status; |
72 | 70 | ||
73 | if (((status = pio_read_8(&dev->status)) & i8042_BUFFER_FULL_MASK)) { |
71 | if (((status = pio_read_8(&dev->status)) & i8042_BUFFER_FULL_MASK)) { |
74 | uint8_t data = pio_read_8(&dev->data); |
72 | uint8_t data = pio_read_8(&dev->data); |
75 | indev_push_character(&instance->kbrdin, data); |
73 | indev_push_character(instance->kbrdin, data); |
76 | } |
74 | } |
77 | } |
75 | } |
78 | 76 | ||
- | 77 | /**< Clear input buffer. */ |
|
- | 78 | static void i8042_clear_buffer(i8042_t *dev) |
|
- | 79 | { |
|
- | 80 | while (pio_read_8(&dev->status) & i8042_BUFFER_FULL_MASK) |
|
- | 81 | (void) pio_read_8(&dev->data); |
|
- | 82 | } |
|
- | 83 | ||
79 | /** Initialize i8042. */ |
84 | /** Initialize i8042. */ |
80 | indev_t *i8042_init(i8042_t *dev, inr_t inr) |
85 | i8042_instance_t *i8042_init(i8042_t *dev, inr_t inr) |
81 | { |
86 | { |
82 | i8042_instance_t *instance |
87 | i8042_instance_t *instance |
83 | = malloc(sizeof(i8042_instance_t), FRAME_ATOMIC); |
88 | = malloc(sizeof(i8042_instance_t), FRAME_ATOMIC); |
84 | if (!instance) |
89 | if (instance) { |
- | 90 | instance->i8042 = dev; |
|
85 | return NULL; |
91 | instance->kbrdin = NULL; |
86 | 92 | ||
87 | indev_initialize("i8042", &instance->kbrdin, &kbrdin_ops); |
93 | irq_initialize(&instance->irq); |
- | 94 | instance->irq.devno = device_assign_devno(); |
|
- | 95 | instance->irq.inr = inr; |
|
- | 96 | instance->irq.claim = i8042_claim; |
|
- | 97 | instance->irq.handler = i8042_irq_handler; |
|
- | 98 | instance->irq.instance = instance; |
|
- | 99 | ||
- | 100 | } |
|
88 | 101 | ||
89 | instance->i8042 = dev; |
102 | return instance; |
- | 103 | } |
|
- | 104 | ||
- | 105 | void i8042_wire(i8042_instance_t *instance, indev_t *kbrdin) |
|
- | 106 | { |
|
- | 107 | ASSERT(instance); |
|
- | 108 | ASSERT(kbrdin); |
|
90 | 109 | ||
91 | irq_initialize(&instance->irq); |
- | |
92 | instance->irq.devno = device_assign_devno(); |
- | |
93 | instance->irq.inr = inr; |
110 | instance->kbrdin = kbrdin; |
94 | instance->irq.claim = i8042_claim; |
- | |
95 | instance->irq.handler = i8042_irq_handler; |
- | |
96 | instance->irq.instance = instance; |
- | |
97 | irq_register(&instance->irq); |
111 | irq_register(&instance->irq); |
- | 112 | i8042_clear_buffer(instance->i8042); |
|
- | 113 | } |
|
- | 114 | ||
- | 115 | /* Reset CPU by pulsing pin 0 */ |
|
- | 116 | void i8042_cpu_reset(i8042_t *dev) |
|
- | 117 | { |
|
- | 118 | interrupts_disable(); |
|
98 | 119 | ||
99 | /* |
- | |
100 | * Clear input buffer. |
- | |
101 | */ |
- | |
102 | while (pio_read_8(&dev->status) & i8042_BUFFER_FULL_MASK) |
- | |
103 | (void) pio_read_8(&dev->data); |
120 | i8042_clear_buffer(dev); |
104 | 121 | ||
105 | return &instance->kbrdin; |
122 | /* Reset CPU */ |
- | 123 | pio_write_8(&dev->status, i8042_CPU_RESET); |
|
106 | } |
124 | } |
107 | 125 | ||
108 | /** @} |
126 | /** @} |
109 | */ |
127 | */ |