Rev 3961 | Rev 4042 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | jermar | 1 | /* |
3982 | jermar | 2 | * Copyright (c) 2009 Jakub Jermar |
1 | jermar | 3 | * All rights reserved. |
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
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 |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
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 |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
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 |
||
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 |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
1754 | jermar | 29 | /** @addtogroup genarch |
1702 | cejka | 30 | * @{ |
31 | */ |
||
1754 | jermar | 32 | /** |
1757 | jermar | 33 | * @file |
3961 | jermar | 34 | * @brief Zilog 8530 serial port driver. |
1702 | cejka | 35 | */ |
36 | |||
1842 | jermar | 37 | #include <genarch/kbd/z8530.h> |
1843 | jermar | 38 | #include <genarch/kbd/key.h> |
1842 | jermar | 39 | #include <genarch/kbd/scanc.h> |
40 | #include <genarch/kbd/scanc_sun.h> |
||
1875 | jermar | 41 | #include <arch/drivers/kbd.h> |
3961 | jermar | 42 | #include <console/console.h> |
511 | jermar | 43 | #include <console/chardev.h> |
3961 | jermar | 44 | #include <ddi/irq.h> |
45 | #include <arch/asm.h> |
||
46 | #include <mm/slab.h> |
||
1 | jermar | 47 | |
3961 | jermar | 48 | static inline void z8530_write(ioport8_t *ctl, uint8_t reg, uint8_t val) |
49 | { |
||
50 | /* |
||
51 | * Registers 8-15 will automatically issue the Point High |
||
52 | * command as their bit 3 is 1. |
||
53 | */ |
||
54 | pio_write_8(ctl, reg); /* select register */ |
||
55 | pio_write_8(ctl, val); /* write value */ |
||
56 | } |
||
57 | |||
58 | static inline uint8_t z8530_read(ioport8_t *ctl, uint8_t reg) |
||
59 | { |
||
60 | /* |
||
61 | * Registers 8-15 will automatically issue the Point High |
||
62 | * command as their bit 3 is 1. |
||
63 | */ |
||
64 | pio_write_8(ctl, reg); /* select register */ |
||
65 | return pio_read_8(ctl); |
||
66 | } |
||
67 | |||
670 | vana | 68 | /* |
1842 | jermar | 69 | * These codes read from z8530 data register are silently ignored. |
895 | jermar | 70 | */ |
1842 | jermar | 71 | #define IGNORE_CODE 0x7f /* all keys up */ |
895 | jermar | 72 | |
1842 | jermar | 73 | static void z8530_suspend(chardev_t *); |
74 | static void z8530_resume(chardev_t *); |
||
511 | jermar | 75 | |
76 | static chardev_operations_t ops = { |
||
1842 | jermar | 77 | .suspend = z8530_suspend, |
78 | .resume = z8530_resume, |
||
511 | jermar | 79 | }; |
80 | |||
3961 | jermar | 81 | /** Initialize z8530. */ |
82 | bool |
||
83 | z8530_init(z8530_t *dev, devno_t devno, inr_t inr, cir_t cir, void *cir_arg) |
||
1 | jermar | 84 | { |
3961 | jermar | 85 | z8530_instance_t *instance; |
1944 | jermar | 86 | |
3961 | jermar | 87 | chardev_initialize("z8530_kbd", &kbrd, &ops); |
88 | stdin = &kbrd; |
||
1925 | jermar | 89 | |
3961 | jermar | 90 | instance = malloc(sizeof(z8530_instance_t), FRAME_ATOMIC); |
91 | if (!instance) |
||
92 | return false; |
||
93 | |||
94 | instance->devno = devno; |
||
95 | instance->z8530 = dev; |
||
96 | |||
97 | irq_initialize(&instance->irq); |
||
98 | instance->irq.devno = devno; |
||
99 | instance->irq.inr = inr; |
||
100 | instance->irq.claim = z8530_claim; |
||
101 | instance->irq.handler = z8530_irq_handler; |
||
102 | instance->irq.instance = instance; |
||
103 | instance->irq.cir = cir; |
||
104 | instance->irq.cir_arg = cir_arg; |
||
105 | irq_register(&instance->irq); |
||
106 | |||
107 | (void) z8530_read(&dev->ctl_a, RR8); |
||
108 | |||
1925 | jermar | 109 | /* |
110 | * Clear any pending TX interrupts or we never manage |
||
111 | * to set FHC UART interrupt state to idle. |
||
112 | */ |
||
3961 | jermar | 113 | z8530_write(&dev->ctl_a, WR0, WR0_TX_IP_RST); |
1925 | jermar | 114 | |
3655 | jermar | 115 | /* interrupt on all characters */ |
3961 | jermar | 116 | z8530_write(&dev->ctl_a, WR1, WR1_IARCSC); |
1925 | jermar | 117 | |
118 | /* 8 bits per character and enable receiver */ |
||
3961 | jermar | 119 | z8530_write(&dev->ctl_a, WR3, WR3_RX8BITSCH | WR3_RX_ENABLE); |
1925 | jermar | 120 | |
3655 | jermar | 121 | /* Master Interrupt Enable. */ |
3961 | jermar | 122 | z8530_write(&dev->ctl_a, WR9, WR9_MIE); |
1849 | jermar | 123 | |
3961 | jermar | 124 | return true; |
1 | jermar | 125 | } |
126 | |||
511 | jermar | 127 | /* Called from getc(). */ |
1842 | jermar | 128 | void z8530_resume(chardev_t *d) |
511 | jermar | 129 | { |
130 | } |
||
131 | |||
132 | /* Called from getc(). */ |
||
1842 | jermar | 133 | void z8530_suspend(chardev_t *d) |
511 | jermar | 134 | { |
135 | } |
||
878 | vana | 136 | |
3961 | jermar | 137 | irq_ownership_t z8530_claim(irq_t *irq) |
878 | vana | 138 | { |
3961 | jermar | 139 | z8530_instance_t *instance = irq->instance; |
140 | z8530_t *dev = instance->z8530; |
||
878 | vana | 141 | |
3961 | jermar | 142 | return (z8530_read(&dev->ctl_a, RR0) & RR0_RCA); |
878 | vana | 143 | } |
895 | jermar | 144 | |
3961 | jermar | 145 | void z8530_irq_handler(irq_t *irq) |
895 | jermar | 146 | { |
3961 | jermar | 147 | z8530_instance_t *instance = irq->instance; |
148 | z8530_t *dev = instance->z8530; |
||
1780 | jermar | 149 | uint8_t x; |
895 | jermar | 150 | |
3961 | jermar | 151 | if (z8530_read(&dev->ctl_a, RR0) & RR0_RCA) { |
152 | x = z8530_read(&dev->ctl_a, RR8); |
||
895 | jermar | 153 | if (x != IGNORE_CODE) { |
154 | if (x & KEY_RELEASE) |
||
155 | key_released(x ^ KEY_RELEASE); |
||
156 | else |
||
157 | key_pressed(x); |
||
158 | } |
||
159 | } |
||
160 | } |
||
1702 | cejka | 161 | |
1754 | jermar | 162 | /** @} |
1702 | cejka | 163 | */ |