Skip to content

Commit 684415d

Browse files
committed
Merge tag 'v5.5-next-soc' of https://git.kernel.org/pub/scm/linux/kernel/git/matthias.bgg/linux into arm/drivers
cmdq: - clean ups of unused code and debuggability - add cmdq_instruction to make the function call interface more readable - add functions for polling and providing info for the user of cmdq scpsys: - add bindings for MT6765 * tag 'v5.5-next-soc' of https://git.kernel.org/pub/scm/linux/kernel/git/matthias.bgg/linux: dt-bindings: mediatek: add MT6765 power dt-bindings soc: mediatek: cmdq: delete not used define soc: mediatek: cmdq: add cmdq_dev_get_client_reg function soc: mediatek: cmdq: add polling function soc: mediatek: cmdq: define the instruction struct soc: mediatek: cmdq: remove OR opertaion from err return Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Olof Johansson <[email protected]>
2 parents 96b34ba + 9c26abe commit 684415d

File tree

5 files changed

+205
-28
lines changed

5 files changed

+205
-28
lines changed

Documentation/devicetree/bindings/soc/mediatek/scpsys.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The driver implements the Generic PM domain bindings described in
1111
power/power-domain.yaml. It provides the power domains defined in
1212
- include/dt-bindings/power/mt8173-power.h
1313
- include/dt-bindings/power/mt6797-power.h
14+
- include/dt-bindings/power/mt6765-power.h
1415
- include/dt-bindings/power/mt2701-power.h
1516
- include/dt-bindings/power/mt2712-power.h
1617
- include/dt-bindings/power/mt7622-power.h
@@ -19,6 +20,7 @@ Required properties:
1920
- compatible: Should be one of:
2021
- "mediatek,mt2701-scpsys"
2122
- "mediatek,mt2712-scpsys"
23+
- "mediatek,mt6765-scpsys"
2224
- "mediatek,mt6797-scpsys"
2325
- "mediatek,mt7622-scpsys"
2426
- "mediatek,mt7623-scpsys", "mediatek,mt2701-scpsys": For MT7623 SoC
@@ -33,6 +35,10 @@ Required properties:
3335
enabled before enabling certain power domains.
3436
Required clocks for MT2701 or MT7623: "mm", "mfg", "ethif"
3537
Required clocks for MT2712: "mm", "mfg", "venc", "jpgdec", "audio", "vdec"
38+
Required clocks for MT6765: MUX: "mm", "mfg"
39+
CG: "mm-0", "mm-1", "mm-2", "mm-3", "isp-0",
40+
"isp-1", "cam-0", "cam-1", "cam-2",
41+
"cam-3","cam-4"
3642
Required clocks for MT6797: "mm", "mfg", "vdec"
3743
Required clocks for MT7622 or MT7629: "hif_sel"
3844
Required clocks for MT7623A: "ethif"

drivers/soc/mediatek/mtk-cmdq-helper.c

Lines changed: 121 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,51 @@
99
#include <linux/mailbox_controller.h>
1010
#include <linux/soc/mediatek/mtk-cmdq.h>
1111

12-
#define CMDQ_ARG_A_WRITE_MASK 0xffff
1312
#define CMDQ_WRITE_ENABLE_MASK BIT(0)
13+
#define CMDQ_POLL_ENABLE_MASK BIT(0)
1414
#define CMDQ_EOC_IRQ_EN BIT(0)
15-
#define CMDQ_EOC_CMD ((u64)((CMDQ_CODE_EOC << CMDQ_OP_CODE_SHIFT)) \
16-
<< 32 | CMDQ_EOC_IRQ_EN)
15+
16+
struct cmdq_instruction {
17+
union {
18+
u32 value;
19+
u32 mask;
20+
};
21+
union {
22+
u16 offset;
23+
u16 event;
24+
};
25+
u8 subsys;
26+
u8 op;
27+
};
28+
29+
int cmdq_dev_get_client_reg(struct device *dev,
30+
struct cmdq_client_reg *client_reg, int idx)
31+
{
32+
struct of_phandle_args spec;
33+
int err;
34+
35+
if (!client_reg)
36+
return -ENOENT;
37+
38+
err = of_parse_phandle_with_fixed_args(dev->of_node,
39+
"mediatek,gce-client-reg",
40+
3, idx, &spec);
41+
if (err < 0) {
42+
dev_err(dev,
43+
"error %d can't parse gce-client-reg property (%d)",
44+
err, idx);
45+
46+
return err;
47+
}
48+
49+
client_reg->subsys = (u8)spec.args[0];
50+
client_reg->offset = (u16)spec.args[1];
51+
client_reg->size = (u16)spec.args[2];
52+
of_node_put(spec.np);
53+
54+
return 0;
55+
}
56+
EXPORT_SYMBOL(cmdq_dev_get_client_reg);
1757

