Rev 3982 | Rev 4094 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3982 | Rev 4042 | ||
---|---|---|---|
Line 29... | Line 29... | ||
29 | /** @addtogroup genarch |
29 | /** @addtogroup genarch |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** |
32 | /** |
33 | * @file |
33 | * @file |
34 | * @brief Zilog 8530 serial port driver. |
34 | * @brief Zilog 8530 serial controller driver. |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <genarch/kbd/z8530.h> |
37 | #include <genarch/drivers/z8530/z8530.h> |
38 | #include <genarch/kbd/key.h> |
- | |
39 | #include <genarch/kbd/scanc.h> |
- | |
40 | #include <genarch/kbd/scanc_sun.h> |
- | |
41 | #include <arch/drivers/kbd.h> |
- | |
42 | #include <console/console.h> |
- | |
43 | #include <console/chardev.h> |
38 | #include <console/chardev.h> |
44 | #include <ddi/irq.h> |
39 | #include <ddi/irq.h> |
45 | #include <arch/asm.h> |
40 | #include <arch/asm.h> |
46 | #include <mm/slab.h> |
41 | #include <mm/slab.h> |
47 | 42 | ||
Line 63... | Line 58... | ||
63 | */ |
58 | */ |
64 | pio_write_8(ctl, reg); /* select register */ |
59 | pio_write_8(ctl, reg); /* select register */ |
65 | return pio_read_8(ctl); |
60 | return pio_read_8(ctl); |
66 | } |
61 | } |
67 | 62 | ||
68 | /* |
- | |
69 | * These codes read from z8530 data register are silently ignored. |
- | |
70 | */ |
- | |
71 | #define IGNORE_CODE 0x7f /* all keys up */ |
- | |
72 | - | ||
73 | static void z8530_suspend(chardev_t *); |
- | |
74 | static void z8530_resume(chardev_t *); |
- | |
75 | - | ||
76 | static chardev_operations_t ops = { |
- | |
77 | .suspend = z8530_suspend, |
- | |
78 | .resume = z8530_resume, |
- | |
79 | }; |
- | |
80 | - | ||
81 | /** Initialize z8530. */ |
63 | /** Initialize z8530. */ |
82 | bool |
64 | bool |
83 | z8530_init(z8530_t *dev, devno_t devno, inr_t inr, cir_t cir, void *cir_arg) |
65 | z8530_init(z8530_t *dev, devno_t devno, inr_t inr, cir_t cir, void *cir_arg, |
- | 66 | chardev_t *devout) |
|
84 | { |
67 | { |
85 | z8530_instance_t *instance; |
68 | z8530_instance_t *instance; |
86 | 69 | ||
87 | chardev_initialize("z8530_kbd", &kbrd, &ops); |
- | |
88 | stdin = &kbrd; |
- | |
89 | - | ||
90 | instance = malloc(sizeof(z8530_instance_t), FRAME_ATOMIC); |
70 | instance = malloc(sizeof(z8530_instance_t), FRAME_ATOMIC); |
91 | if (!instance) |
71 | if (!instance) |
92 | return false; |
72 | return false; |
93 | 73 | ||
94 | instance->devno = devno; |
74 | instance->devno = devno; |
95 | instance->z8530 = dev; |
75 | instance->z8530 = dev; |
- | 76 | instance->devout = devout; |
|
96 | 77 | ||
97 | irq_initialize(&instance->irq); |
78 | irq_initialize(&instance->irq); |
98 | instance->irq.devno = devno; |
79 | instance->irq.devno = devno; |
99 | instance->irq.inr = inr; |
80 | instance->irq.inr = inr; |
100 | instance->irq.claim = z8530_claim; |
81 | instance->irq.claim = z8530_claim; |
Line 122... | Line 103... | ||
122 | z8530_write(&dev->ctl_a, WR9, WR9_MIE); |
103 | z8530_write(&dev->ctl_a, WR9, WR9_MIE); |
123 | 104 | ||
124 | return true; |
105 | return true; |
125 | } |
106 | } |
126 | 107 | ||
127 | /* Called from getc(). */ |
- | |
128 | void z8530_resume(chardev_t *d) |
- | |
129 | { |
- | |
130 | } |
- | |
131 | - | ||
132 | /* Called from getc(). */ |
- | |
133 | void z8530_suspend(chardev_t *d) |
- | |
134 | { |
- | |
135 | } |
- | |
136 | - | ||
137 | irq_ownership_t z8530_claim(irq_t *irq) |
108 | irq_ownership_t z8530_claim(irq_t *irq) |
138 | { |
109 | { |
139 | z8530_instance_t *instance = irq->instance; |
110 | z8530_instance_t *instance = irq->instance; |
140 | z8530_t *dev = instance->z8530; |
111 | z8530_t *dev = instance->z8530; |
141 | 112 | ||
142 | return (z8530_read(&dev->ctl_a, RR0) & RR0_RCA); |
113 | if (z8530_read(&dev->ctl_a, RR0) & RR0_RCA) |
- | 114 | return IRQ_ACCEPT; |
|
- | 115 | else |
|
- | 116 | return IRQ_DECLINE; |
|
143 | } |
117 | } |
144 | 118 | ||
145 | void z8530_irq_handler(irq_t *irq) |
119 | void z8530_irq_handler(irq_t *irq) |
146 | { |
120 | { |
147 | z8530_instance_t *instance = irq->instance; |
121 | z8530_instance_t *instance = irq->instance; |
148 | z8530_t *dev = instance->z8530; |
122 | z8530_t *dev = instance->z8530; |
149 | uint8_t x; |
123 | uint8_t x; |
150 | 124 | ||
151 | if (z8530_read(&dev->ctl_a, RR0) & RR0_RCA) { |
125 | if (z8530_read(&dev->ctl_a, RR0) & RR0_RCA) { |
152 | x = z8530_read(&dev->ctl_a, RR8); |
126 | x = z8530_read(&dev->ctl_a, RR8); |
153 | if (x != IGNORE_CODE) { |
- | |
154 | if (x & KEY_RELEASE) |
127 | if (instance->devout) |
155 | key_released(x ^ KEY_RELEASE); |
128 | chardev_push_character(instance->devout, x); |
156 | else |
- | |
157 | key_pressed(x); |
- | |
158 | } |
- | |
159 | } |
129 | } |
160 | } |
130 | } |
161 | 131 | ||
162 | /** @} |
132 | /** @} |
163 | */ |
133 | */ |