Subversion Repositories HelenOS

Rev

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

Rev 1921 Rev 1923
1
/*
1
/*
2
 * Copyright (C) 2001-2004 Jakub Jermar
2
 * Copyright (C) 2001-2004 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   Zilog 8530 serial port / keyboard driver.
34
 * @brief   Zilog 8530 serial port / keyboard driver.
35
 */
35
 */
36
 
36
 
37
#include <genarch/kbd/z8530.h>
37
#include <genarch/kbd/z8530.h>
38
#include <genarch/kbd/key.h>
38
#include <genarch/kbd/key.h>
39
#include <genarch/kbd/scanc.h>
39
#include <genarch/kbd/scanc.h>
40
#include <genarch/kbd/scanc_sun.h>
40
#include <genarch/kbd/scanc_sun.h>
41
#include <arch/drivers/z8530.h>
41
#include <arch/drivers/z8530.h>
42
#include <ddi/irq.h>
42
#include <ddi/irq.h>
-
 
43
#include <ipc/irq.h>
43
#include <arch/interrupt.h>
44
#include <arch/interrupt.h>
44
#include <arch/drivers/kbd.h>
45
#include <arch/drivers/kbd.h>
45
#include <arch/drivers/fhc.h>
46
#include <arch/drivers/fhc.h>
46
#include <cpu.h>
47
#include <cpu.h>
47
#include <arch/asm.h>
48
#include <arch/asm.h>
48
#include <arch.h>
49
#include <arch.h>
49
#include <typedefs.h>
50
#include <typedefs.h>
50
#include <console/chardev.h>
51
#include <console/chardev.h>
51
#include <console/console.h>
52
#include <console/console.h>
52
#include <interrupt.h>
53
#include <interrupt.h>
53
#include <sysinfo/sysinfo.h>
54
#include <sysinfo/sysinfo.h>
54
#include <print.h>
55
#include <print.h>
55
 
56
 
56
/*
57
/*
57
 * These codes read from z8530 data register are silently ignored.
58
 * These codes read from z8530 data register are silently ignored.
58
 */
59
 */
59
#define IGNORE_CODE 0x7f        /* all keys up */
60
#define IGNORE_CODE 0x7f        /* all keys up */
60
 
61
 
61
bool z8530_belongs_to_kernel = true;
-
 
62
 
-
 
63
static z8530_t z8530;       /**< z8530 device structure. */
62
static z8530_t z8530;       /**< z8530 device structure. */
64
static irq_t z8530_irq;     /**< z8530's IRQ. */
63
static irq_t z8530_irq;     /**< z8530's IRQ. */
65
 
64
 
66
static void z8530_suspend(chardev_t *);
65
static void z8530_suspend(chardev_t *);
67
static void z8530_resume(chardev_t *);
66
static void z8530_resume(chardev_t *);
68
 
67
 
69
static chardev_operations_t ops = {
68
static chardev_operations_t ops = {
70
    .suspend = z8530_suspend,
69
    .suspend = z8530_suspend,
71
    .resume = z8530_resume,
70
    .resume = z8530_resume,
72
    .read = z8530_key_read
71
    .read = z8530_key_read
73
};
72
};
74
 
73
 
75
void z8530_wait(void);
-
 
76
 
-
 
77
/** Initialize keyboard and service interrupts using kernel routine */
74
/** Initialize keyboard and service interrupts using kernel routine. */
78
void z8530_grab(void)
75
void z8530_grab(void)
79
{
76
{
80
    z8530_belongs_to_kernel = true;
-
 
81
}
77
}
82
 
78
 
83
/** Resume the former interrupt vector */
79
/** Resume the former IPC notification behavior. */
84
void z8530_release(void)
80
void z8530_release(void)
85
{
81
{
86
    z8530_belongs_to_kernel = false;
-
 
87
}
82
}
88
 
83
 
