2 * Copyright (c) 2017 Intel Corporation
4 * Intel Mobile Internet Devices (MID) based on Intel Atom SoCs have few
5 * microcontrollers inside to do some auxiliary tasks. One of such
6 * microcontroller is System Controller Unit (SCU) which, in particular,
7 * is servicing watchdog and controlling system reset function.
9 * This driver enables IPC channel to SCU.
11 * SPDX-License-Identifier: GPL-2.0+
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_simple_command() - send a simple command
110 * Issue a simple command to the SCU. Do not use this interface if
111 * you must then access data as any data values may be overwritten
112 * by another SCU access by the time this function returns.
114 * This function may sleep. Locking for SCU accesses is handled for
117 int scu_ipc_simple_command(u32 cmd, u32 sub)
123 ret = syscon_get_by_driver_data(X86_SYSCON_SCU, &dev);
127 scu = dev_get_priv(dev);
129 scu_ipc_send_command(scu->regs, sub << 12 | cmd);
130 return scu_ipc_check_status(scu->regs);
133 int scu_ipc_command(u32 cmd, u32 sub, u32 *in, int inlen, u32 *out, int outlen)
139 ret = syscon_get_by_driver_data(X86_SYSCON_SCU, &dev);
143 scu = dev_get_priv(dev);
145 return scu_ipc_cmd(scu->regs, cmd, sub, in, inlen, out, outlen);
148 static int scu_ipc_probe(struct udevice *dev)
150 struct scu *scu = dev_get_priv(dev);
152 scu->regs = syscon_get_first_range(X86_SYSCON_SCU);
157 static const struct udevice_id scu_ipc_match[] = {
158 { .compatible = "intel,scu-ipc", .data = X86_SYSCON_SCU },
162 U_BOOT_DRIVER(scu_ipc) = {
165 .of_match = scu_ipc_match,
166 .probe = scu_ipc_probe,
167 .priv_auto_alloc_size = sizeof(struct scu),