Subversion Repositories HelenOS

Rev

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

Rev 1875 Rev 1896
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/fhc.h>
41
#include <arch/drivers/fhc.h>
42
#include <arch/drivers/z8530.h>
42
#include <arch/drivers/z8530.h>
43
#include <arch/interrupt.h>
43
#include <arch/interrupt.h>
44
#include <arch/drivers/kbd.h>
44
#include <arch/drivers/kbd.h>
45
#include <cpu.h>
45
#include <cpu.h>
46
#include <arch/asm.h>
46
#include <arch/asm.h>
47
#include <arch.h>
47
#include <arch.h>
48
#include <typedefs.h>
48
#include <typedefs.h>
49
#include <console/chardev.h>
49
#include <console/chardev.h>
50
#include <console/console.h>
50
#include <console/console.h>
51
#include <interrupt.h>
51
#include <interrupt.h>
52
#include <sysinfo/sysinfo.h>
52
#include <sysinfo/sysinfo.h>
53
#include <print.h>
53
#include <print.h>
54
 
54
 
55
/*
55
/*
56
 * These codes read from z8530 data register are silently ignored.
56
 * These codes read from z8530 data register are silently ignored.
57
 */
57
 */
58
#define IGNORE_CODE 0x7f        /* all keys up */
58
#define IGNORE_CODE 0x7f        /* all keys up */
59
 
59
 
60
bool z8530_belongs_to_kernel = true;
60
bool z8530_belongs_to_kernel = true;
61
 
61
 
62
static void z8530_suspend(chardev_t *);
62
static void z8530_suspend(chardev_t *);
63
static void z8530_resume(chardev_t *);
63
static void z8530_resume(chardev_t *);
64
 
64
 
65
chardev_t kbrd;
-
 
66
static chardev_operations_t ops = {
65
static chardev_operations_t ops = {
67
    .suspend = z8530_suspend,
66
    .suspend = z8530_suspend,
68
    .resume = z8530_resume,
67
    .resume = z8530_resume,
69
    .read = key_read
68
    .read = z8530_key_read
70
};
69
};
71
 
70
 
72
void z8530_wait(void);
71
void z8530_wait(void);
73
 
72
 
74
/** Initialize keyboard and service interrupts using kernel routine */
73
/** Initialize keyboard and service interrupts using kernel routine */
75
void z8530_grab(void)
74
void z8530_grab(void)
76
{
75
{
77
    z8530_belongs_to_kernel = true;
76
    z8530_belongs_to_kernel = true;
78
}
77
}
79
 
78
 
80
/** Resume the former interrupt vector */
79
/** Resume the former interrupt vector */
81
void z8530_release(void)
80
void z8530_release(void)
82
{
81
{
83
    z8530_belongs_to_kernel = false;
82
    z8530_belongs_to_kernel = false;
84
}
83
}
85
 
84
 
86
/** Initialize z8530. */
85
/** Initialize z8530. */
87
void z8530_init(void)
86
void z8530_init(void)
88
{
87
{
89
    chardev_initialize("z8530_kbd", &kbrd, &ops);
88
    chardev_initialize("z8530_kbd", &kbrd, &ops);
90
    stdin = &kbrd;
89
    stdin = &kbrd;
91
 
90
 
92
    sysinfo_set_item_val("kbd", NULL, true);
91
    sysinfo_set_item_val("kbd", NULL, true);
93
    sysinfo_set_item_val("kbd.irq", NULL, 0);
92
    sysinfo_set_item_val("kbd.irq", NULL, 0);
94
    sysinfo_set_item_val("kbd.address.virtual", NULL, (uintptr_t) kbd_virt_address);
93
    sysinfo_set_item_val("kbd.address.virtual", NULL, (uintptr_t) kbd_virt_address);
95
 
94
 
96
    (void) z8530_read_a(RR8);
95
    (void) z8530_read_a(RR8);
97
 
96
 
98
    /*
97
    /*
99
     * Clear any pending TX interrupts or we never manage
98
     * Clear any pending TX interrupts or we never manage
100
     * to set FHC UART interrupt state to idle.
99
     * to set FHC UART interrupt state to idle.
101
     */
100
     */
102
    z8530_write_a(WR0, WR0_TX_IP_RST);
101
    z8530_write_a(WR0, WR0_TX_IP_RST);
103
 
102
 
104
    z8530_write_a(WR1, WR1_IARCSC);     /* interrupt on all characters */
103
    z8530_write_a(WR1, WR1_IARCSC);     /* interrupt on all characters */
105
 
104
 
106
    /* 8 bits per character and enable receiver */
105
    /* 8 bits per character and enable receiver */
107
    z8530_write_a(WR3, WR3_RX8BITSCH | WR3_RX_ENABLE);
106
    z8530_write_a(WR3, WR3_RX8BITSCH | WR3_RX_ENABLE);
108
   
107
   
109
    z8530_write_a(WR9, WR9_MIE);        /* Master Interrupt Enable. */
108
    z8530_write_a(WR9, WR9_MIE);        /* Master Interrupt Enable. */
110
   
109
   
111
    /*
110
    /*
112
     * We need to initialize the FireHose Controller,
111
     * We need to initialize the FireHose Controller,
113
     * to which is this z8530 attached. Otherwise
112
     * to which is this z8530 attached. Otherwise
114
     * interrupts generated by the z8530 would not
113
     * interrupts generated by the z8530 would not
115
     * be forwarded to the CPU.
114
     * be forwarded to the CPU.
116
     */
115
     */
117
    fhc_init();
116
    fhc_init();
118
}
117
}
119
 
