source: mainline/uspace/srv/hid/input/port/z8530.c@ 60e5a856

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 60e5a856 was 5f88293, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Rename 'kbd' server to 'input' server.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2006 Martin Decky
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 Z8530 keyboard port driver.
36 */
37
38#include <ipc/irc.h>
39#include <async.h>
40#include <async_obsolete.h>
41#include <sysinfo.h>
42#include <kbd.h>
43#include <kbd_port.h>
44#include <sys/types.h>
45#include <ddi.h>
46#include <errno.h>
47
48static int z8530_port_init(kbd_dev_t *);
49static void z8530_port_yield(void);
50static void z8530_port_reclaim(void);
51static void z8530_port_write(uint8_t data);
52
53kbd_port_ops_t z8530_port = {
54 .init = z8530_port_init,
55 .yield = z8530_port_yield,
56 .reclaim = z8530_port_reclaim,
57 .write = z8530_port_write
58};
59
60static kbd_dev_t *kbd_dev;
61
62#define CHAN_A_STATUS 4
63#define CHAN_A_DATA 6
64
65#define RR0_RCA 1
66
67static irq_cmd_t z8530_cmds[] = {
68 {
69 .cmd = CMD_PIO_READ_8,
70 .addr = (void *) 0, /* Will be patched in run-time */
71 .dstarg = 1
72 },
73 {
74 .cmd = CMD_BTEST,
75 .value = RR0_RCA,
76 .srcarg = 1,
77 .dstarg = 3
78 },
79 {
80 .cmd = CMD_PREDICATE,
81 .value = 2,
82 .srcarg = 3
83 },
84 {
85 .cmd = CMD_PIO_READ_8,
86 .addr = (void *) 0, /* Will be patched in run-time */
87 .dstarg = 2
88 },
89 {
90 .cmd = CMD_ACCEPT
91 }
92};
93
94static irq_code_t z8530_kbd = {
95 sizeof(z8530_cmds) / sizeof(irq_cmd_t),
96 z8530_cmds
97};
98
99static void z8530_irq_handler(ipc_callid_t iid, ipc_call_t *call);
100
101static int z8530_port_init(kbd_dev_t *kdev)
102{
103 kbd_dev = kdev;
104
105 sysarg_t z8530;
106 if (sysinfo_get_value("kbd.type.z8530", &z8530) != EOK)
107 return -1;
108 if (!z8530)
109 return -1;
110
111 sysarg_t kaddr;
112 if (sysinfo_get_value("kbd.address.kernel", &kaddr) != EOK)
113 return -1;
114
115 sysarg_t inr;
116 if (sysinfo_get_value("kbd.inr", &inr) != EOK)
117 return -1;
118
119 z8530_cmds[0].addr = (void *) kaddr + CHAN_A_STATUS;
120 z8530_cmds[3].addr = (void *) kaddr + CHAN_A_DATA;
121
122 async_set_interrupt_received(z8530_irq_handler);
123 register_irq(inr, device_assign_devno(), inr, &z8530_kbd);
124
125 return 0;
126}
127
128static void z8530_port_yield(void)
129{
130}
131
132static void z8530_port_reclaim(void)
133{
134}
135
136static void z8530_port_write(uint8_t data)
137{
138 (void) data;
139}
140
141static void z8530_irq_handler(ipc_callid_t iid, ipc_call_t *call)
142{
143 int scan_code = IPC_GET_ARG2(*call);
144 kbd_push_scancode(kbd_dev, scan_code);
145
146 if (irc_service)
147 async_obsolete_msg_1(irc_phone, IRC_CLEAR_INTERRUPT,
148 IPC_GET_IMETHOD(*call));
149}
150
151/** @}
152 */
Note: See TracBrowser for help on using the repository browser.