Subversion Repositories HelenOS

Rev

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

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