source: mainline/uspace/srv/hid/input/port/pl050.c@ 2e39656

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 2e39656 was 21063c2, checked in by Jakub Jermar <jakub@…>, 14 years ago

Define a PIO range for PL050 keyboard and adjust its IRQ code accordingly.

  • Property mode set to 100644
File size: 3.6 KB
Line 
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
49static int pl050_port_init(kbd_dev_t *);
50static void pl050_port_yield(void);
51static void pl050_port_reclaim(void);
52static void pl050_port_write(uint8_t data);
53
54kbd_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
61static kbd_dev_t *kbd_dev;
62
63#define PL050_STAT 4
64#define PL050_DATA 8
65
66#define PL050_STAT_RXFULL (1 << 4)
67
68static irq_pio_range_t pl050_ranges[] = {
69 {
70 .base = 0,
71 .size = 9,
72 }
73};
74
75static irq_cmd_t pl050_cmds[] = {
76 {
77 .cmd = CMD_PIO_READ_8,
78 .addr = NULL,
79 .dstarg = 1
80 },
81 {
82 .cmd = CMD_BTEST,
83 .value = PL050_STAT_RXFULL,
84 .srcarg = 1,
85 .dstarg = 3
86 },
87 {
88 .cmd = CMD_PREDICATE,
89 .value = 2,
90 .srcarg = 3
91 },
92 {
93 .cmd = CMD_PIO_READ_8,
94 .addr = NULL, /* Will be patched in run-time */
95 .dstarg = 2
96 },
97 {
98 .cmd = CMD_ACCEPT
99 }
100};
101
102static irq_code_t pl050_kbd = {
103 sizeof(pl050_ranges) / sizeof(irq_pio_range_t),
104 pl050_ranges,
105 sizeof(pl050_cmds) / sizeof(irq_cmd_t),
106 pl050_cmds
107};
108
109static void pl050_irq_handler(ipc_callid_t iid, ipc_call_t *call);
110
111static int pl050_port_init(kbd_dev_t *kdev)
112{
113 kbd_dev = kdev;
114
115 sysarg_t addr;
116 if (sysinfo_get_value("kbd.address.physical", &addr) != EOK)
117 return -1;
118
119 pl050_kbd.ranges[0].base = addr;
120 pl050_kbd.cmds[0].addr = (void *) addr + PL050_STAT;
121 pl050_kbd.cmds[3].addr = (void *) addr + PL050_DATA;
122
123 sysarg_t inr;
124 if (sysinfo_get_value("kbd.inr", &inr) != EOK)
125 return -1;
126
127 async_set_interrupt_received(pl050_irq_handler);
128 irq_register(inr, device_assign_devno(), 0, &pl050_kbd);
129
130 return 0;
131}
132
133static void pl050_port_yield(void)
134{
135}
136
137static void pl050_port_reclaim(void)
138{
139}
140
141static void pl050_port_write(uint8_t data)
142{
143 (void) data;
144}
145
146static void pl050_irq_handler(ipc_callid_t iid, ipc_call_t *call)
147{
148 kbd_push_data(kbd_dev, IPC_GET_ARG2(*call));
149}
150
151/**
152 * @}
153 */
Note: See TracBrowser for help on using the repository browser.