layerscape: add ls1088ardb device support
[openwrt/staging/lynxis/omap.git] / target / linux / layerscape / patches-4.4 / 7189-staging-fsl-mc-update-dpcon-binary-interface-to-v2.2.patch
1 From 95c8565453e068db2664b5ee9cb0b7eced9a8d24 Mon Sep 17 00:00:00 2001
2 From: Ioana Radulescu <ruxandra.radulescu@freescale.com>
3 Date: Fri, 3 Jul 2015 19:02:45 +0300
4 Subject: [PATCH 189/226] staging: fsl-mc: update dpcon binary interface to
5 v2.2
6
7 -this includes adding the command building/parsing
8 wrapper functions
9
10 Signed-off-by: Stuart Yoder <stuart.yoder@freescale.com>
11 ---
12 drivers/staging/fsl-mc/bus/Makefile | 3 +-
13 drivers/staging/fsl-mc/bus/dpcon.c | 407 ++++++++++++++++++++++++++++
14 drivers/staging/fsl-mc/include/dpcon-cmd.h | 102 ++++++-
15 drivers/staging/fsl-mc/include/dpcon.h | 407 ++++++++++++++++++++++++++++
16 4 files changed, 917 insertions(+), 2 deletions(-)
17 create mode 100644 drivers/staging/fsl-mc/bus/dpcon.c
18 create mode 100644 drivers/staging/fsl-mc/include/dpcon.h
19
20 --- a/drivers/staging/fsl-mc/bus/Makefile
21 +++ b/drivers/staging/fsl-mc/bus/Makefile
22 @@ -16,4 +16,5 @@ mc-bus-driver-objs := mc-bus.o \
23 mc-msi.o \
24 irq-gic-v3-its-fsl-mc-msi.o \
25 dpmcp.o \
26 - dpbp.o
27 + dpbp.o \
28 + dpcon.o
29 --- /dev/null
30 +++ b/drivers/staging/fsl-mc/bus/dpcon.c
31 @@ -0,0 +1,407 @@
32 +/* Copyright 2013-2015 Freescale Semiconductor Inc.
33 + *
34 + * Redistribution and use in source and binary forms, with or without
35 + * modification, are permitted provided that the following conditions are met:
36 + * * Redistributions of source code must retain the above copyright
37 + * notice, this list of conditions and the following disclaimer.
38 + * * Redistributions in binary form must reproduce the above copyright
39 + * notice, this list of conditions and the following disclaimer in the
40 + * documentation and/or other materials provided with the distribution.
41 + * * Neither the name of the above-listed copyright holders nor the
42 + * names of any contributors may be used to endorse or promote products
43 + * derived from this software without specific prior written permission.
44 + *
45 + *
46 + * ALTERNATIVELY, this software may be distributed under the terms of the
47 + * GNU General Public License ("GPL") as published by the Free Software
48 + * Foundation, either version 2 of that License or (at your option) any
49 + * later version.
50 + *
51 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
52 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
55 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
56 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
57 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
58 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
59 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
60 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
61 + * POSSIBILITY OF SUCH DAMAGE.
62 + */
63 +#include "../include/mc-sys.h"
64 +#include "../include/mc-cmd.h"
65 +#include "../include/dpcon.h"
66 +#include "../include/dpcon-cmd.h"
67 +
68 +int dpcon_open(struct fsl_mc_io *mc_io,
69 + uint32_t cmd_flags,
70 + int dpcon_id,
71 + uint16_t *token)
72 +{
73 + struct mc_command cmd = { 0 };
74 + int err;
75 +
76 + /* prepare command */
77 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,
78 + cmd_flags,
79 + 0);
80 + DPCON_CMD_OPEN(cmd, dpcon_id);
81 +
82 + /* send command to mc*/
83 + err = mc_send_command(mc_io, &cmd);
84 + if (err)
85 + return err;
86 +
87 + /* retrieve response parameters */
88 + *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
89 +
90 + return 0;
91 +}
92 +EXPORT_SYMBOL(dpcon_open);
93 +
94 +int dpcon_close(struct fsl_mc_io *mc_io,
95 + uint32_t cmd_flags,
96 + uint16_t token)
97 +{
98 + struct mc_command cmd = { 0 };
99 +
100 + /* prepare command */
101 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,
102 + cmd_flags,
103 + token);
104 +
105 + /* send command to mc*/
106 + return mc_send_command(mc_io, &cmd);
107 +}
108 +EXPORT_SYMBOL(dpcon_close);
109 +
110 +int dpcon_create(struct fsl_mc_io *mc_io,
111 + uint32_t cmd_flags,
112 + const struct dpcon_cfg *cfg,
113 + uint16_t *token)
114 +{
115 + struct mc_command cmd = { 0 };
116 + int err;
117 +
118 + /* prepare command */
119 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_CREATE,
120 + cmd_flags,
121 + 0);
122 + DPCON_CMD_CREATE(cmd, cfg);
123 +
124 + /* send command to mc*/
125 + err = mc_send_command(mc_io, &cmd);
126 + if (err)
127 + return err;
128 +
129 + /* retrieve response parameters */
130 + *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
131 +
132 + return 0;
133 +}
134 +
135 +int dpcon_destroy(struct fsl_mc_io *mc_io,
136 + uint32_t cmd_flags,
137 + uint16_t token)
138 +{
139 + struct mc_command cmd = { 0 };
140 +
141 + /* prepare command */
142 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_DESTROY,
143 + cmd_flags,
144 + token);
145 +
146 + /* send command to mc*/
147 + return mc_send_command(mc_io, &cmd);
148 +}
149 +
150 +int dpcon_enable(struct fsl_mc_io *mc_io,
151 + uint32_t cmd_flags,
152 + uint16_t token)
153 +{
154 + struct mc_command cmd = { 0 };
155 +
156 + /* prepare command */
157 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,
158 + cmd_flags,
159 + token);
160 +
161 + /* send command to mc*/
162 + return mc_send_command(mc_io, &cmd);
163 +}
164 +EXPORT_SYMBOL(dpcon_enable);
165 +
166 +int dpcon_disable(struct fsl_mc_io *mc_io,
167 + uint32_t cmd_flags,
168 + uint16_t token)
169 +{
170 + struct mc_command cmd = { 0 };
171 +
172 + /* prepare command */
173 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,
174 + cmd_flags,
175 + token);
176 +
177 + /* send command to mc*/
178 + return mc_send_command(mc_io, &cmd);
179 +}
180 +EXPORT_SYMBOL(dpcon_disable);
181 +
182 +int dpcon_is_enabled(struct fsl_mc_io *mc_io,
183 + uint32_t cmd_flags,
184 + uint16_t token,
185 + int *en)
186 +{
187 + struct mc_command cmd = { 0 };
188 + int err;
189 + /* prepare command */
190 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_IS_ENABLED,
191 + cmd_flags,
192 + token);
193 +
194 + /* send command to mc*/
195 + err = mc_send_command(mc_io, &cmd);
196 + if (err)
197 + return err;
198 +
199 + /* retrieve response parameters */
200 + DPCON_RSP_IS_ENABLED(cmd, *en);
201 +
202 + return 0;
203 +}
204 +
205 +int dpcon_reset(struct fsl_mc_io *mc_io,
206 + uint32_t cmd_flags,
207 + uint16_t token)
208 +{
209 + struct mc_command cmd = { 0 };
210 +
211 + /* prepare command */
212 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,
213 + cmd_flags, token);
214 +
215 + /* send command to mc*/
216 + return mc_send_command(mc_io, &cmd);
217 +}
218 +
219 +int dpcon_set_irq(struct fsl_mc_io *mc_io,
220 + uint32_t cmd_flags,
221 + uint16_t token,
222 + uint8_t irq_index,
223 + struct dpcon_irq_cfg *irq_cfg)
224 +{
225 + struct mc_command cmd = { 0 };
226 +
227 + /* prepare command */
228 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_SET_IRQ,
229 + cmd_flags,
230 + token);
231 + DPCON_CMD_SET_IRQ(cmd, irq_index, irq_cfg);
232 +
233 + /* send command to mc*/
234 + return mc_send_command(mc_io, &cmd);
235 +}
236 +
237 +int dpcon_get_irq(struct fsl_mc_io *mc_io,
238 + uint32_t cmd_flags,
239 + uint16_t token,
240 + uint8_t irq_index,
241 + int *type,
242 + struct dpcon_irq_cfg *irq_cfg)
243 +{
244 + struct mc_command cmd = { 0 };
245 + int err;
246 +
247 + /* prepare command */
248 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_IRQ,
249 + cmd_flags,
250 + token);
251 + DPCON_CMD_GET_IRQ(cmd, irq_index);
252 +
253 + /* send command to mc*/
254 + err = mc_send_command(mc_io, &cmd);
255 + if (err)
256 + return err;
257 +
258 + /* retrieve response parameters */
259 + DPCON_RSP_GET_IRQ(cmd, *type, irq_cfg);
260 +
261 + return 0;
262 +}
263 +
264 +int dpcon_set_irq_enable(struct fsl_mc_io *mc_io,
265 + uint32_t cmd_flags,
266 + uint16_t token,
267 + uint8_t irq_index,
268 + uint8_t en)
269 +{
270 + struct mc_command cmd = { 0 };
271 +
272 + /* prepare command */
273 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_SET_IRQ_ENABLE,
274 + cmd_flags,
275 + token);
276 + DPCON_CMD_SET_IRQ_ENABLE(cmd, irq_index, en);
277 +
278 + /* send command to mc*/
279 + return mc_send_command(mc_io, &cmd);
280 +}
281 +
282 +int dpcon_get_irq_enable(struct fsl_mc_io *mc_io,
283 + uint32_t cmd_flags,
284 + uint16_t token,
285 + uint8_t irq_index,
286 + uint8_t *en)
287 +{
288 + struct mc_command cmd = { 0 };
289 + int err;
290 +
291 + /* prepare command */
292 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_IRQ_ENABLE,
293 + cmd_flags,
294 + token);
295 + DPCON_CMD_GET_IRQ_ENABLE(cmd, irq_index);
296 +
297 + /* send command to mc*/
298 + err = mc_send_command(mc_io, &cmd);
299 + if (err)
300 + return err;
301 +
302 + /* retrieve response parameters */
303 + DPCON_RSP_GET_IRQ_ENABLE(cmd, *en);
304 +
305 + return 0;
306 +}
307 +
308 +int dpcon_set_irq_mask(struct fsl_mc_io *mc_io,
309 + uint32_t cmd_flags,
310 + uint16_t token,
311 + uint8_t irq_index,
312 + uint32_t mask)
313 +{
314 + struct mc_command cmd = { 0 };
315 +
316 + /* prepare command */
317 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_SET_IRQ_MASK,
318 + cmd_flags,
319 + token);
320 + DPCON_CMD_SET_IRQ_MASK(cmd, irq_index, mask);
321 +
322 + /* send command to mc*/
323 + return mc_send_command(mc_io, &cmd);
324 +}
325 +
326 +int dpcon_get_irq_mask(struct fsl_mc_io *mc_io,
327 + uint32_t cmd_flags,
328 + uint16_t token,
329 + uint8_t irq_index,
330 + uint32_t *mask)
331 +{
332 + struct mc_command cmd = { 0 };
333 + int err;
334 +
335 + /* prepare command */
336 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_IRQ_MASK,
337 + cmd_flags,
338 + token);
339 + DPCON_CMD_GET_IRQ_MASK(cmd, irq_index);
340 +
341 + /* send command to mc*/
342 + err = mc_send_command(mc_io, &cmd);
343 + if (err)
344 + return err;
345 +
346 + /* retrieve response parameters */
347 + DPCON_RSP_GET_IRQ_MASK(cmd, *mask);
348 +
349 + return 0;
350 +}
351 +
352 +int dpcon_get_irq_status(struct fsl_mc_io *mc_io,
353 + uint32_t cmd_flags,
354 + uint16_t token,
355 + uint8_t irq_index,
356 + uint32_t *status)
357 +{
358 + struct mc_command cmd = { 0 };
359 + int err;
360 +
361 + /* prepare command */
362 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_IRQ_STATUS,
363 + cmd_flags,
364 + token);
365 + DPCON_CMD_GET_IRQ_STATUS(cmd, irq_index, *status);
366 +
367 + /* send command to mc*/
368 + err = mc_send_command(mc_io, &cmd);
369 + if (err)
370 + return err;
371 +
372 + /* retrieve response parameters */
373 + DPCON_RSP_GET_IRQ_STATUS(cmd, *status);
374 +
375 + return 0;
376 +}
377 +
378 +int dpcon_clear_irq_status(struct fsl_mc_io *mc_io,
379 + uint32_t cmd_flags,
380 + uint16_t token,
381 + uint8_t irq_index,
382 + uint32_t status)
383 +{
384 + struct mc_command cmd = { 0 };
385 +
386 + /* prepare command */
387 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLEAR_IRQ_STATUS,
388 + cmd_flags,
389 + token);
390 + DPCON_CMD_CLEAR_IRQ_STATUS(cmd, irq_index, status);
391 +
392 + /* send command to mc*/
393 + return mc_send_command(mc_io, &cmd);
394 +}
395 +
396 +int dpcon_get_attributes(struct fsl_mc_io *mc_io,
397 + uint32_t cmd_flags,
398 + uint16_t token,
399 + struct dpcon_attr *attr)
400 +{
401 + struct mc_command cmd = { 0 };
402 + int err;
403 +
404 + /* prepare command */
405 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,
406 + cmd_flags,
407 + token);
408 +
409 + /* send command to mc*/
410 + err = mc_send_command(mc_io, &cmd);
411 + if (err)
412 + return err;
413 +
414 + /* retrieve response parameters */
415 + DPCON_RSP_GET_ATTR(cmd, attr);
416 +
417 + return 0;
418 +}
419 +EXPORT_SYMBOL(dpcon_get_attributes);
420 +
421 +int dpcon_set_notification(struct fsl_mc_io *mc_io,
422 + uint32_t cmd_flags,
423 + uint16_t token,
424 + struct dpcon_notification_cfg *cfg)
425 +{
426 + struct mc_command cmd = { 0 };
427 +
428 + /* prepare command */
429 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_SET_NOTIFICATION,
430 + cmd_flags,
431 + token);
432 + DPCON_CMD_SET_NOTIFICATION(cmd, cfg);
433 +
434 + /* send command to mc*/
435 + return mc_send_command(mc_io, &cmd);
436 +}
437 +EXPORT_SYMBOL(dpcon_set_notification);
438 +
439 --- a/drivers/staging/fsl-mc/include/dpcon-cmd.h
440 +++ b/drivers/staging/fsl-mc/include/dpcon-cmd.h
441 @@ -34,7 +34,7 @@
442
443 /* DPCON Version */
444 #define DPCON_VER_MAJOR 2
445 -#define DPCON_VER_MINOR 1
446 +#define DPCON_VER_MINOR 2
447
448 /* Command IDs */
449 #define DPCON_CMDID_CLOSE 0x800
450 @@ -59,4 +59,104 @@
451
452 #define DPCON_CMDID_SET_NOTIFICATION 0x100
453
454 +/* cmd, param, offset, width, type, arg_name */
455 +#define DPCON_CMD_OPEN(cmd, dpcon_id) \
456 + MC_CMD_OP(cmd, 0, 0, 32, int, dpcon_id)
457 +
458 +/* cmd, param, offset, width, type, arg_name */
459 +#define DPCON_CMD_CREATE(cmd, cfg) \
460 + MC_CMD_OP(cmd, 0, 0, 8, uint8_t, cfg->num_priorities)
461 +
462 +/* cmd, param, offset, width, type, arg_name */
463 +#define DPCON_RSP_IS_ENABLED(cmd, en) \
464 + MC_RSP_OP(cmd, 0, 0, 1, int, en)
465 +
466 +/* cmd, param, offset, width, type, arg_name */
467 +#define DPCON_CMD_SET_IRQ(cmd, irq_index, irq_cfg) \
468 +do { \
469 + MC_CMD_OP(cmd, 0, 0, 8, uint8_t, irq_index);\
470 + MC_CMD_OP(cmd, 0, 32, 32, uint32_t, irq_cfg->val);\
471 + MC_CMD_OP(cmd, 1, 0, 64, uint64_t, irq_cfg->addr);\
472 + MC_CMD_OP(cmd, 2, 0, 32, int, irq_cfg->irq_num); \
473 +} while (0)
474 +
475 +/* cmd, param, offset, width, type, arg_name */
476 +#define DPCON_CMD_GET_IRQ(cmd, irq_index) \
477 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index)
478 +
479 +/* cmd, param, offset, width, type, arg_name */
480 +#define DPCON_RSP_GET_IRQ(cmd, type, irq_cfg) \
481 +do { \
482 + MC_RSP_OP(cmd, 0, 0, 32, uint32_t, irq_cfg->val);\
483 + MC_RSP_OP(cmd, 1, 0, 64, uint64_t, irq_cfg->addr);\
484 + MC_RSP_OP(cmd, 2, 0, 32, int, irq_cfg->irq_num); \
485 + MC_RSP_OP(cmd, 2, 32, 32, int, type);\
486 +} while (0)
487 +
488 +/* cmd, param, offset, width, type, arg_name */
489 +#define DPCON_CMD_SET_IRQ_ENABLE(cmd, irq_index, en) \
490 +do { \
491 + MC_CMD_OP(cmd, 0, 0, 8, uint8_t, en); \
492 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index);\
493 +} while (0)
494 +
495 +/* cmd, param, offset, width, type, arg_name */
496 +#define DPCON_CMD_GET_IRQ_ENABLE(cmd, irq_index) \
497 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index)
498 +
499 +/* cmd, param, offset, width, type, arg_name */
500 +#define DPCON_RSP_GET_IRQ_ENABLE(cmd, en) \
501 + MC_RSP_OP(cmd, 0, 0, 8, uint8_t, en)
502 +
503 +/* cmd, param, offset, width, type, arg_name */
504 +#define DPCON_CMD_SET_IRQ_MASK(cmd, irq_index, mask) \
505 +do { \
506 + MC_CMD_OP(cmd, 0, 0, 32, uint32_t, mask); \
507 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index);\
508 +} while (0)
509 +
510 +/* cmd, param, offset, width, type, arg_name */
511 +#define DPCON_CMD_GET_IRQ_MASK(cmd, irq_index) \
512 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index)
513 +
514 +/* cmd, param, offset, width, type, arg_name */
515 +#define DPCON_RSP_GET_IRQ_MASK(cmd, mask) \
516 + MC_RSP_OP(cmd, 0, 0, 32, uint32_t, mask)
517 +
518 +/* cmd, param, offset, width, type, arg_name */
519 +#define DPCON_CMD_GET_IRQ_STATUS(cmd, irq_index, status) \
520 +do { \
521 + MC_CMD_OP(cmd, 0, 0, 32, uint32_t, status);\
522 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index);\
523 +} while (0)
524 +
525 +/* cmd, param, offset, width, type, arg_name */
526 +#define DPCON_RSP_GET_IRQ_STATUS(cmd, status) \
527 + MC_RSP_OP(cmd, 0, 0, 32, uint32_t, status)
528 +
529 +/* cmd, param, offset, width, type, arg_name */
530 +#define DPCON_CMD_CLEAR_IRQ_STATUS(cmd, irq_index, status) \
531 +do { \
532 + MC_CMD_OP(cmd, 0, 0, 32, uint32_t, status); \
533 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index);\
534 +} while (0)
535 +
536 +/* cmd, param, offset, width, type, arg_name */
537 +#define DPCON_RSP_GET_ATTR(cmd, attr) \
538 +do { \
539 + MC_RSP_OP(cmd, 0, 0, 32, int, attr->id);\
540 + MC_RSP_OP(cmd, 0, 32, 16, uint16_t, attr->qbman_ch_id);\
541 + MC_RSP_OP(cmd, 0, 48, 8, uint8_t, attr->num_priorities);\
542 + MC_RSP_OP(cmd, 1, 0, 16, uint16_t, attr->version.major);\
543 + MC_RSP_OP(cmd, 1, 16, 16, uint16_t, attr->version.minor);\
544 +} while (0)
545 +
546 +/* cmd, param, offset, width, type, arg_name */
547 +#define DPCON_CMD_SET_NOTIFICATION(cmd, cfg) \
548 +do { \
549 + MC_CMD_OP(cmd, 0, 0, 32, int, cfg->dpio_id);\
550 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, cfg->priority);\
551 + MC_CMD_OP(cmd, 1, 0, 64, uint64_t, cfg->user_ctx);\
552 +} while (0)
553 +
554 #endif /* _FSL_DPCON_CMD_H */
555 --- /dev/null
556 +++ b/drivers/staging/fsl-mc/include/dpcon.h
557 @@ -0,0 +1,407 @@
558 +/* Copyright 2013-2015 Freescale Semiconductor Inc.
559 + *
560 + * Redistribution and use in source and binary forms, with or without
561 + * modification, are permitted provided that the following conditions are met:
562 + * * Redistributions of source code must retain the above copyright
563 + * notice, this list of conditions and the following disclaimer.
564 + * * Redistributions in binary form must reproduce the above copyright
565 + * notice, this list of conditions and the following disclaimer in the
566 + * documentation and/or other materials provided with the distribution.
567 + * * Neither the name of the above-listed copyright holders nor the
568 + * names of any contributors may be used to endorse or promote products
569 + * derived from this software without specific prior written permission.
570 + *
571 + *
572 + * ALTERNATIVELY, this software may be distributed under the terms of the
573 + * GNU General Public License ("GPL") as published by the Free Software
574 + * Foundation, either version 2 of that License or (at your option) any
575 + * later version.
576 + *
577 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
578 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
579 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
580 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
581 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
582 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
583 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
584 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
585 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
586 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
587 + * POSSIBILITY OF SUCH DAMAGE.
588 + */
589 +#ifndef __FSL_DPCON_H
590 +#define __FSL_DPCON_H
591 +
592 +/* Data Path Concentrator API
593 + * Contains initialization APIs and runtime control APIs for DPCON
594 + */
595 +
596 +struct fsl_mc_io;
597 +
598 +/** General DPCON macros */
599 +
600 +/**
601 + * Use it to disable notifications; see dpcon_set_notification()
602 + */
603 +#define DPCON_INVALID_DPIO_ID (int)(-1)
604 +
605 +/**
606 + * dpcon_open() - Open a control session for the specified object
607 + * @mc_io: Pointer to MC portal's I/O object
608 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
609 + * @dpcon_id: DPCON unique ID
610 + * @token: Returned token; use in subsequent API calls
611 + *
612 + * This function can be used to open a control session for an
613 + * already created object; an object may have been declared in
614 + * the DPL or by calling the dpcon_create() function.
615 + * This function returns a unique authentication token,
616 + * associated with the specific object ID and the specific MC
617 + * portal; this token must be used in all subsequent commands for
618 + * this specific object.
619 + *
620 + * Return: '0' on Success; Error code otherwise.
621 + */
622 +int dpcon_open(struct fsl_mc_io *mc_io,
623 + uint32_t cmd_flags,
624 + int dpcon_id,
625 + uint16_t *token);
626 +
627 +/**
628 + * dpcon_close() - Close the control session of the object
629 + * @mc_io: Pointer to MC portal's I/O object
630 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
631 + * @token: Token of DPCON object
632 + *
633 + * After this function is called, no further operations are
634 + * allowed on the object without opening a new control session.
635 + *
636 + * Return: '0' on Success; Error code otherwise.
637 + */
638 +int dpcon_close(struct fsl_mc_io *mc_io,
639 + uint32_t cmd_flags,
640 + uint16_t token);
641 +
642 +/**
643 + * struct dpcon_cfg - Structure representing DPCON configuration
644 + * @num_priorities: Number of priorities for the DPCON channel (1-8)
645 + */
646 +struct dpcon_cfg {
647 + uint8_t num_priorities;
648 +};
649 +
650 +/**
651 + * dpcon_create() - Create the DPCON object.
652 + * @mc_io: Pointer to MC portal's I/O object
653 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
654 + * @cfg: Configuration structure
655 + * @token: Returned token; use in subsequent API calls
656 + *
657 + * Create the DPCON object, allocate required resources and
658 + * perform required initialization.
659 + *
660 + * The object can be created either by declaring it in the
661 + * DPL file, or by calling this function.
662 + *
663 + * This function returns a unique authentication token,
664 + * associated with the specific object ID and the specific MC
665 + * portal; this token must be used in all subsequent calls to
666 + * this specific object. For objects that are created using the
667 + * DPL file, call dpcon_open() function to get an authentication
668 + * token first.
669 + *
670 + * Return: '0' on Success; Error code otherwise.
671 + */
672 +int dpcon_create(struct fsl_mc_io *mc_io,
673 + uint32_t cmd_flags,
674 + const struct dpcon_cfg *cfg,
675 + uint16_t *token);
676 +
677 +/**
678 + * dpcon_destroy() - Destroy the DPCON object and release all its resources.
679 + * @mc_io: Pointer to MC portal's I/O object
680 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
681 + * @token: Token of DPCON object
682 + *
683 + * Return: '0' on Success; error code otherwise.
684 + */
685 +int dpcon_destroy(struct fsl_mc_io *mc_io,
686 + uint32_t cmd_flags,
687 + uint16_t token);
688 +
689 +/**
690 + * dpcon_enable() - Enable the DPCON
691 + * @mc_io: Pointer to MC portal's I/O object
692 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
693 + * @token: Token of DPCON object
694 + *
695 + * Return: '0' on Success; Error code otherwise
696 + */
697 +int dpcon_enable(struct fsl_mc_io *mc_io,
698 + uint32_t cmd_flags,
699 + uint16_t token);
700 +
701 +/**
702 + * dpcon_disable() - Disable the DPCON
703 + * @mc_io: Pointer to MC portal's I/O object
704 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
705 + * @token: Token of DPCON object
706 + *
707 + * Return: '0' on Success; Error code otherwise
708 + */
709 +int dpcon_disable(struct fsl_mc_io *mc_io,
710 + uint32_t cmd_flags,
711 + uint16_t token);
712 +
713 +/**
714 + * dpcon_is_enabled() - Check if the DPCON is enabled.
715 + * @mc_io: Pointer to MC portal's I/O object
716 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
717 + * @token: Token of DPCON object
718 + * @en: Returns '1' if object is enabled; '0' otherwise
719 + *
720 + * Return: '0' on Success; Error code otherwise.
721 + */
722 +int dpcon_is_enabled(struct fsl_mc_io *mc_io,
723 + uint32_t cmd_flags,
724 + uint16_t token,
725 + int *en);
726 +
727 +/**
728 + * dpcon_reset() - Reset the DPCON, returns the object to initial state.
729 + * @mc_io: Pointer to MC portal's I/O object
730 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
731 + * @token: Token of DPCON object
732 + *
733 + * Return: '0' on Success; Error code otherwise.
734 + */
735 +int dpcon_reset(struct fsl_mc_io *mc_io,
736 + uint32_t cmd_flags,
737 + uint16_t token);
738 +
739 +/**
740 + * struct dpcon_irq_cfg - IRQ configuration
741 + * @addr: Address that must be written to signal a message-based interrupt
742 + * @val: Value to write into irq_addr address
743 + * @irq_num: A user defined number associated with this IRQ
744 + */
745 +struct dpcon_irq_cfg {
746 + uint64_t addr;
747 + uint32_t val;
748 + int irq_num;
749 +};
750 +
751 +/**
752 + * dpcon_set_irq() - Set IRQ information for the DPCON to trigger an interrupt.
753 + * @mc_io: Pointer to MC portal's I/O object
754 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
755 + * @token: Token of DPCON object
756 + * @irq_index: Identifies the interrupt index to configure
757 + * @irq_cfg: IRQ configuration
758 + * Return: '0' on Success; Error code otherwise.
759 + */
760 +int dpcon_set_irq(struct fsl_mc_io *mc_io,
761 + uint32_t cmd_flags,
762 + uint16_t token,
763 + uint8_t irq_index,
764 + struct dpcon_irq_cfg *irq_cfg);
765 +
766 +/**
767 + * dpcon_get_irq() - Get IRQ information from the DPCON.
768 + *
769 + * @mc_io: Pointer to MC portal's I/O object
770 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
771 + * @token: Token of DPCON object
772 + * @irq_index: The interrupt index to configure
773 + * @type: Interrupt type: 0 represents message interrupt
774 + * type (both irq_addr and irq_val are valid)
775 + * @irq_cfg: IRQ attributes
776 + *
777 + * Return: '0' on Success; Error code otherwise.
778 + */
779 +int dpcon_get_irq(struct fsl_mc_io *mc_io,
780 + uint32_t cmd_flags,
781 + uint16_t token,
782 + uint8_t irq_index,
783 + int *type,
784 + struct dpcon_irq_cfg *irq_cfg);
785 +
786 +/**
787 + * dpcon_set_irq_enable() - Set overall interrupt state.
788 + * @mc_io: Pointer to MC portal's I/O object
789 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
790 + * @token: Token of DPCON object
791 + * @irq_index: The interrupt index to configure
792 + * @en: Interrupt state - enable = 1, disable = 0
793 + *
794 + * Allows GPP software to control when interrupts are generated.
795 + * Each interrupt can have up to 32 causes. The enable/disable control's the
796 + * overall interrupt state. if the interrupt is disabled no causes will cause
797 + * an interrupt.
798 + *
799 + * Return: '0' on Success; Error code otherwise.
800 + */
801 +int dpcon_set_irq_enable(struct fsl_mc_io *mc_io,
802 + uint32_t cmd_flags,
803 + uint16_t token,
804 + uint8_t irq_index,
805 + uint8_t en);
806 +
807 +/**
808 + * dpcon_get_irq_enable() - Get overall interrupt state.
809 + * @mc_io: Pointer to MC portal's I/O object
810 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
811 + * @token: Token of DPCON object
812 + * @irq_index: The interrupt index to configure
813 + * @en: Returned interrupt state - enable = 1, disable = 0
814 + *
815 + * Return: '0' on Success; Error code otherwise.
816 + */
817 +int dpcon_get_irq_enable(struct fsl_mc_io *mc_io,
818 + uint32_t cmd_flags,
819 + uint16_t token,
820 + uint8_t irq_index,
821 + uint8_t *en);
822 +
823 +/**
824 + * dpcon_set_irq_mask() - Set interrupt mask.
825 + * @mc_io: Pointer to MC portal's I/O object
826 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
827 + * @token: Token of DPCON object
828 + * @irq_index: The interrupt index to configure
829 + * @mask: Event mask to trigger interrupt;
830 + * each bit:
831 + * 0 = ignore event
832 + * 1 = consider event for asserting IRQ
833 + *
834 + * Every interrupt can have up to 32 causes and the interrupt model supports
835 + * masking/unmasking each cause independently
836 + *
837 + * Return: '0' on Success; Error code otherwise.
838 + */
839 +int dpcon_set_irq_mask(struct fsl_mc_io *mc_io,
840 + uint32_t cmd_flags,
841 + uint16_t token,
842 + uint8_t irq_index,
843 + uint32_t mask);
844 +
845 +/**
846 + * dpcon_get_irq_mask() - Get interrupt mask.
847 + * @mc_io: Pointer to MC portal's I/O object
848 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
849 + * @token: Token of DPCON object
850 + * @irq_index: The interrupt index to configure
851 + * @mask: Returned event mask to trigger interrupt
852 + *
853 + * Every interrupt can have up to 32 causes and the interrupt model supports
854 + * masking/unmasking each cause independently
855 + *
856 + * Return: '0' on Success; Error code otherwise.
857 + */
858 +int dpcon_get_irq_mask(struct fsl_mc_io *mc_io,
859 + uint32_t cmd_flags,
860 + uint16_t token,
861 + uint8_t irq_index,
862 + uint32_t *mask);
863 +
864 +/**
865 + * dpcon_get_irq_status() - Get the current status of any pending interrupts.
866 + * @mc_io: Pointer to MC portal's I/O object
867 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
868 + * @token: Token of DPCON object
869 + * @irq_index: The interrupt index to configure
870 + * @status: interrupts status - one bit per cause:
871 + * 0 = no interrupt pending
872 + * 1 = interrupt pending
873 + *
874 + * Return: '0' on Success; Error code otherwise.
875 + */
876 +int dpcon_get_irq_status(struct fsl_mc_io *mc_io,
877 + uint32_t cmd_flags,
878 + uint16_t token,
879 + uint8_t irq_index,
880 + uint32_t *status);
881 +
882 +/**
883 + * dpcon_clear_irq_status() - Clear a pending interrupt's status
884 + * @mc_io: Pointer to MC portal's I/O object
885 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
886 + * @token: Token of DPCON object
887 + * @irq_index: The interrupt index to configure
888 + * @status: bits to clear (W1C) - one bit per cause:
889 + * 0 = don't change
890 + * 1 = clear status bit
891 + *
892 + * Return: '0' on Success; Error code otherwise.
893 + */
894 +int dpcon_clear_irq_status(struct fsl_mc_io *mc_io,
895 + uint32_t cmd_flags,
896 + uint16_t token,
897 + uint8_t irq_index,
898 + uint32_t status);
899 +
900 +/**
901 + * struct dpcon_attr - Structure representing DPCON attributes
902 + * @id: DPCON object ID
903 + * @version: DPCON version
904 + * @qbman_ch_id: Channel ID to be used by dequeue operation
905 + * @num_priorities: Number of priorities for the DPCON channel (1-8)
906 + */
907 +struct dpcon_attr {
908 + int id;
909 + /**
910 + * struct version - DPCON version
911 + * @major: DPCON major version
912 + * @minor: DPCON minor version
913 + */
914 + struct {
915 + uint16_t major;
916 + uint16_t minor;
917 + } version;
918 + uint16_t qbman_ch_id;
919 + uint8_t num_priorities;
920 +};
921 +
922 +/**
923 + * dpcon_get_attributes() - Retrieve DPCON attributes.
924 + * @mc_io: Pointer to MC portal's I/O object
925 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
926 + * @token: Token of DPCON object
927 + * @attr: Object's attributes
928 + *
929 + * Return: '0' on Success; Error code otherwise.
930 + */
931 +int dpcon_get_attributes(struct fsl_mc_io *mc_io,
932 + uint32_t cmd_flags,
933 + uint16_t token,
934 + struct dpcon_attr *attr);
935 +
936 +/**
937 + * struct dpcon_notification_cfg - Structure representing notification parameters
938 + * @dpio_id: DPIO object ID; must be configured with a notification channel;
939 + * to disable notifications set it to 'DPCON_INVALID_DPIO_ID';
940 + * @priority: Priority selection within the DPIO channel; valid values
941 + * are 0-7, depending on the number of priorities in that channel
942 + * @user_ctx: User context value provided with each CDAN message
943 + */
944 +struct dpcon_notification_cfg {
945 + int dpio_id;
946 + uint8_t priority;
947 + uint64_t user_ctx;
948 +};
949 +
950 +/**
951 + * dpcon_set_notification() - Set DPCON notification destination
952 + * @mc_io: Pointer to MC portal's I/O object
953 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
954 + * @token: Token of DPCON object
955 + * @cfg: Notification parameters
956 + *
957 + * Return: '0' on Success; Error code otherwise
958 + */
959 +int dpcon_set_notification(struct fsl_mc_io *mc_io,
960 + uint32_t cmd_flags,
961 + uint16_t token,
962 + struct dpcon_notification_cfg *cfg);
963 +
964 +#endif /* __FSL_DPCON_H */