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.
18 #include <linux/errno.h>
20 #include <linux/kernel.h>
22 /* SCU register map */
34 struct ipc_regs *regs;
38 * scu_ipc_send_command() - send command to SCU
39 * @regs: register map of SCU
42 * Command Register (Write Only):
43 * A write to this register results in an interrupt to the SCU core processor
45 * |rfu2(8) | size(8) | command id(4) | rfu1(3) | ioc(1) | command(8)|
47 static void scu_ipc_send_command(struct ipc_regs *regs, u32 cmd)
49 writel(cmd, ®s->cmd);
53 * scu_ipc_check_status() - check status of last command
54 * @regs: register map of SCU
56 * Status Register (Read Only):
57 * Driver will read this register to get the ready/busy status of the IPC
58 * block and error status of the IPC command that was just processed by SCU
60 * |rfu3(8)|error code(8)|initiator id(8)|cmd id(4)|rfu1(2)|error(1)|busy(1)|
62 static int scu_ipc_check_status(struct ipc_regs *regs)
64 int loop_count = 100000;
68 status = readl(®s->status);
69 if (!(status & BIT(0)))
73 } while (--loop_count);
77 if (status & BIT(1)) {
78 printf("%s() status=0x%08x\n", __func__, status);
85 static int scu_ipc_cmd(struct ipc_regs *regs, u32 cmd, u32 sub,
86 u32 *in, int inlen, u32 *out, int outlen)
90 for (i = 0; i < inlen; i++)
91 writel(*in++, ®s->wbuf[i]);
93 scu_ipc_send_command(regs, (inlen << 16) | (sub << 12) | cmd);
94 err = scu_ipc_check_status(regs);
97 for (i = 0; i < outlen; i++)
98 *out++ = readl(®s->rbuf[i]);
105 * scu_ipc_simple_command() - send a simple command
109 * Issue a simple command to the SCU. Do not use this interface if
110 * you must then access data as any data values may be overwritten
111 * by another SCU access by the time this function returns.
113 * This function may sleep. Locking for SCU accesses is handled for
116 int scu_ipc_simple_command(u32 cmd, u32 sub)
122 ret = syscon_get_by_driver_data(X86_SYSCON_SCU, &dev);
126 scu = dev_get_priv(dev);
128 scu_ipc_send_command(scu->regs, sub << 12 | cmd);
129 return scu_ipc_check_status(scu->regs);
132 int scu_ipc_command(u32 cmd, u32 sub, u32 *in, int inlen, u32 *out, int outlen)
138 ret = syscon_get_by_driver_data(X86_SYSCON_SCU, &dev);
142 scu = dev_get_priv(dev);
144 return scu_ipc_cmd(scu->regs, cmd, sub, in, inlen, out, outlen);
147 static int scu_ipc_probe(struct udevice *dev)
149 struct scu *scu = dev_get_priv(dev);
151 scu->regs = syscon_get_first_range(X86_SYSCON_SCU);
156 static const struct udevice_id scu_ipc_match[] = {
157 { .compatible = "intel,scu-ipc", .data = X86_SYSCON_SCU },
161 U_BOOT_DRIVER(scu_ipc) = {
164 .of_match = scu_ipc_match,
165 .probe = scu_ipc_probe,
166 .priv_auto_alloc_size = sizeof(struct scu),