mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2026-06-13 15:03:58 +03:00
arm: apple: rtkit: Add a generic RTKit helper driver
This driver handles the MTP ASC coprocessor, which does not need any special handling on the RTKit side and communicates out-of-band. Signed-off-by: Hector Martin <marcan@marcan.st> Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
This commit is contained in:
@@ -29,3 +29,5 @@ int apple_rtkit_boot(struct apple_rtkit *rtk);
|
||||
int apple_rtkit_set_ap_power(struct apple_rtkit *rtk, int pwrstate);
|
||||
int apple_rtkit_poll(struct apple_rtkit *rtk, ulong timeout);
|
||||
int apple_rtkit_shutdown(struct apple_rtkit *rtk, int pwrstate);
|
||||
|
||||
int apple_rtkit_helper_poll(struct udevice *dev, ulong timeout);
|
||||
|
||||
@@ -3,4 +3,5 @@
|
||||
obj-y += board.o
|
||||
obj-y += lowlevel_init.o
|
||||
obj-y += rtkit.o
|
||||
obj-$(CONFIG_APPLE_MTP_KEYB) += rtkit_helper.o
|
||||
obj-$(CONFIG_NVME_APPLE) += sart.o
|
||||
|
||||
97
arch/arm/mach-apple/rtkit_helper.c
Normal file
97
arch/arm/mach-apple/rtkit_helper.c
Normal file
@@ -0,0 +1,97 @@
|
||||
// SPDX-License-Identifier: GPL-2.0+ OR MIT
|
||||
/*
|
||||
* Copyright The Asahi Linux Contributors
|
||||
*/
|
||||
|
||||
#include <dm.h>
|
||||
#include <mailbox.h>
|
||||
#include <mapmem.h>
|
||||
#include <reset.h>
|
||||
|
||||
#include <asm/io.h>
|
||||
#include <asm/arch/rtkit.h>
|
||||
#include <linux/iopoll.h>
|
||||
|
||||
/* ASC registers */
|
||||
#define REG_CPU_CTRL 0x0044
|
||||
#define REG_CPU_CTRL_RUN BIT(4)
|
||||
|
||||
struct rtkit_helper_priv {
|
||||
void *asc; /* ASC registers */
|
||||
struct mbox_chan chan;
|
||||
struct apple_rtkit *rtk;
|
||||
};
|
||||
|
||||
static int rtkit_helper_probe(struct udevice *dev)
|
||||
{
|
||||
struct rtkit_helper_priv *priv = dev_get_priv(dev);
|
||||
u32 ctrl;
|
||||
int ret;
|
||||
|
||||
priv->asc = dev_read_addr_ptr(dev);
|
||||
if (!priv->asc)
|
||||
return -EINVAL;
|
||||
|
||||
ret = mbox_get_by_index(dev, 0, &priv->chan);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ctrl = readl(priv->asc + REG_CPU_CTRL);
|
||||
writel(ctrl | REG_CPU_CTRL_RUN, priv->asc + REG_CPU_CTRL);
|
||||
|
||||
priv->rtk = apple_rtkit_init(&priv->chan, priv, NULL, NULL);
|
||||
if (!priv->rtk)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = apple_rtkit_boot(priv->rtk);
|
||||
if (ret < 0) {
|
||||
printf("%s: Helper apple_rtkit_boot returned: %d\n", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = apple_rtkit_set_ap_power(priv->rtk, APPLE_RTKIT_PWR_STATE_ON);
|
||||
if (ret < 0) {
|
||||
printf("%s: Helper apple_rtkit_set_ap_power returned: %d\n", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rtkit_helper_remove(struct udevice *dev)
|
||||
{
|
||||
struct rtkit_helper_priv *priv = dev_get_priv(dev);
|
||||
u32 ctrl;
|
||||
|
||||
apple_rtkit_shutdown(priv->rtk, APPLE_RTKIT_PWR_STATE_QUIESCED);
|
||||
|
||||
ctrl = readl(priv->asc + REG_CPU_CTRL);
|
||||
writel(ctrl & ~REG_CPU_CTRL_RUN, priv->asc + REG_CPU_CTRL);
|
||||
|
||||
apple_rtkit_free(priv->rtk);
|
||||
priv->rtk = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int apple_rtkit_helper_poll(struct udevice *dev, ulong timeout)
|
||||
{
|
||||
struct rtkit_helper_priv *priv = dev_get_priv(dev);
|
||||
|
||||
return apple_rtkit_poll(priv->rtk, timeout);
|
||||
}
|
||||
|
||||
static const struct udevice_id rtkit_helper_ids[] = {
|
||||
{ .compatible = "apple,rtk-helper-asc4" },
|
||||
{ /* sentinel */ }
|
||||
};
|
||||
|
||||
U_BOOT_DRIVER(rtkit_helper) = {
|
||||
.name = "rtkit_helper",
|
||||
.id = UCLASS_MISC,
|
||||
.of_match = rtkit_helper_ids,
|
||||
.priv_auto = sizeof(struct rtkit_helper_priv),
|
||||
.probe = rtkit_helper_probe,
|
||||
.remove = rtkit_helper_remove,
|
||||
.flags = DM_FLAG_OS_PREPARE,
|
||||
};
|
||||
Reference in New Issue
Block a user