[a2bd204f] | 1 | /*
|
---|
[797ab95] | 2 | * Copyright (c) 2025 Jiri Svoboda
|
---|
[a2bd204f] | 3 | * Copyright (c) 2006 Josef Cejka
|
---|
[9f97ffe] | 4 | * Copyright (c) 2011 Jan Vesely
|
---|
[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 |
|
---|
[c8ea6eca] | 31 | /** @addtogroup i8042
|
---|
[a2bd204f] | 32 | * @{
|
---|
| 33 | */
|
---|
[2df6f6fe] | 34 |
|
---|
[a2bd204f] | 35 | /** @file
|
---|
| 36 | * @brief i8042 port driver.
|
---|
| 37 | */
|
---|
| 38 |
|
---|
| 39 | #ifndef i8042_H_
|
---|
| 40 | #define i8042_H_
|
---|
| 41 |
|
---|
[e7588a8] | 42 | #include <adt/circ_buf.h>
|
---|
[75751db6] | 43 | #include <io/chardev_srv.h>
|
---|
[7ee7e6a] | 44 | #include <ddi.h>
|
---|
[b1f44b4] | 45 | #include <fibril_synch.h>
|
---|
[ee163b3] | 46 | #include <ddf/driver.h>
|
---|
[9f97ffe] | 47 |
|
---|
[2df6f6fe] | 48 | #define NAME "i8042"
|
---|
| 49 |
|
---|
[5d1ff11] | 50 | /** Buffer needs to be large enough for rate at which keyboard or mouse
|
---|
| 51 | * produces data (mouse produces data at faster rate).
|
---|
| 52 | */
|
---|
| 53 | #define BUFFER_SIZE 64
|
---|
[9f97ffe] | 54 |
|
---|
[a2bd204f] | 55 | /** i8042 HW I/O interface */
|
---|
[7f1669f] | 56 | typedef struct {
|
---|
[a2bd204f] | 57 | ioport8_t data;
|
---|
| 58 | uint8_t pad[3];
|
---|
| 59 | ioport8_t status;
|
---|
[1433ecda] | 60 | } __attribute__((packed)) i8042_regs_t;
|
---|
[a2bd204f] | 61 |
|
---|
[75751db6] | 62 | /** i8042 Port. */
|
---|
| 63 | typedef struct {
|
---|
[0851a3d] | 64 | /** Controller */
|
---|
| 65 | struct i8042 *ctl;
|
---|
| 66 | /** Device function */
|
---|
| 67 | ddf_fun_t *fun;
|
---|
| 68 | /** Character device server data */
|
---|
| 69 | chardev_srvs_t cds;
|
---|
| 70 | /** Circular buffer */
|
---|
| 71 | circ_buf_t cbuf;
|
---|
| 72 | /** Buffer data space */
|
---|
| 73 | uint8_t buf_data[BUFFER_SIZE];
|
---|
| 74 | /** Protect buffer */
|
---|
| 75 | fibril_mutex_t buf_lock;
|
---|
| 76 | /** Signal new data in buffer */
|
---|
| 77 | fibril_condvar_t buf_cv;
|
---|
[9754ed2] | 78 | /** Interrupt number */
|
---|
| 79 | int irq;
|
---|
[75751db6] | 80 | } i8042_port_t;
|
---|
| 81 |
|
---|
| 82 | /** i8042 Controller. */
|
---|
[336f03b] | 83 | typedef struct i8042 {
|
---|
[60744cb] | 84 | /** DDF device */
|
---|
| 85 | ddf_dev_t *dev;
|
---|
[d1582b50] | 86 | /** I/O registers. */
|
---|
[0851a3d] | 87 | i8042_regs_t *regs;
|
---|
| 88 | /** Keyboard port */
|
---|
[75751db6] | 89 | i8042_port_t *kbd;
|
---|
[0851a3d] | 90 | /** AUX port */
|
---|
[75751db6] | 91 | i8042_port_t *aux;
|
---|
[d1582b50] | 92 | /** Prevents simultanous port writes. */
|
---|
[0851a3d] | 93 | fibril_mutex_t write_guard;
|
---|
[336f03b] | 94 | } i8042_t;
|
---|
[78aa0ab] | 95 |
|
---|
[b7fd2a0] | 96 | extern errno_t i8042_init(i8042_t *, addr_range_t *, int, int, ddf_dev_t *);
|
---|
[797ab95] | 97 | extern void i8042_quiesce(i8042_t *);
|
---|
[2df6f6fe] | 98 |
|
---|
[ee163b3] | 99 | #endif
|
---|
[2df6f6fe] | 100 |
|
---|
[a2bd204f] | 101 | /**
|
---|
| 102 | * @}
|
---|
| 103 | */
|
---|