2019-01-18 16:48:13 +00:00
|
|
|
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 Amarula Solutions.
|
|
|
|
* Author: Jagan Teki <jagan@amarulasolutions.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <malloc.h>
|
2019-01-18 16:48:13 +00:00
|
|
|
#include <reset-uclass.h>
|
|
|
|
#include <asm/io.h>
|
2021-09-12 16:48:43 +00:00
|
|
|
#include <clk/sunxi.h>
|
2020-12-23 02:30:28 +00:00
|
|
|
#include <dm/device-internal.h>
|
2019-01-18 16:48:13 +00:00
|
|
|
#include <dm/lists.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2019-01-18 16:48:13 +00:00
|
|
|
#include <linux/log2.h>
|
|
|
|
|
2022-05-09 05:29:36 +00:00
|
|
|
struct sunxi_reset_plat {
|
2019-01-18 16:48:13 +00:00
|
|
|
void *base;
|
|
|
|
const struct ccu_desc *desc;
|
|
|
|
};
|
|
|
|
|
2022-05-09 05:29:36 +00:00
|
|
|
static const struct ccu_reset *plat_to_reset(struct sunxi_reset_plat *plat,
|
2019-01-18 16:48:13 +00:00
|
|
|
unsigned long id)
|
|
|
|
{
|
2022-05-09 05:29:36 +00:00
|
|
|
return &plat->desc->resets[id];
|
2019-01-18 16:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sunxi_reset_request(struct reset_ctl *reset_ctl)
|
|
|
|
{
|
2022-05-09 05:29:36 +00:00
|
|
|
struct sunxi_reset_plat *plat = dev_get_plat(reset_ctl->dev);
|
2019-01-18 16:48:13 +00:00
|
|
|
|
|
|
|
debug("%s: (RST#%ld)\n", __func__, reset_ctl->id);
|
|
|
|
|
2022-05-09 05:29:36 +00:00
|
|
|
if (reset_ctl->id >= plat->desc->num_resets)
|
2019-01-18 16:48:13 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sunxi_set_reset(struct reset_ctl *reset_ctl, bool on)
|
|
|
|
{
|
2022-05-09 05:29:36 +00:00
|
|
|
struct sunxi_reset_plat *plat = dev_get_plat(reset_ctl->dev);
|
|
|
|
const struct ccu_reset *reset = plat_to_reset(plat, reset_ctl->id);
|
2019-01-18 16:48:13 +00:00
|
|
|
u32 reg;
|
|
|
|
|
|
|
|
if (!(reset->flags & CCU_RST_F_IS_VALID)) {
|
|
|
|
printf("%s: (RST#%ld) unhandled\n", __func__, reset_ctl->id);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("%s: (RST#%ld) off#0x%x, BIT(%d)\n", __func__,
|
|
|
|
reset_ctl->id, reset->off, ilog2(reset->bit));
|
|
|
|
|
2022-05-09 05:29:36 +00:00
|
|
|
reg = readl(plat->base + reset->off);
|
2019-01-18 16:48:13 +00:00
|
|
|
if (on)
|
|
|
|
reg |= reset->bit;
|
|
|
|
else
|
|
|
|
reg &= ~reset->bit;
|
|
|
|
|
2022-05-09 05:29:36 +00:00
|
|
|
writel(reg, plat->base + reset->off);
|
2019-01-18 16:48:13 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sunxi_reset_assert(struct reset_ctl *reset_ctl)
|
|
|
|
{
|
|
|
|
return sunxi_set_reset(reset_ctl, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sunxi_reset_deassert(struct reset_ctl *reset_ctl)
|
|
|
|
{
|
|
|
|
return sunxi_set_reset(reset_ctl, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct reset_ops sunxi_reset_ops = {
|
|
|
|
.request = sunxi_reset_request,
|
|
|
|
.rst_assert = sunxi_reset_assert,
|
|
|
|
.rst_deassert = sunxi_reset_deassert,
|
|
|
|
};
|
|
|
|
|
2022-05-09 05:29:36 +00:00
|
|
|
static int sunxi_reset_of_to_plat(struct udevice *dev)
|
2019-01-18 16:48:13 +00:00
|
|
|
{
|
2022-05-09 05:29:36 +00:00
|
|
|
struct sunxi_reset_plat *plat = dev_get_plat(dev);
|
2019-01-18 16:48:13 +00:00
|
|
|
|
2022-05-09 05:29:36 +00:00
|
|
|
plat->base = dev_read_addr_ptr(dev);
|
2019-01-18 16:48:13 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-05-09 05:29:33 +00:00
|
|
|
int sunxi_reset_bind(struct udevice *dev)
|
2019-01-18 16:48:13 +00:00
|
|
|
{
|
|
|
|
struct udevice *rst_dev;
|
2022-05-09 05:29:36 +00:00
|
|
|
struct sunxi_reset_plat *plat;
|
2019-01-18 16:48:13 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = device_bind_driver_to_node(dev, "sunxi_reset", "reset",
|
|
|
|
dev_ofnode(dev), &rst_dev);
|
|
|
|
if (ret) {
|
|
|
|
debug("failed to bind sunxi_reset driver (ret=%d)\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2022-05-09 05:29:36 +00:00
|
|
|
plat = malloc(sizeof(struct sunxi_reset_plat));
|
|
|
|
plat->desc = (const struct ccu_desc *)dev_get_driver_data(dev);
|
|
|
|
dev_set_plat(rst_dev, plat);
|
2019-01-18 16:48:13 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(sunxi_reset) = {
|
|
|
|
.name = "sunxi_reset",
|
|
|
|
.id = UCLASS_RESET,
|
|
|
|
.ops = &sunxi_reset_ops,
|
2022-05-09 05:29:36 +00:00
|
|
|
.of_to_plat = sunxi_reset_of_to_plat,
|
|
|
|
.plat_auto = sizeof(struct sunxi_reset_plat),
|
2019-01-18 16:48:13 +00:00
|
|
|
};
|