89
/** Initialize z8530. */
84
/** Initialize z8530. */
90
void z8530_init(devno_t devno, inr_t inr, uintptr_t vaddr)
85
void z8530_init(devno_t devno, inr_t inr, uintptr_t vaddr)
91
{
86
{
92
    chardev_initialize("z8530_kbd", &kbrd, &ops);
87
    chardev_initialize("z8530_kbd", &kbrd, &ops);
93
    stdin = &kbrd;
88
    stdin = &kbrd;
94
 
89
 
95
    z8530.devno = devno;
90
    z8530.devno = devno;
96
    z8530.reg = (uint8_t *) vaddr;
91
    z8530.reg = (uint8_t *) vaddr;
97
 
92
 
98
    irq_initialize(&z8530_irq);
93
    irq_initialize(&z8530_irq);
99
    z8530_irq.devno = devno;
94
    z8530_irq.devno = devno;
100
    z8530_irq.inr = inr;
95
    z8530_irq.inr = inr;
101
    z8530_irq.claim = z8530_claim;
96
    z8530_irq.claim = z8530_claim;
102
    z8530_irq.handler = z8530_irq_handler;
97
    z8530_irq.handler = z8530_irq_handler;
103
    irq_register(&z8530_irq);
98
    irq_register(&z8530_irq);
104
 
99
 
105
    sysinfo_set_item_val("kbd", NULL, true);
100
    sysinfo_set_item_val("kbd", NULL, true);
106
    sysinfo_set_item_val("kbd.devno", NULL, devno);
101
    sysinfo_set_item_val("kbd.devno", NULL, devno);
107
    sysinfo_set_item_val("kbd.inr", NULL, inr);
102
    sysinfo_set_item_val("kbd.inr", NULL, inr);
108
    sysinfo_set_item_val("kbd.address.virtual", NULL, vaddr);
103
    sysinfo_set_item_val("kbd.address.virtual", NULL, vaddr);
109
 
104
 
110
    (void) z8530_read_a(&z8530, RR8);
105
    (void) z8530_read_a(&z8530, RR8);
111
 
106
 
112
    /*
107
    /*
113
     * Clear any pending TX interrupts or we never manage
108
     * Clear any pending TX interrupts or we never manage
114
     * to set FHC UART interrupt state to idle.
109
     * to set FHC UART interrupt state to idle.
115
     */
110
     */
116
    z8530_write_a(&z8530, WR0, WR0_TX_IP_RST);
111
    z8530_write_a(&z8530, WR0, WR0_TX_IP_RST);
117
 
112
 
118
    z8530_write_a(&z8530, WR1, WR1_IARCSC);     /* interrupt on all characters */
113
    z8530_write_a(&z8530, WR1, WR1_IARCSC);     /* interrupt on all characters */
119
 
114
 
120
    /* 8 bits per character and enable receiver */
115
    /* 8 bits per character and enable receiver */
121
    z8530_write_a(&z8530, WR3, WR3_RX8BITSCH | WR3_RX_ENABLE);
116
    z8530_write_a(&z8530, WR3, WR3_RX8BITSCH | WR3_RX_ENABLE);
122
   
117
   
123
    z8530_write_a(&z8530, WR9, WR9_MIE);        /* Master Interrupt Enable. */
118
    z8530_write_a(&z8530, WR9, WR9_MIE);        /* Master Interrupt Enable. */
124
}
119
}
125
 
120
 
126
/** Process z8530 interrupt.
121
/** Process z8530 interrupt.
127
 *
122
 *
128
 * @param n Interrupt vector.
123
 * @param n Interrupt vector.
129
 * @param istate Interrupted state.
124
 * @param istate Interrupted state.
130
 */
125
 */
131
void z8530_interrupt(void)
126
void z8530_interrupt(void)
132
{
127
{
133
    z8530_poll();
128
    z8530_poll();
134
}
129
}
135
 
130
 
136
/** Wait until the controller reads its data. */
-
 
137
void z8530_wait(void) {
-
 
138
}
-
 
139
 
-
 
140
/* Called from getc(). */
131
/* Called from getc(). */
141
void z8530_resume(chardev_t *d)
132
void z8530_resume(chardev_t *d)
142
{
133
{
143
}
134
}
144
 
135
 
