2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2018-03-29 12:55:25 +00:00
|
|
|
/*
|
|
|
|
* Amlogic Meson Reset Controller driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2018 BayLibre, SAS.
|
|
|
|
* Author: Neil Armstrong <narmstrong@baylibre.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <malloc.h>
|
2018-03-29 12:55:25 +00:00
|
|
|
#include <reset-uclass.h>
|
|
|
|
#include <regmap.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2018-03-29 12:55:25 +00:00
|
|
|
|
|
|
|
#define REG_COUNT 8
|
|
|
|
#define BITS_PER_REG 32
|
|
|
|
#define LEVEL_OFFSET 0x7c
|
|
|
|
|
|
|
|
struct meson_reset_priv {
|
|
|
|
struct regmap *regmap;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int meson_reset_request(struct reset_ctl *reset_ctl)
|
|
|
|
{
|
|
|
|
if (reset_ctl->id > (REG_COUNT * BITS_PER_REG))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int meson_reset_free(struct reset_ctl *reset_ctl)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int meson_reset_level(struct reset_ctl *reset_ctl, bool assert)
|
|
|
|
{
|
|
|
|
struct meson_reset_priv *priv = dev_get_priv(reset_ctl->dev);
|
|
|
|
uint bank = reset_ctl->id / BITS_PER_REG;
|
|
|
|
uint offset = reset_ctl->id % BITS_PER_REG;
|
|
|
|
uint reg_offset = LEVEL_OFFSET + (bank << 2);
|
|
|
|
uint val;
|
|
|
|
|
|
|
|
regmap_read(priv->regmap, reg_offset, &val);
|
|
|
|
if (assert)
|
|
|
|
val &= ~BIT(offset);
|
|
|
|
else
|
|
|
|
val |= BIT(offset);
|
|
|
|
regmap_write(priv->regmap, reg_offset, val);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int meson_reset_assert(struct reset_ctl *reset_ctl)
|
|
|
|
{
|
|
|
|
return meson_reset_level(reset_ctl, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int meson_reset_deassert(struct reset_ctl *reset_ctl)
|
|
|
|
{
|
|
|
|
return meson_reset_level(reset_ctl, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct reset_ops meson_reset_ops = {
|
|
|
|
.request = meson_reset_request,
|
2020-02-03 14:35:52 +00:00
|
|
|
.rfree = meson_reset_free,
|
2018-03-29 12:55:25 +00:00
|
|
|
.rst_assert = meson_reset_assert,
|
|
|
|
.rst_deassert = meson_reset_deassert,
|
|
|
|
};
|
|
|
|
|
2021-09-27 15:42:38 +00:00
|
|
|
static const struct udevice_id meson_reset_ids[] = {
|
|
|
|
{ .compatible = "amlogic,meson-gxbb-reset" },
|
2019-03-26 10:25:44 +00:00
|
|
|
{ .compatible = "amlogic,meson-axg-reset" },
|
2021-09-27 15:42:38 +00:00
|
|
|
{ }
|
|
|
|
};
|
2018-03-29 12:55:25 +00:00
|
|
|
|
|
|
|
static int meson_reset_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct meson_reset_priv *priv = dev_get_priv(dev);
|
2021-09-27 15:42:38 +00:00
|
|
|
|
2018-04-19 03:14:03 +00:00
|
|
|
return regmap_init_mem(dev_ofnode(dev), &priv->regmap);
|
2018-03-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(meson_reset) = {
|
|
|
|
.name = "meson_reset",
|
|
|
|
.id = UCLASS_RESET,
|
|
|
|
.of_match = meson_reset_ids,
|
|
|
|
.probe = meson_reset_probe,
|
|
|
|
.ops = &meson_reset_ops,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct meson_reset_priv),
|
2018-03-29 12:55:25 +00:00
|
|
|
};
|