1 | /*
|
---|
2 | * Copyright (c) 2006 Josef Cejka
|
---|
3 | * Copyright (c) 2011 Jan Vesely
|
---|
4 | * Copyright (c) 2017 Jiri Svoboda
|
---|
5 | * All rights reserved.
|
---|
6 | *
|
---|
7 | * Redistribution and use in source and binary forms, with or without
|
---|
8 | * modification, are permitted provided that the following conditions
|
---|
9 | * are met:
|
---|
10 | *
|
---|
11 | * - Redistributions of source code must retain the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer.
|
---|
13 | * - Redistributions in binary form must reproduce the above copyright
|
---|
14 | * notice, this list of conditions and the following disclaimer in the
|
---|
15 | * documentation and/or other materials provided with the distribution.
|
---|
16 | * - The name of the author may not be used to endorse or promote products
|
---|
17 | * derived from this software without specific prior written permission.
|
---|
18 | *
|
---|
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
29 | */
|
---|
30 |
|
---|
31 | /** @addtogroup kbd_port
|
---|
32 | * @ingroup kbd
|
---|
33 | * @{
|
---|
34 | */
|
---|
35 |
|
---|
36 | /** @file
|
---|
37 | * @brief i8042 port driver.
|
---|
38 | */
|
---|
39 |
|
---|
40 | #ifndef i8042_H_
|
---|
41 | #define i8042_H_
|
---|
42 |
|
---|
43 | #include <adt/circ_buf.h>
|
---|
44 | #include <io/chardev_srv.h>
|
---|
45 | #include <ddi.h>
|
---|
46 | #include <fibril_synch.h>
|
---|
47 | #include <ddf/driver.h>
|
---|
48 |
|
---|
49 | #define NAME "i8042"
|
---|
50 |
|
---|
51 | #define BUFFER_SIZE 12
|
---|
52 |
|
---|
53 | /** i8042 HW I/O interface */
|
---|
54 | typedef struct {
|
---|
55 | ioport8_t data;
|
---|
56 | uint8_t pad[3];
|
---|
57 | ioport8_t status;
|
---|
58 | } __attribute__((packed)) i8042_regs_t;
|
---|
59 |
|
---|
60 | /** i8042 Port. */
|
---|
61 | typedef struct {
|
---|
62 | /** Controller */
|
---|
63 | struct i8042 *ctl;
|
---|
64 | /** Device function */
|
---|
65 | ddf_fun_t *fun;
|
---|
66 | /** Character device server data */
|
---|
67 | chardev_srvs_t cds;
|
---|
68 | /** Circular buffer */
|
---|
69 | circ_buf_t cbuf;
|
---|
70 | /** Buffer data space */
|
---|
71 | uint8_t buf_data[BUFFER_SIZE];
|
---|
72 | /** Protect buffer */
|
---|
73 | fibril_mutex_t buf_lock;
|
---|
74 | /** Signal new data in buffer */
|
---|
75 | fibril_condvar_t buf_cv;
|
---|
76 | } i8042_port_t;
|
---|
77 |
|
---|
78 | /** i8042 Controller. */
|
---|
79 | typedef struct i8042 {
|
---|
80 | /**< I/O registers. */
|
---|
81 | i8042_regs_t *regs;
|
---|
82 | /** Keyboard port */
|
---|
83 | i8042_port_t *kbd;
|
---|
84 | /** AUX port */
|
---|
85 | i8042_port_t *aux;
|
---|
86 | /** Prevents simultanous port writes.*/
|
---|
87 | fibril_mutex_t write_guard;
|
---|
88 | } i8042_t;
|
---|
89 |
|
---|
90 | extern errno_t i8042_init(i8042_t *, addr_range_t *, int, int, ddf_dev_t *);
|
---|
91 |
|
---|
92 | #endif
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * @}
|
---|
96 | */
|
---|