145
/* Called from getc(). */
136
/* Called from getc(). */
146
void z8530_suspend(chardev_t *d)
137
void z8530_suspend(chardev_t *d)
147
{
138
{
148
}
139
}
149
 
140
 
150
char z8530_key_read(chardev_t *d)
141
char z8530_key_read(chardev_t *d)
151
{
142
{
152
    char ch;   
143
    char ch;   
153
 
144
 
154
    while(!(ch = active_read_buff_read())) {
145
    while(!(ch = active_read_buff_read())) {
155
        uint8_t x;
146
        uint8_t x;
156
        while (!(z8530_read_a(&z8530, RR0) & RR0_RCA))
147
        while (!(z8530_read_a(&z8530, RR0) & RR0_RCA))
157
            ;
148
            ;
158
        x = z8530_read_a(&z8530, RR8);
149
        x = z8530_read_a(&z8530, RR8);
159
        if (x != IGNORE_CODE) {
150
        if (x != IGNORE_CODE) {
160
            if (x & KEY_RELEASE)
151
            if (x & KEY_RELEASE)
161
                key_released(x ^ KEY_RELEASE);
152
                key_released(x ^ KEY_RELEASE);
162
            else
153
            else
163
                active_read_key_pressed(x);
154
                active_read_key_pressed(x);
164
        }
155
        }
165
    }
156
    }
166
    return ch;
157
    return ch;
167
}
158
}
168
 
159
 
169
/** Poll for key press and release events.
160
/** Poll for key press and release events.
170
 *
161
 *
171
 * This function can be used to implement keyboard polling.
162
 * This function can be used to implement keyboard polling.
172
 */
163
 */
173
void z8530_poll(void)
164
void z8530_poll(void)
174
{
165
{
175
    uint8_t x;
166
    uint8_t x;
176
 
167
 
177
    while (z8530_read_a(&z8530, RR0) & RR0_RCA) {
168
    while (z8530_read_a(&z8530, RR0) & RR0_RCA) {
178
        x = z8530_read_a(&z8530, RR8);
169
        x = z8530_read_a(&z8530, RR8);
179
        if (x != IGNORE_CODE) {
170
        if (x != IGNORE_CODE) {
180
            if (x & KEY_RELEASE)
171
            if (x & KEY_RELEASE)
181
                key_released(x ^ KEY_RELEASE);
172
                key_released(x ^ KEY_RELEASE);
182
            else
173
            else
183
                key_pressed(x);
174
                key_pressed(x);
184
        }
175
        }
185
    }
176
    }
186
}
177
}
187
 
178
 
188
irq_ownership_t z8530_claim(void)
179
irq_ownership_t z8530_claim(void)
189
{
180
{
190
    return (z8530_read_a(&z8530, RR0) & RR0_RCA);
181
    return (z8530_read_a(&z8530, RR0) & RR0_RCA);
191
}
182
}
192
 
183
 
193
void z8530_irq_handler(irq_t *irq, void *arg, ...)
184
void z8530_irq_handler(irq_t *irq, void *arg, ...)
194
{
185
{
195
    /*
186
    /*
196
     * So far, we know we got this interrupt through the FHC.
187
     * So far, we know we got this interrupt through the FHC.
197
     * Since we don't have enough information about the FHC and
188
     * Since we don't have enough documentation about the FHC
198
     * because the interrupt looks like level sensitive,
189
     * and because the interrupt looks like level sensitive,
199
     * we cannot handle it by scheduling one of the level
190
     * we cannot handle it by scheduling one of the level
200
     * interrupt traps. Process the interrupt directly.
191
     * interrupt traps. Process the interrupt directly.
201
     */
192
     */
202
    if (z8530_belongs_to_kernel)
193
    if (irq->notif_cfg.answerbox)
203
        z8530_interrupt();
194
        ipc_irq_send_notif(irq);
204
    else
195
    else
205
        ipc_irq_send_notif(0);
196
        z8530_interrupt();
206
    fhc_clear_interrupt(central_fhc, irq->inr);
197
    fhc_clear_interrupt(central_fhc, irq->inr);
207
}
198
}
208
 
199
 
209
/** @}
200
/** @}
210
 */
201
 */
211
 
202