[a2bd204f] | 1 | /*
|
---|
| 2 | * Copyright (c) 2006 Josef Cejka
|
---|
[9f97ffe] | 3 | * Copyright (c) 2011 Jan Vesely
|
---|
[0851a3d] | 4 | * Copyright (c) 2017 Jiri Svoboda
|
---|
[a2bd204f] | 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 | */
|
---|
[2df6f6fe] | 30 |
|
---|
[a2bd204f] | 31 | /** @addtogroup kbd_port
|
---|
| 32 | * @ingroup kbd
|
---|
| 33 | * @{
|
---|
| 34 | */
|
---|
[2df6f6fe] | 35 |
|
---|
[a2bd204f] | 36 | /** @file
|
---|
| 37 | * @brief i8042 port driver.
|
---|
| 38 | */
|
---|
| 39 |
|
---|
| 40 | #ifndef i8042_H_
|
---|
| 41 | #define i8042_H_
|
---|
| 42 |
|
---|
[e7588a8] | 43 | #include <adt/circ_buf.h>
|
---|
[75751db6] | 44 | #include <io/chardev_srv.h>
|
---|
[7ee7e6a] | 45 | #include <ddi.h>
|
---|
[b1f44b4] | 46 | #include <fibril_synch.h>
|
---|
[ee163b3] | 47 | #include <ddf/driver.h>
|
---|
[9f97ffe] | 48 |
|
---|
[2df6f6fe] | 49 | #define NAME "i8042"
|
---|
| 50 |
|
---|
| 51 | #define BUFFER_SIZE 12
|
---|
[9f97ffe] | 52 |
|
---|
[a2bd204f] | 53 | /** i8042 HW I/O interface */
|
---|
[7f1669f] | 54 | typedef struct {
|
---|
[a2bd204f] | 55 | ioport8_t data;
|
---|
| 56 | uint8_t pad[3];
|
---|
| 57 | ioport8_t status;
|
---|
[1433ecda] | 58 | } __attribute__((packed)) i8042_regs_t;
|
---|
[a2bd204f] | 59 |
|
---|
[75751db6] | 60 | /** i8042 Port. */
|
---|
| 61 | typedef struct {
|
---|
[0851a3d] | 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;
|
---|
[75751db6] | 76 | } i8042_port_t;
|
---|
| 77 |
|
---|
| 78 | /** i8042 Controller. */
|
---|
[336f03b] | 79 | typedef struct i8042 {
|
---|
[0851a3d] | 80 | /**< I/O registers. */
|
---|
| 81 | i8042_regs_t *regs;
|
---|
| 82 | /** Keyboard port */
|
---|
[75751db6] | 83 | i8042_port_t *kbd;
|
---|
[0851a3d] | 84 | /** AUX port */
|
---|
[75751db6] | 85 | i8042_port_t *aux;
|
---|
[0851a3d] | 86 | /** Prevents simultanous port writes.*/
|
---|
| 87 | fibril_mutex_t write_guard;
|
---|
[336f03b] | 88 | } i8042_t;
|
---|
[78aa0ab] | 89 |
|
---|
[b7fd2a0] | 90 | extern errno_t i8042_init(i8042_t *, addr_range_t *, int, int, ddf_dev_t *);
|
---|
[2df6f6fe] | 91 |
|
---|
[ee163b3] | 92 | #endif
|
---|
[2df6f6fe] | 93 |
|
---|
[a2bd204f] | 94 | /**
|
---|
| 95 | * @}
|
---|
| 96 | */
|
---|