1858
static void cmdq_client_timeout(struct timer_list *t)
1959
{
@@ -110,10 +150,10 @@ void cmdq_pkt_destroy(struct cmdq_pkt *pkt)
110150
}
111151
EXPORT_SYMBOL(cmdq_pkt_destroy);
112152

113-
static int cmdq_pkt_append_command(struct cmdq_pkt *pkt, enum cmdq_code code,
114-
u32 arg_a, u32 arg_b)
153+
static int cmdq_pkt_append_command(struct cmdq_pkt *pkt,
154+
struct cmdq_instruction inst)
115155
{
116-
u64 *cmd_ptr;
156+
struct cmdq_instruction *cmd_ptr;
117157

118158
if (unlikely(pkt->cmd_buf_size + CMDQ_INST_SIZE > pkt->buf_size)) {
119159
/*
@@ -129,77 +169,130 @@ static int cmdq_pkt_append_command(struct cmdq_pkt *pkt, enum cmdq_code code,
129169
__func__, (u32)pkt->buf_size);
130170
return -ENOMEM;
131171
}
172+
132173
cmd_ptr = pkt->va_base + pkt->cmd_buf_size;
133-
(*cmd_ptr) = (u64)((code << CMDQ_OP_CODE_SHIFT) | arg_a) << 32 | arg_b;
174+
*cmd_ptr = inst;
134175
pkt->cmd_buf_size += CMDQ_INST_SIZE;
135176

136177
return 0;
137178
}
138179

139180
int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u16 offset, u32 value)
140181
{
141-
u32 arg_a = (offset & CMDQ_ARG_A_WRITE_MASK) |
142-
(subsys << CMDQ_SUBSYS_SHIFT);
182+
struct cmdq_instruction inst;
143183

144-
return cmdq_pkt_append_command(pkt, CMDQ_CODE_WRITE, arg_a, value);
184+
inst.op = CMDQ_CODE_WRITE;
185+
inst.value = value;
186+
inst.offset = offset;
187+
inst.subsys = subsys;
188+
189+
return cmdq_pkt_append_command(pkt, inst);
145190
}
146191
EXPORT_SYMBOL(cmdq_pkt_write);
147192

148193
int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u8 subsys,
149194
u16 offset, u32 value, u32 mask)
150195
{
151-
u32 offset_mask = offset;
152-
int err = 0;
196+
struct cmdq_instruction inst = { {0} };
197+
u16 offset_mask = offset;
198+
int err;
153199

154200
if (mask != 0xffffffff) {
155-
err = cmdq_pkt_append_command(pkt, CMDQ_CODE_MASK, 0, ~mask);
201+
inst.op = CMDQ_CODE_MASK;
202+
inst.mask = ~mask;
203+
err = cmdq_pkt_append_command(pkt, inst);
204+
if (err < 0)
205+
return err;
206+
156207
offset_mask |= CMDQ_WRITE_ENABLE_MASK;
157208
}
158-
err |= cmdq_pkt_write(pkt, subsys, offset_mask, value);
209+
err = cmdq_pkt_write(pkt, subsys, offset_mask, value);
159210

160211
return err;
161212
}
162213
EXPORT_SYMBOL(cmdq_pkt_write_mask);
163214

164215
int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event)
165216
{
166-
u32 arg_b;
217+
struct cmdq_instruction inst = { {0} };
167218

168219
if (event >= CMDQ_MAX_EVENT)
169220
return -EINVAL;
170221

171-
/*
172-
* WFE arg_b
173-
* bit 0-11: wait value
174-
* bit 15: 1 - wait, 0 - no wait
175-
* bit 16-27: update value
176-
* bit 31: 1 - update, 0 - no update
177-
*/
178-
arg_b = CMDQ_WFE_UPDATE | CMDQ_WFE_WAIT | CMDQ_WFE_WAIT_VALUE;
222+
inst.op = CMDQ_CODE_WFE;
223+
inst.value = CMDQ_WFE_OPTION;
224+
inst.event = event;
179225

180-
return cmdq_pkt_append_command(pkt, CMDQ_CODE_WFE, event, arg_b);
226+
return cmdq_pkt_append_command(pkt, inst);
181227
}
182228
EXPORT_SYMBOL(cmdq_pkt_wfe);
183229

184230
int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u16 event)
185231
{
232+
struct cmdq_instruction inst = { {0} };
233+
186234
if (event >= CMDQ_MAX_EVENT)
187235
return -EINVAL;
188236

189-
return cmdq_pkt_append_command(pkt, CMDQ_CODE_WFE, event,
190-
CMDQ_WFE_UPDATE);
237+
inst.op = CMDQ_CODE_WFE;
238+
inst.value = CMDQ_WFE_UPDATE;
239+
inst.event = event;
240+
241+
return cmdq_pkt_append_command(pkt, inst);
191242
}
192243
EXPORT_SYMBOL(cmdq_pkt_clear_event);
193244

