2020-09-09 16:44:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
2021-03-08 21:38:07 +00:00
|
|
|
* Copyright (C) 2020-2021, Linaro Limited
|
2020-09-09 16:44:05 +00:00
|
|
|
*/
|
|
|
|
|
2021-02-24 10:19:44 +00:00
|
|
|
#define LOG_CATEGORY UCLASS_MISC
|
|
|
|
|
2020-09-09 16:44:05 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <clk.h>
|
|
|
|
#include <dm.h>
|
2021-03-08 21:38:07 +00:00
|
|
|
#include <log.h>
|
2020-09-09 16:44:05 +00:00
|
|
|
#include <malloc.h>
|
2020-09-09 16:44:07 +00:00
|
|
|
#include <reset.h>
|
2020-09-09 16:44:05 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/scmi_test.h>
|
|
|
|
#include <dm/device_compat.h>
|
2021-03-08 21:38:07 +00:00
|
|
|
#include <power/regulator.h>
|
2020-09-09 16:44:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Simulate to some extent a SCMI exchange.
|
|
|
|
* This drivers gets SCMI resources and offers API function to the
|
2020-09-09 16:44:07 +00:00
|
|
|
* SCMI test sequence manipulate the resources, currently clock
|
|
|
|
* and reset controllers.
|
2020-09-09 16:44:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define SCMI_TEST_DEVICES_CLK_COUNT 3
|
2020-09-09 16:44:07 +00:00
|
|
|
#define SCMI_TEST_DEVICES_RD_COUNT 1
|
2021-03-08 21:38:07 +00:00
|
|
|
#define SCMI_TEST_DEVICES_VOLTD_COUNT 2
|
2020-09-09 16:44:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* struct sandbox_scmi_device_priv - Storage for device handles used by test
|
|
|
|
* @clk: Array of clock instances used by tests
|
2020-09-09 16:44:07 +00:00
|
|
|
* @reset_clt: Array of the reset controller instances used by tests
|
2021-03-08 21:38:07 +00:00
|
|
|
* @regulators: Array of regulator device references used by the tests
|
2020-09-09 16:44:05 +00:00
|
|
|
* @devices: Resources exposed by sandbox_scmi_devices_ctx()
|
|
|
|
*/
|
|
|
|
struct sandbox_scmi_device_priv {
|
|
|
|
struct clk clk[SCMI_TEST_DEVICES_CLK_COUNT];
|
2020-09-09 16:44:07 +00:00
|
|
|
struct reset_ctl reset_ctl[SCMI_TEST_DEVICES_RD_COUNT];
|
2021-03-08 21:38:07 +00:00
|
|
|
struct udevice *regulators[SCMI_TEST_DEVICES_VOLTD_COUNT];
|
2020-09-09 16:44:05 +00:00
|
|
|
struct sandbox_scmi_devices devices;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sandbox_scmi_devices *sandbox_scmi_devices_ctx(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct sandbox_scmi_device_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
if (priv)
|
|
|
|
return &priv->devices;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-09-09 16:44:07 +00:00
|
|
|
static int sandbox_scmi_devices_remove(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct sandbox_scmi_devices *devices = sandbox_scmi_devices_ctx(dev);
|
|
|
|
int ret = 0;
|
|
|
|
size_t n;
|
|
|
|
|
2021-02-01 02:01:54 +00:00
|
|
|
if (!devices)
|
|
|
|
return 0;
|
|
|
|
|
2020-09-09 16:44:07 +00:00
|
|
|
for (n = 0; n < SCMI_TEST_DEVICES_RD_COUNT; n++) {
|
|
|
|
int ret2 = reset_free(devices->reset + n);
|
|
|
|
|
|
|
|
if (ret2 && !ret)
|
|
|
|
ret = ret2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-09-09 16:44:05 +00:00
|
|
|
static int sandbox_scmi_devices_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct sandbox_scmi_device_priv *priv = dev_get_priv(dev);
|
|
|
|
int ret;
|
|
|
|
size_t n;
|
|
|
|
|
|
|
|
priv->devices = (struct sandbox_scmi_devices){
|
|
|
|
.clk = priv->clk,
|
|
|
|
.clk_count = SCMI_TEST_DEVICES_CLK_COUNT,
|
2020-09-09 16:44:07 +00:00
|
|
|
.reset = priv->reset_ctl,
|
|
|
|
.reset_count = SCMI_TEST_DEVICES_RD_COUNT,
|
2021-03-08 21:38:07 +00:00
|
|
|
.regul = priv->regulators,
|
|
|
|
.regul_count = SCMI_TEST_DEVICES_VOLTD_COUNT,
|
2020-09-09 16:44:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (n = 0; n < SCMI_TEST_DEVICES_CLK_COUNT; n++) {
|
|
|
|
ret = clk_get_by_index(dev, n, priv->devices.clk + n);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "%s: Failed on clk %zu\n", __func__, n);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-09 16:44:07 +00:00
|
|
|
for (n = 0; n < SCMI_TEST_DEVICES_RD_COUNT; n++) {
|
|
|
|
ret = reset_get_by_index(dev, n, priv->devices.reset + n);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "%s: Failed on reset %zu\n", __func__, n);
|
|
|
|
goto err_reset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-08 21:38:07 +00:00
|
|
|
for (n = 0; n < SCMI_TEST_DEVICES_VOLTD_COUNT; n++) {
|
|
|
|
char name[32];
|
|
|
|
|
|
|
|
ret = snprintf(name, sizeof(name), "regul%zu-supply", n);
|
|
|
|
assert(ret >= 0 && ret < sizeof(name));
|
|
|
|
|
|
|
|
ret = device_get_supply_regulator(dev, name,
|
|
|
|
priv->devices.regul + n);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "%s: Failed on voltd %zu\n", __func__, n);
|
|
|
|
goto err_regul;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-09 16:44:05 +00:00
|
|
|
return 0;
|
2020-09-09 16:44:07 +00:00
|
|
|
|
2021-03-08 21:38:07 +00:00
|
|
|
err_regul:
|
|
|
|
n = SCMI_TEST_DEVICES_RD_COUNT;
|
2020-09-09 16:44:07 +00:00
|
|
|
err_reset:
|
|
|
|
for (; n > 0; n--)
|
|
|
|
reset_free(priv->devices.reset + n - 1);
|
|
|
|
|
|
|
|
return ret;
|
2020-09-09 16:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id sandbox_scmi_devices_ids[] = {
|
|
|
|
{ .compatible = "sandbox,scmi-devices" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(sandbox_scmi_devices) = {
|
|
|
|
.name = "sandbox-scmi_devices",
|
|
|
|
.id = UCLASS_MISC,
|
|
|
|
.of_match = sandbox_scmi_devices_ids,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct sandbox_scmi_device_priv),
|
2020-09-09 16:44:07 +00:00
|
|
|
.remove = sandbox_scmi_devices_remove,
|
2020-09-09 16:44:05 +00:00
|
|
|
.probe = sandbox_scmi_devices_probe,
|
|
|
|
};
|