1 // SPDX-License-Identifier: GPL-2.0
2 /* ICSSG Buffer queue helpers
3 *
4 * Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com
5 */
6
7 #include <linux/regmap.h>
8 #include "icssg_prueth.h"
9
10 #define ICSSG_QUEUES_MAX 64
11 #define ICSSG_QUEUE_OFFSET 0xd00
12 #define ICSSG_QUEUE_PEEK_OFFSET 0xe00
13 #define ICSSG_QUEUE_CNT_OFFSET 0xe40
14 #define ICSSG_QUEUE_RESET_OFFSET 0xf40
15
icssg_queue_pop(struct prueth * prueth,u8 queue)16 int icssg_queue_pop(struct prueth *prueth, u8 queue)
17 {
18 u32 val, cnt;
19
20 if (queue >= ICSSG_QUEUES_MAX)
21 return -EINVAL;
22
23 regmap_read(prueth->miig_rt, ICSSG_QUEUE_CNT_OFFSET + 4 * queue, &cnt);
24 if (!cnt)
25 return -EINVAL;
26
27 regmap_read(prueth->miig_rt, ICSSG_QUEUE_OFFSET + 4 * queue, &val);
28
29 return val;
30 }
31 EXPORT_SYMBOL_GPL(icssg_queue_pop);
32
icssg_queue_push(struct prueth * prueth,int queue,u16 addr)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 EXPORT_SYMBOL_GPL(icssg_queue_push);
41
icssg_queue_level(struct prueth * prueth,int queue)42 u32 icssg_queue_level(struct prueth *prueth, int queue)
43 {
44 u32 reg;
45
46 if (queue >= ICSSG_QUEUES_MAX)
47 return 0;
48
49 regmap_read(prueth->miig_rt, ICSSG_QUEUE_CNT_OFFSET + 4 * queue, ®);
50
51 return reg;
52 }
53