| 1 | /*
|
|---|
| 2 | * Copyright (c) 2009 Vineeth Pillai
|
|---|
| 3 | * Copyright (c) 2011 Jiri Svoboda
|
|---|
| 4 | * All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 7 | * modification, are permitted provided that the following conditions
|
|---|
| 8 | * are met:
|
|---|
| 9 | *
|
|---|
| 10 | * - Redistributions of source code must retain the above copyright
|
|---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 14 | * documentation and/or other materials provided with the distribution.
|
|---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 16 | * derived from this software without specific prior written permission.
|
|---|
| 17 | *
|
|---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 28 | */
|
|---|
| 29 |
|
|---|
| 30 | /** @addtogroup kbd_port
|
|---|
| 31 | * @ingroup kbd
|
|---|
| 32 | * @{
|
|---|
| 33 | */
|
|---|
| 34 | /** @file
|
|---|
| 35 | * @brief pl050 port driver.
|
|---|
| 36 | */
|
|---|
| 37 |
|
|---|
| 38 | #include <ddi.h>
|
|---|
| 39 | #include <libarch/ddi.h>
|
|---|
| 40 | #include <async.h>
|
|---|
| 41 | #include <unistd.h>
|
|---|
| 42 | #include <sysinfo.h>
|
|---|
| 43 | #include <kbd_port.h>
|
|---|
| 44 | #include <kbd.h>
|
|---|
| 45 | #include <ddi.h>
|
|---|
| 46 | #include <stdio.h>
|
|---|
| 47 | #include <errno.h>
|
|---|
| 48 |
|
|---|
| 49 | static int pl050_port_init(kbd_dev_t *);
|
|---|
| 50 | static void pl050_port_yield(void);
|
|---|
| 51 | static void pl050_port_reclaim(void);
|
|---|
| 52 | static void pl050_port_write(uint8_t data);
|
|---|
| 53 |
|
|---|
| 54 | kbd_port_ops_t pl050_port = {
|
|---|
| 55 | .init = pl050_port_init,
|
|---|
| 56 | .yield = pl050_port_yield,
|
|---|
| 57 | .reclaim = pl050_port_reclaim,
|
|---|
| 58 | .write = pl050_port_write
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | static kbd_dev_t *kbd_dev;
|
|---|
| 62 |
|
|---|
| 63 | #define PL050_STAT_RXFULL (1 << 4)
|
|---|
| 64 |
|
|---|
| 65 | static irq_cmd_t pl050_cmds[] = {
|
|---|
| 66 | {
|
|---|
| 67 | .cmd = CMD_PIO_READ_8,
|
|---|
| 68 | .addr = NULL,
|
|---|
| 69 | .dstarg = 1
|
|---|
| 70 | },
|
|---|
| 71 | {
|
|---|
| 72 | .cmd = CMD_BTEST,
|
|---|
| 73 | .value = PL050_STAT_RXFULL,
|
|---|
| 74 | .srcarg = 1,
|
|---|
| 75 | .dstarg = 3
|
|---|
| 76 | },
|
|---|
| 77 | {
|
|---|
| 78 | .cmd = CMD_PREDICATE,
|
|---|
| 79 | .value = 2,
|
|---|
| 80 | .srcarg = 3
|
|---|
| 81 | },
|
|---|
| 82 | {
|
|---|
| 83 | .cmd = CMD_PIO_READ_8,
|
|---|
| 84 | .addr = NULL, /* Will be patched in run-time */
|
|---|
| 85 | .dstarg = 2
|
|---|
| 86 | },
|
|---|
| 87 | {
|
|---|
| 88 | .cmd = CMD_ACCEPT
|
|---|
| 89 | }
|
|---|
| 90 | };
|
|---|
| 91 |
|
|---|
| 92 | static irq_code_t pl050_kbd = {
|
|---|
| 93 | sizeof(pl050_cmds) / sizeof(irq_cmd_t),
|
|---|
| 94 | pl050_cmds
|
|---|
| 95 | };
|
|---|
| 96 |
|
|---|
| 97 | static void pl050_irq_handler(ipc_callid_t iid, ipc_call_t *call);
|
|---|
| 98 |
|
|---|
| 99 | static int pl050_port_init(kbd_dev_t *kdev)
|
|---|
| 100 | {
|
|---|
| 101 | kbd_dev = kdev;
|
|---|
| 102 |
|
|---|
| 103 | sysarg_t addr;
|
|---|
| 104 | if (sysinfo_get_value("kbd.address.status", &addr) != EOK)
|
|---|
| 105 | return -1;
|
|---|
| 106 |
|
|---|
| 107 | pl050_kbd.cmds[0].addr = (void *) addr;
|
|---|
| 108 |
|
|---|
| 109 | if (sysinfo_get_value("kbd.address.data", &addr) != EOK)
|
|---|
| 110 | return -1;
|
|---|
| 111 |
|
|---|
| 112 | pl050_kbd.cmds[3].addr = (void *) addr;
|
|---|
| 113 |
|
|---|
| 114 | sysarg_t inr;
|
|---|
| 115 | if (sysinfo_get_value("kbd.inr", &inr) != EOK)
|
|---|
| 116 | return -1;
|
|---|
| 117 |
|
|---|
| 118 | async_set_interrupt_received(pl050_irq_handler);
|
|---|
| 119 | register_irq(inr, device_assign_devno(), 0, &pl050_kbd);
|
|---|
| 120 |
|
|---|
| 121 | return 0;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | static void pl050_port_yield(void)
|
|---|
| 125 | {
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | static void pl050_port_reclaim(void)
|
|---|
| 129 | {
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | static void pl050_port_write(uint8_t data)
|
|---|
| 133 | {
|
|---|
| 134 | (void) data;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | static void pl050_irq_handler(ipc_callid_t iid, ipc_call_t *call)
|
|---|
| 138 | {
|
|---|
| 139 | kbd_push_data(kbd_dev, IPC_GET_ARG2(*call));
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | /**
|
|---|
| 143 | * @}
|
|---|
| 144 | */
|
|---|