1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2017 Intel Corporation
5 * Intel Mobile Internet Devices (MID) based on Intel Atom SoCs have few
6 * microcontrollers inside to do some auxiliary tasks. One of such
7 * microcontroller is System Controller Unit (SCU) which, in particular,
8 * is servicing watchdog and controlling system reset function.
10 * This driver enables IPC channel to SCU.
17 #include <linux/bitops.h>
18 #include <linux/delay.h>
19 #include <linux/errno.h>
21 #include <linux/kernel.h>
23 /* SCU register map */
35 struct ipc_regs *regs;
39 * scu_ipc_send_command() - send command to SCU
40 * @regs: register map of SCU
43 * Command Register (Write Only):
44 * A write to this register results in an interrupt to the SCU core processor
46 * |rfu2(8) | size(8) | command id(4) | rfu1(3) | ioc(1) | command(8)|
48 static void scu_ipc_send_command(struct ipc_regs *regs, u32 cmd)
50 writel(cmd, ®s->cmd);
54 * scu_ipc_check_status() - check status of last command
55 * @regs: register map of SCU
57 * Status Register (Read Only):
58 * Driver will read this register to get the ready/busy status of the IPC
59 * block and error status of the IPC command that was just processed by SCU
61 * |rfu3(8)|error code(8)|initiator id(8)|cmd id(4)|rfu1(2)|error(1)|busy(1)|
63 static int scu_ipc_check_status(struct ipc_regs *regs)
65 int loop_count = 100000;
69 status = readl(®s->status);
70 if (!(status & BIT(0)))
74 } while (--loop_count);
78 if (status & BIT(1)) {
79 printf("%s() status=0x%08x\n", __func__, status);
86 static int scu_ipc_cmd(struct ipc_regs *regs, u32 cmd, u32 sub,
87 u32 *in, int inlen, u32 *out, int outlen)
91 for (i = 0; i < inlen; i++)
92 writel(*in++, ®s->wbuf[i]);
94 scu_ipc_send_command(regs, (inlen << 16) | (sub << 12) | cmd);
95 err = scu_ipc_check_status(regs);
98 for (i = 0; i < outlen; i++)
99 *out++ = readl(®s->rbuf[i]);
106 * scu_ipc_raw_command() - IPC command with data and pointers
107 * @cmd: IPC command code
108 * @sub: IPC command sub type
109 * @in: input data of this IPC command
110 * @inlen: input data length in dwords
111 * @out: output data of this IPC command
112 * @outlen: output data length in dwords
113 * @dptr: data writing to SPTR register
114 * @sptr: data writing to DPTR register
116 * Send an IPC command to SCU with input/output data and source/dest pointers.
118 * Return: an IPC error code or 0 on success.
120 int scu_ipc_raw_command(u32 cmd, u32 sub, u32 *in, int inlen, u32 *out,
121 int outlen, u32 dptr, u32 sptr)
123 int inbuflen = DIV_ROUND_UP(inlen, 4);
128 ret = syscon_get_by_driver_data(X86_SYSCON_SCU, &dev);
132 scu = dev_get_priv(dev);
138 writel(dptr, &scu->regs->dptr);
139 writel(sptr, &scu->regs->sptr);
142 * SRAM controller doesn't support 8-bit writes, it only
143 * supports 32-bit writes, so we have to copy input data into
144 * the temporary buffer, and SCU FW will use the inlen to
145 * determine the actual input data length in the temporary
151 memcpy(inbuf, in, inlen);
153 return scu_ipc_cmd(scu->regs, cmd, sub, inbuf, inlen, out, outlen);
157 * scu_ipc_simple_command() - send a simple command
161 * Issue a simple command to the SCU. Do not use this interface if
162 * you must then access data as any data values may be overwritten
163 * by another SCU access by the time this function returns.
165 * This function may sleep. Locking for SCU accesses is handled for
168 int scu_ipc_simple_command(u32 cmd, u32 sub)
174 ret = syscon_get_by_driver_data(X86_SYSCON_SCU, &dev);
178 scu = dev_get_priv(dev);
180 scu_ipc_send_command(scu->regs, sub << 12 | cmd);
181 return scu_ipc_check_status(scu->regs);
185 * scu_ipc_command - command with data
189 * @inlen: input length in dwords
191 * @outlen: output length in dwords
193 * Issue a command to the SCU which involves data transfers.
195 int scu_ipc_command(u32 cmd, u32 sub, u32 *in, int inlen, u32 *out, int outlen)
201 ret = syscon_get_by_driver_data(X86_SYSCON_SCU, &dev);
205 scu = dev_get_priv(dev);
207 return scu_ipc_cmd(scu->regs, cmd, sub, in, inlen, out, outlen);
210 static int scu_ipc_probe(struct udevice *dev)
212 struct scu *scu = dev_get_priv(dev);
214 scu->regs = syscon_get_first_range(X86_SYSCON_SCU);
219 static const struct udevice_id scu_ipc_match[] = {
220 { .compatible = "intel,scu-ipc", .data = X86_SYSCON_SCU },
224 U_BOOT_DRIVER(scu_ipc) = {
227 .of_match = scu_ipc_match,
228 .probe = scu_ipc_probe,
229 .priv_auto = sizeof(struct scu),