245+
int cmdq_pkt_poll(struct cmdq_pkt *pkt, u8 subsys,
246+
u16 offset, u32 value)
247+
{
248+
struct cmdq_instruction inst = { {0} };
249+
int err;
250+
251+
inst.op = CMDQ_CODE_POLL;
252+
inst.value = value;
253+
inst.offset = offset;
254+
inst.subsys = subsys;
255+
err = cmdq_pkt_append_command(pkt, inst);
256+
257+
return err;
258+
}
259+
EXPORT_SYMBOL(cmdq_pkt_poll);
260+
261+
int cmdq_pkt_poll_mask(struct cmdq_pkt *pkt, u8 subsys,
262+
u16 offset, u32 value, u32 mask)
263+
{
264+
struct cmdq_instruction inst = { {0} };
265+
int err;
266+
267+
inst.op = CMDQ_CODE_MASK;
268+
inst.mask = ~mask;
269+
err = cmdq_pkt_append_command(pkt, inst);
270+
if (err < 0)
271+
return err;
272+
273+
offset = offset | CMDQ_POLL_ENABLE_MASK;
274+
err = cmdq_pkt_poll(pkt, subsys, offset, value);
275+
276+
return err;
277+
}
278+
EXPORT_SYMBOL(cmdq_pkt_poll_mask);
279+
194280
static int cmdq_pkt_finalize(struct cmdq_pkt *pkt)
195281
{
282+
struct cmdq_instruction inst = { {0} };
196283
int err;
197284

198285
/* insert EOC and generate IRQ for each command iteration */
199-
err = cmdq_pkt_append_command(pkt, CMDQ_CODE_EOC, 0, CMDQ_EOC_IRQ_EN);
286+
inst.op = CMDQ_CODE_EOC;
287+
inst.value = CMDQ_EOC_IRQ_EN;
288+
err = cmdq_pkt_append_command(pkt, inst);
289+
if (err < 0)
290+
return err;
200291

201292
/* JUMP to end */
202-
err |= cmdq_pkt_append_command(pkt, CMDQ_CODE_JUMP, 0, CMDQ_JUMP_PASS);
293+
inst.op = CMDQ_CODE_JUMP;
294+
inst.value = CMDQ_JUMP_PASS;
295+
err = cmdq_pkt_append_command(pkt, inst);
203296

204297
return err;
205298
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _DT_BINDINGS_POWER_MT6765_POWER_H
3+
#define _DT_BINDINGS_POWER_MT6765_POWER_H
4+
5+
#define MT6765_POWER_DOMAIN_CONN 0
6+
#define MT6765_POWER_DOMAIN_MM 1
7+
#define MT6765_POWER_DOMAIN_MFG_ASYNC 2
8+
#define MT6765_POWER_DOMAIN_ISP 3
9+
#define MT6765_POWER_DOMAIN_MFG 4
10+
#define MT6765_POWER_DOMAIN_MFG_CORE0 5
11+
#define MT6765_POWER_DOMAIN_CAM 6
12+
#define MT6765_POWER_DOMAIN_VCODEC 7
13+
14+
#endif /* _DT_BINDINGS_POWER_MT6765_POWER_H */

include/linux/mailbox/mtk-cmdq-mailbox.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
#define CMDQ_WFE_WAIT BIT(15)
2121
#define CMDQ_WFE_WAIT_VALUE 0x1
2222

23+
/*
24+
* WFE arg_b
25+
* bit 0-11: wait value
26+
* bit 15: 1 - wait, 0 - no wait
27+
* bit 16-27: update value
28+
* bit 31: 1 - update, 0 - no update
29+
*/
30+
#define CMDQ_WFE_OPTION (CMDQ_WFE_UPDATE | CMDQ_WFE_WAIT | \
31+
CMDQ_WFE_WAIT_VALUE)
32+
2333
/** cmdq event maximum */
2434
#define CMDQ_MAX_EVENT 0x3ff
2535

