Subversion Repositories HelenOS

Rev

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

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