blob: fc4d33dbb25916876b59069f484bebbac19600e8 [file] [log] [blame]
MD Danish Anwar6712abb2024-04-04 12:38:01 +05301// 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
17int 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
33void 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
41u32 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, &reg);
49
50 return reg;
51}