@@ -45,6 +55,7 @@
4555
enum cmdq_code {
4656
CMDQ_CODE_MASK = 0x02,
4757
CMDQ_CODE_WRITE = 0x04,
58+
CMDQ_CODE_POLL = 0x08,
4859
CMDQ_CODE_JUMP = 0x10,
4960
CMDQ_CODE_WFE = 0x20,
5061
CMDQ_CODE_EOC = 0x40,

include/linux/soc/mediatek/mtk-cmdq.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515

1616
struct cmdq_pkt;
1717

18+
struct cmdq_client_reg {
19+
u8 subsys;
20+
u16 offset;
21+
u16 size;
22+
};
23+
1824
struct cmdq_client {
1925
spinlock_t lock;
2026
u32 pkt_cnt;
@@ -24,6 +30,21 @@ struct cmdq_client {
2430
u32 timeout_ms; /* in unit of microsecond */
2531
};
2632

33+
/**
34+
* cmdq_dev_get_client_reg() - parse cmdq client reg from the device
35+
* node of CMDQ client
36+
* @dev: device of CMDQ mailbox client
37+
* @client_reg: CMDQ client reg pointer
38+
* @idx: the index of desired reg
39+
*
40+
* Return: 0 for success; else the error code is returned
41+
*
42+
* Help CMDQ client parsing the cmdq client reg
43+
* from the device node of CMDQ client.
44+
*/
45+
int cmdq_dev_get_client_reg(struct device *dev,
46+
struct cmdq_client_reg *client_reg, int idx);
47+
2748
/**
2849
* cmdq_mbox_create() - create CMDQ mailbox client and channel
2950
* @dev: device of CMDQ mailbox client
@@ -99,6 +120,38 @@ int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event);
99120
*/
100121
int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u16 event);
101122

123+
/**
124+
* cmdq_pkt_poll() - Append polling command to the CMDQ packet, ask GCE to
125+
* execute an instruction that wait for a specified
126+
* hardware register to check for the value w/o mask.
127+
* All GCE hardware threads will be blocked by this
128+
* instruction.
129+
* @pkt: the CMDQ packet
130+
* @subsys: the CMDQ sub system code
131+
* @offset: register offset from CMDQ sub system
132+
* @value: the specified target register value
133+
*
134+
* Return: 0 for success; else the error code is returned
135+
*/
136+
int cmdq_pkt_poll(struct cmdq_pkt *pkt, u8 subsys,
137+
u16 offset, u32 value);
138+
139+
/**
140+
* cmdq_pkt_poll_mask() - Append polling command to the CMDQ packet, ask GCE to
141+
* execute an instruction that wait for a specified
142+
* hardware register to check for the value w/ mask.
143+
* All GCE hardware threads will be blocked by this
144+
* instruction.
145+
* @pkt: the CMDQ packet
146+
* @subsys: the CMDQ sub system code
147+
* @offset: register offset from CMDQ sub system
148+
* @value: the specified target register value
149+
* @mask: the specified target register mask
150+
*
151+
* Return: 0 for success; else the error code is returned
152+
*/
153+
int cmdq_pkt_poll_mask(struct cmdq_pkt *pkt, u8 subsys,
154+
u16 offset, u32 value, u32 mask);
102155
/**
103156
* cmdq_pkt_flush_async() - trigger CMDQ to asynchronously execute the CMDQ
104157
* packet and call back at the end of done packet

0 commit comments

Comments
 (0)