2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-09-13 16:00:07 +00:00
|
|
|
/*
|
2017-10-23 07:53:58 +00:00
|
|
|
* Copyright (C) 2017, STMicroelectronics - All Rights Reserved
|
2020-12-02 17:47:30 +00:00
|
|
|
* Author(s): Patrice Chotard, <patrice.chotard@foss.st.com> for STMicroelectronics.
|
2017-09-13 16:00:07 +00:00
|
|
|
*/
|
|
|
|
|
2020-11-06 18:01:48 +00:00
|
|
|
#define LOG_CATEGORY UCLASS_RESET
|
|
|
|
|
2017-09-13 16:00:07 +00:00
|
|
|
#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>
|
2017-09-13 16:00:07 +00:00
|
|
|
#include <reset-uclass.h>
|
2018-07-09 13:17:20 +00:00
|
|
|
#include <stm32_rcc.h>
|
2017-09-13 16:00:07 +00:00
|
|
|
#include <asm/io.h>
|
2020-11-06 18:01:48 +00:00
|
|
|
#include <dm/device_compat.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2017-09-13 16:00:07 +00:00
|
|
|
|
2020-10-15 13:01:11 +00:00
|
|
|
/* offset of register without set/clear management */
|
|
|
|
#define RCC_MP_GCR_OFFSET 0x10C
|
|
|
|
|
2018-03-12 09:46:14 +00:00
|
|
|
/* reset clear offset for STM32MP RCC */
|
|
|
|
#define RCC_CL 0x4
|
|
|
|
|
2017-09-13 16:00:07 +00:00
|
|
|
struct stm32_reset_priv {
|
|
|
|
fdt_addr_t base;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int stm32_reset_request(struct reset_ctl *reset_ctl)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stm32_reset_free(struct reset_ctl *reset_ctl)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stm32_reset_assert(struct reset_ctl *reset_ctl)
|
|
|
|
{
|
|
|
|
struct stm32_reset_priv *priv = dev_get_priv(reset_ctl->dev);
|
2021-04-28 11:42:45 +00:00
|
|
|
int bank = (reset_ctl->id / (sizeof(u32) * BITS_PER_BYTE)) * 4;
|
|
|
|
int offset = reset_ctl->id % (sizeof(u32) * BITS_PER_BYTE);
|
2020-11-06 18:01:48 +00:00
|
|
|
|
|
|
|
dev_dbg(reset_ctl->dev, "reset id = %ld bank = %d offset = %d)\n",
|
|
|
|
reset_ctl->id, bank, offset);
|
2017-09-13 16:00:07 +00:00
|
|
|
|
2018-07-09 13:17:20 +00:00
|
|
|
if (dev_get_driver_data(reset_ctl->dev) == STM32MP1)
|
2020-10-15 13:01:11 +00:00
|
|
|
if (bank != RCC_MP_GCR_OFFSET)
|
|
|
|
/* reset assert is done in rcc set register */
|
|
|
|
writel(BIT(offset), priv->base + bank);
|
|
|
|
else
|
|
|
|
clrbits_le32(priv->base + bank, BIT(offset));
|
2018-03-12 09:46:14 +00:00
|
|
|
else
|
|
|
|
setbits_le32(priv->base + bank, BIT(offset));
|
2017-09-13 16:00:07 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stm32_reset_deassert(struct reset_ctl *reset_ctl)
|
|
|
|
{
|
|
|
|
struct stm32_reset_priv *priv = dev_get_priv(reset_ctl->dev);
|
2021-04-28 11:42:45 +00:00
|
|
|
int bank = (reset_ctl->id / (sizeof(u32) * BITS_PER_BYTE)) * 4;
|
|
|
|
int offset = reset_ctl->id % (sizeof(u32) * BITS_PER_BYTE);
|
2020-11-06 18:01:48 +00:00
|
|
|
|
|
|
|
dev_dbg(reset_ctl->dev, "reset id = %ld bank = %d offset = %d)\n",
|
|
|
|
reset_ctl->id, bank, offset);
|
2017-09-13 16:00:07 +00:00
|
|
|
|
2018-07-09 13:17:20 +00:00
|
|
|
if (dev_get_driver_data(reset_ctl->dev) == STM32MP1)
|
2020-10-15 13:01:11 +00:00
|
|
|
if (bank != RCC_MP_GCR_OFFSET)
|
|
|
|
/* reset deassert is done in rcc clr register */
|
|
|
|
writel(BIT(offset), priv->base + bank + RCC_CL);
|
|
|
|
else
|
|
|
|
setbits_le32(priv->base + bank, BIT(offset));
|
2018-03-12 09:46:14 +00:00
|
|
|
else
|
|
|
|
clrbits_le32(priv->base + bank, BIT(offset));
|
2017-09-13 16:00:07 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct reset_ops stm32_reset_ops = {
|
|
|
|
.request = stm32_reset_request,
|
2020-02-03 14:35:52 +00:00
|
|
|
.rfree = stm32_reset_free,
|
2017-09-13 16:00:07 +00:00
|
|
|
.rst_assert = stm32_reset_assert,
|
|
|
|
.rst_deassert = stm32_reset_deassert,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int stm32_reset_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct stm32_reset_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2018-03-12 09:46:14 +00:00
|
|
|
priv->base = dev_read_addr(dev);
|
|
|
|
if (priv->base == FDT_ADDR_T_NONE) {
|
|
|
|
/* for MFD, get address of parent */
|
|
|
|
priv->base = dev_read_addr(dev->parent);
|
|
|
|
if (priv->base == FDT_ADDR_T_NONE)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2017-09-13 16:00:07 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(stm32_rcc_reset) = {
|
|
|
|
.name = "stm32_rcc_reset",
|
|
|
|
.id = UCLASS_RESET,
|
|
|
|
.probe = stm32_reset_probe,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct stm32_reset_priv),
|
2017-09-13 16:00:07 +00:00
|
|
|
.ops = &stm32_reset_ops,
|
|
|
|
};
|