1 | /*
|
---|
2 | * Copyright (c) 2014 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * @defgroup icp IntegratorCP platform driver.
|
---|
31 | * @brief HelenOS IntegratorCP platform driver.
|
---|
32 | * @{
|
---|
33 | */
|
---|
34 |
|
---|
35 | /** @file
|
---|
36 | */
|
---|
37 |
|
---|
38 | #include <assert.h>
|
---|
39 | #include <stdio.h>
|
---|
40 | #include <errno.h>
|
---|
41 | #include <stdbool.h>
|
---|
42 | #include <stdlib.h>
|
---|
43 |
|
---|
44 | #include <ddf/driver.h>
|
---|
45 | #include <ddf/log.h>
|
---|
46 | #include <ops/hw_res.h>
|
---|
47 | #include <ops/pio_window.h>
|
---|
48 |
|
---|
49 | #define NAME "icp"
|
---|
50 |
|
---|
51 | enum {
|
---|
52 | icp_kbd_base = 0x18000000,
|
---|
53 | icp_kbd_irq = 3,
|
---|
54 | icp_mouse_base = 0x19000000,
|
---|
55 | icp_mouse_irq = 4
|
---|
56 | };
|
---|
57 |
|
---|
58 | typedef struct icp_fun {
|
---|
59 | hw_resource_list_t hw_resources;
|
---|
60 | } icp_fun_t;
|
---|
61 |
|
---|
62 | static int icp_dev_add(ddf_dev_t *dev);
|
---|
63 |
|
---|
64 | static driver_ops_t icp_ops = {
|
---|
65 | .dev_add = &icp_dev_add
|
---|
66 | };
|
---|
67 |
|
---|
68 | static driver_t icp_driver = {
|
---|
69 | .name = NAME,
|
---|
70 | .driver_ops = &icp_ops
|
---|
71 | };
|
---|
72 |
|
---|
73 | static hw_resource_t icp_kbd_res[] = {
|
---|
74 | {
|
---|
75 | .type = MEM_RANGE,
|
---|
76 | .res.mem_range = {
|
---|
77 | .address = icp_kbd_base,
|
---|
78 | .size = 9,
|
---|
79 | .relative = false,
|
---|
80 | .endianness = LITTLE_ENDIAN
|
---|
81 | }
|
---|
82 | },
|
---|
83 | {
|
---|
84 | .type = INTERRUPT,
|
---|
85 | .res.interrupt = {
|
---|
86 | .irq = icp_kbd_irq
|
---|
87 | }
|
---|
88 | }
|
---|
89 | };
|
---|
90 |
|
---|
91 | static hw_resource_t icp_mouse_res[] = {
|
---|
92 | {
|
---|
93 | .type = MEM_RANGE,
|
---|
94 | .res.mem_range = {
|
---|
95 | .address = icp_mouse_base,
|
---|
96 | .size = 9,
|
---|
97 | .relative = false,
|
---|
98 | .endianness = LITTLE_ENDIAN
|
---|
99 | }
|
---|
100 | },
|
---|
101 | {
|
---|
102 | .type = INTERRUPT,
|
---|
103 | .res.interrupt = {
|
---|
104 | .irq = icp_mouse_irq
|
---|
105 | }
|
---|
106 | }
|
---|
107 | };
|
---|
108 |
|
---|
109 | static pio_window_t icp_pio_window = {
|
---|
110 | .mem = {
|
---|
111 | .base = 0,
|
---|
112 | .size = -1
|
---|
113 | }
|
---|
114 | };
|
---|
115 |
|
---|
116 | static icp_fun_t icp_kbd_fun_proto = {
|
---|
117 | .hw_resources = {
|
---|
118 | sizeof(icp_kbd_res) / sizeof(icp_kbd_res[0]),
|
---|
119 | icp_kbd_res
|
---|
120 | },
|
---|
121 | };
|
---|
122 |
|
---|
123 | static icp_fun_t icp_mouse_fun_proto = {
|
---|
124 | .hw_resources = {
|
---|
125 | sizeof(icp_mouse_res) / sizeof(icp_mouse_res[0]),
|
---|
126 | icp_mouse_res
|
---|
127 | },
|
---|
128 | };
|
---|
129 |
|
---|
130 | /** Obtain function soft-state from DDF function node */
|
---|
131 | static icp_fun_t *icp_fun(ddf_fun_t *fnode)
|
---|
132 | {
|
---|
133 | return ddf_fun_data_get(fnode);
|
---|
134 | }
|
---|
135 |
|
---|
136 | static hw_resource_list_t *icp_get_resources(ddf_fun_t *fnode)
|
---|
137 | {
|
---|
138 | icp_fun_t *fun = icp_fun(fnode);
|
---|
139 |
|
---|
140 | assert(fun != NULL);
|
---|
141 | return &fun->hw_resources;
|
---|
142 | }
|
---|
143 |
|
---|
144 | static bool icp_enable_interrupt(ddf_fun_t *fun)
|
---|
145 | {
|
---|
146 | /* TODO */
|
---|
147 | return false;
|
---|
148 | }
|
---|
149 |
|
---|
150 | static pio_window_t *icp_get_pio_window(ddf_fun_t *fnode)
|
---|
151 | {
|
---|
152 | return &icp_pio_window;
|
---|
153 | }
|
---|
154 |
|
---|
155 | static hw_res_ops_t icp_hw_res_ops = {
|
---|
156 | .get_resource_list = &icp_get_resources,
|
---|
157 | .enable_interrupt = &icp_enable_interrupt,
|
---|
158 | };
|
---|
159 |
|
---|
160 | static pio_window_ops_t icp_pio_window_ops = {
|
---|
161 | .get_pio_window = &icp_get_pio_window
|
---|
162 | };
|
---|
163 |
|
---|
164 | static ddf_dev_ops_t icp_fun_ops = {
|
---|
165 | .interfaces = {
|
---|
166 | [HW_RES_DEV_IFACE] = &icp_hw_res_ops,
|
---|
167 | [PIO_WINDOW_DEV_IFACE] = &icp_pio_window_ops
|
---|
168 | }
|
---|
169 | };
|
---|
170 |
|
---|
171 | static int icp_add_fun(ddf_dev_t *dev, const char *name, const char *str_match_id,
|
---|
172 | icp_fun_t *fun_proto)
|
---|
173 | {
|
---|
174 | ddf_msg(LVL_NOTE, "Adding function '%s'.", name);
|
---|
175 |
|
---|
176 | ddf_fun_t *fnode = NULL;
|
---|
177 | int rc;
|
---|
178 |
|
---|
179 | /* Create new device. */
|
---|
180 | fnode = ddf_fun_create(dev, fun_inner, name);
|
---|
181 | if (fnode == NULL) {
|
---|
182 | ddf_msg(LVL_ERROR, "Error creating function '%s'", name);
|
---|
183 | rc = ENOMEM;
|
---|
184 | goto error;
|
---|
185 | }
|
---|
186 |
|
---|
187 | icp_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(icp_fun_t));
|
---|
188 | *fun = *fun_proto;
|
---|
189 |
|
---|
190 | /* Add match ID */
|
---|
191 | rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
|
---|
192 | if (rc != EOK) {
|
---|
193 | ddf_msg(LVL_ERROR, "Error adding match ID");
|
---|
194 | goto error;
|
---|
195 | }
|
---|
196 |
|
---|
197 | /* Set provided operations to the device. */
|
---|
198 | ddf_fun_set_ops(fnode, &icp_fun_ops);
|
---|
199 |
|
---|
200 | /* Register function. */
|
---|
201 | if (ddf_fun_bind(fnode) != EOK) {
|
---|
202 | ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
|
---|
203 | goto error;
|
---|
204 | }
|
---|
205 |
|
---|
206 | return EOK;
|
---|
207 |
|
---|
208 | error:
|
---|
209 | if (fnode != NULL)
|
---|
210 | ddf_fun_destroy(fnode);
|
---|
211 |
|
---|
212 | return rc;
|
---|
213 | }
|
---|
214 |
|
---|
215 | static int icp_add_functions(ddf_dev_t *dev)
|
---|
216 | {
|
---|
217 | int rc;
|
---|
218 |
|
---|
219 | rc = icp_add_fun(dev, "kbd", "arm/pl050", &icp_kbd_fun_proto);
|
---|
220 | if (rc != EOK)
|
---|
221 | return rc;
|
---|
222 |
|
---|
223 | rc = icp_add_fun(dev, "mouse", "arm/pl050", &icp_mouse_fun_proto);
|
---|
224 | if (rc != EOK)
|
---|
225 | return rc;
|
---|
226 |
|
---|
227 | return EOK;
|
---|
228 | }
|
---|
229 |
|
---|
230 | /** Add device. */
|
---|
231 | static int icp_dev_add(ddf_dev_t *dev)
|
---|
232 | {
|
---|
233 | ddf_msg(LVL_NOTE, "icp_dev_add, device handle = %d",
|
---|
234 | (int)ddf_dev_get_handle(dev));
|
---|
235 |
|
---|
236 | /* Register functions. */
|
---|
237 | if (icp_add_functions(dev)) {
|
---|
238 | ddf_msg(LVL_ERROR, "Failed to add functions for ICP platform.");
|
---|
239 | }
|
---|
240 |
|
---|
241 | return EOK;
|
---|
242 | }
|
---|
243 |
|
---|
244 | int main(int argc, char *argv[])
|
---|
245 | {
|
---|
246 | int rc;
|
---|
247 |
|
---|
248 | printf(NAME ": HelenOS IntegratorCP platform driver\n");
|
---|
249 |
|
---|
250 | rc = ddf_log_init(NAME);
|
---|
251 | if (rc != EOK) {
|
---|
252 | printf(NAME ": Failed initializing logging service");
|
---|
253 | return 1;
|
---|
254 | }
|
---|
255 |
|
---|
256 | return ddf_driver_main(&icp_driver);
|
---|
257 | }
|
---|
258 |
|
---|
259 | /**
|
---|
260 | * @}
|
---|
261 | */
|
---|