118
 
120
/** Process z8530 interrupt.
119
/** Process z8530 interrupt.
121
 *
120
 *
122
 * @param n Interrupt vector.
121
 * @param n Interrupt vector.
123
 * @param istate Interrupted state.
122
 * @param istate Interrupted state.
124
 */
123
 */
125
void z8530_interrupt(void)
124
void z8530_interrupt(void)
126
{
125
{
127
    z8530_poll();
126
    z8530_poll();
128
}
127
}
129
 
128
 
130
/** Wait until the controller reads its data. */
129
/** Wait until the controller reads its data. */
131
void z8530_wait(void) {
130
void z8530_wait(void) {
132
}
131
}
133
 
132
 
134
/* Called from getc(). */
133
/* Called from getc(). */
135
void z8530_resume(chardev_t *d)
134
void z8530_resume(chardev_t *d)
136
{
135
{
137
}
136
}
138
 
137
 
139
/* Called from getc(). */
138
/* Called from getc(). */
140
void z8530_suspend(chardev_t *d)
139
void z8530_suspend(chardev_t *d)
141
{
140
{
142
}
141
}
143
 
142
 
144
char key_read(chardev_t *d)
143
char z8530_key_read(chardev_t *d)
145
{
144
{
146
    char ch;   
145
    char ch;   
147
 
146
 
148
    while(!(ch = active_read_buff_read())) {
147
    while(!(ch = active_read_buff_read())) {
149
        uint8_t x;
148
        uint8_t x;
150
        while (!(z8530_read_a(RR0) & RR0_RCA))
149
        while (!(z8530_read_a(RR0) & RR0_RCA))
151
            ;
150
            ;
152
        x = z8530_read_a(RR8);
151
        x = z8530_read_a(RR8);
153
        if (x != IGNORE_CODE) {
152
        if (x != IGNORE_CODE) {
154
            if (x & KEY_RELEASE)
153
            if (x & KEY_RELEASE)
155
                key_released(x ^ KEY_RELEASE);
154
                key_released(x ^ KEY_RELEASE);
156
            else
155
            else
157
                active_read_key_pressed(x);
156
                active_read_key_pressed(x);
158
        }
157
        }
159
    }
158
    }
160
    return ch;
159
    return ch;
161
}
160
}
162
 
161
 
163
/** Poll for key press and release events.
162
/** Poll for key press and release events.
164
 *
163
 *
165
 * This function can be used to implement keyboard polling.
164
 * This function can be used to implement keyboard polling.
166
 */
165
 */
167
void z8530_poll(void)
166
void z8530_poll(void)
168
{
167
{
169
    uint8_t x;
168
    uint8_t x;
170
 
169
 
171
    while (z8530_read_a(RR0) & RR0_RCA) {
170
    while (z8530_read_a(RR0) & RR0_RCA) {
172
        x = z8530_read_a(RR8);
171
        x = z8530_read_a(RR8);
173
        if (x != IGNORE_CODE) {
172
        if (x != IGNORE_CODE) {
174
            if (x & KEY_RELEASE)
173
            if (x & KEY_RELEASE)
175
                key_released(x ^ KEY_RELEASE);
174
                key_released(x ^ KEY_RELEASE);
176
            else
175
            else
177
                key_pressed(x);
176
                key_pressed(x);
178
        }
177
        }
179
    }
178
    }
180
}
179
}
181
 
180
 
182
/** @}
181
/** @}
183
 */
182
 */
184
 
183