MD Danish Anwar | 6712abb | 2024-04-04 12:38:01 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* ICSSG Buffer queue helpers |
| 3 | * |
| 4 | * Copyright (C) 2018-2024 Texas Instruments Incorporated - https://www.ti.com |
| 5 | */ |
| 6 | |
| 7 | #include <dm/ofnode.h> |
| 8 | #include <regmap.h> |
| 9 | #include "icssg_prueth.h" |
| 10 | |
| 11 | #define ICSSG_QUEUES_MAX 64 |
| 12 | #define ICSSG_QUEUE_OFFSET 0xd00 |
| 13 | #define ICSSG_QUEUE_PEEK_OFFSET 0xe00 |
| 14 | #define ICSSG_QUEUE_CNT_OFFSET 0xe40 |
| 15 | #define ICSSG_QUEUE_RESET_OFFSET 0xf40 |
| 16 | |
| 17 | int icssg_queue_pop(struct prueth *prueth, u8 queue) |
| 18 | { |
| 19 | u32 val, cnt; |
| 20 | |
| 21 | if (queue >= ICSSG_QUEUES_MAX) |
| 22 | return -EINVAL; |
| 23 | |
| 24 | regmap_read(prueth->miig_rt, ICSSG_QUEUE_CNT_OFFSET + 4 * queue, &cnt); |
| 25 | if (!cnt) |
| 26 | return -EINVAL; |
| 27 | |
| 28 | regmap_read(prueth->miig_rt, ICSSG_QUEUE_OFFSET + 4 * queue, &val); |
| 29 | |
| 30 | return val; |
| 31 | } |
| 32 | |
| 33 | void icssg_queue_push(struct prueth *prueth, int queue, u16 addr) |
| 34 | { |
| 35 | if (queue >= ICSSG_QUEUES_MAX) |
| 36 | return; |
| 37 | |
| 38 | regmap_write(prueth->miig_rt, ICSSG_QUEUE_OFFSET + 4 * queue, addr); |
| 39 | } |
| 40 | |
| 41 | u32 icssg_queue_level(struct prueth *prueth, int queue) |
| 42 | { |
| 43 | u32 reg; |
| 44 | |
| 45 | if (queue >= ICSSG_QUEUES_MAX) |
| 46 | return 0; |
| 47 | |
| 48 | regmap_read(prueth->miig_rt, ICSSG_QUEUE_CNT_OFFSET + 4 * queue, ®); |
| 49 | |
| 50 | return reg; |
| 51 | } |