[U-Boot] [PATCH v2 17/19] rockchip: sysreset: deduplicate rk3066 and rk3188 sysreset drivers
Paweł Jarosz
paweljarosz3691 at gmail.com
Fri Aug 11 20:58:54 UTC 2017
Sysreset drivers for rk3066 and rk3188 contain common elements which can be reused.
Signed-off-by: Paweł Jarosz <paweljarosz3691 at gmail.com>
---
Changes since v1:
- none
.../include/asm/arch-rockchip/sysreset_common.h | 20 +++++++++++
arch/arm/mach-rockchip/Makefile | 3 ++
arch/arm/mach-rockchip/sysreset-common.c | 39 ++++++++++++++++++++++
drivers/sysreset/sysreset_rk3066.c | 34 ++++++-------------
drivers/sysreset/sysreset_rk3188.c | 35 ++++++-------------
5 files changed, 84 insertions(+), 47 deletions(-)
create mode 100644 arch/arm/include/asm/arch-rockchip/sysreset_common.h
create mode 100644 arch/arm/mach-rockchip/sysreset-common.c
diff --git a/arch/arm/include/asm/arch-rockchip/sysreset_common.h b/arch/arm/include/asm/arch-rockchip/sysreset_common.h
new file mode 100644
index 0000000..c7e1fc0
--- /dev/null
+++ b/arch/arm/include/asm/arch-rockchip/sysreset_common.h
@@ -0,0 +1,20 @@
+/*
+ * (C) Copyright 2017 Paweł Jarosz <paweljarosz3691 at gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#ifndef _ASM_ARCH_SYSRESET_COMMON_H
+#define _ASM_ARCH_SYSRESET_COMMON_H
+
+struct rockchip_sysreset_data {
+ void *grf_soc_con0;
+ uint32_t noc_remap_mask;
+ void *cru_mode_con;
+ void *cru_glb_srst_snd_value;
+ void *cru_glb_srst_fst_value;
+};
+
+int rockchip_sysreset_request(struct rockchip_sysreset_data *data,
+ enum sysreset_t type);
+#endif
diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile
index ae878ef..b58a9c4 100644
--- a/arch/arm/mach-rockchip/Makefile
+++ b/arch/arm/mach-rockchip/Makefile
@@ -11,6 +11,9 @@
obj-spl-$(CONFIG_ROCKCHIP_BROM_HELPER) += bootrom.o save_boot_param.o
obj-tpl-$(CONFIG_ROCKCHIP_BROM_HELPER) += bootrom.o save_boot_param.o
+obj-$(CONFIG_ROCKCHIP_RK3066) += sysreset-common.o
+obj-$(CONFIG_ROCKCHIP_RK3188) += sysreset-common.o
+
obj-tpl-$(CONFIG_ROCKCHIP_RK3066) += rk3066-board-tpl.o
obj-tpl-$(CONFIG_ROCKCHIP_RK3188) += rk3188-board-tpl.o
obj-tpl-$(CONFIG_ROCKCHIP_RK3368) += rk3368-board-tpl.o
diff --git a/arch/arm/mach-rockchip/sysreset-common.c b/arch/arm/mach-rockchip/sysreset-common.c
new file mode 100644
index 0000000..41e76e3
--- /dev/null
+++ b/arch/arm/mach-rockchip/sysreset-common.c
@@ -0,0 +1,39 @@
+/*
+ * (C) Copyright 2017 Paweł Jarosz <paweljarosz3691 at gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <sysreset.h>
+#include <asm/io.h>
+#include <asm/arch/hardware.h>
+#include <asm/arch/sysreset_common.h>
+#include <linux/err.h>
+
+int rockchip_sysreset_request(struct rockchip_sysreset_data *data,
+ enum sysreset_t type)
+{
+ switch (type) {
+ case SYSRESET_WARM:
+ /*
+ * warm-reset keeps the remap value,
+ * so make sure it's disabled.
+ */
+ rk_clrsetreg(data->grf_soc_con0,
+ data->noc_remap_mask, 0);
+
+ rk_clrreg(data->cru_mode_con, 0xffff);
+ writel(0xeca8, data->cru_glb_srst_snd_value);
+ break;
+ case SYSRESET_COLD:
+ rk_clrreg(data->cru_mode_con, 0xffff);
+ writel(0xfdb9, data->cru_glb_srst_fst_value);
+ break;
+ default:
+ return -EPROTONOSUPPORT;
+ }
+
+ return -EINPROGRESS;
+}
diff --git a/drivers/sysreset/sysreset_rk3066.c b/drivers/sysreset/sysreset_rk3066.c
index b5dcb9a..f82b3dd 100644
--- a/drivers/sysreset/sysreset_rk3066.c
+++ b/drivers/sysreset/sysreset_rk3066.c
@@ -14,40 +14,28 @@
#include <asm/arch/cru_rk3066.h>
#include <asm/arch/grf_rk3066.h>
#include <asm/arch/hardware.h>
+#include <asm/arch/sysreset_common.h>
#include <linux/err.h>
int rk3066_sysreset_request(struct udevice *dev, enum sysreset_t type)
{
struct rk3066_cru *cru = rockchip_get_cru();
- struct rk3066_grf *grf;
+ struct rk3066_grf *grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
+ struct rockchip_sysreset_data data = {
+ .grf_soc_con0 = &grf->soc_con0,
+ .noc_remap_mask = NOC_REMAP_MASK,
+ .cru_mode_con = &cru->cru_mode_con,
+ .cru_glb_srst_snd_value = &cru->cru_glb_srst_snd_value,
+ .cru_glb_srst_fst_value = &cru->cru_glb_srst_fst_value
+ };
if (IS_ERR(cru))
return PTR_ERR(cru);
- switch (type) {
- case SYSRESET_WARM:
- grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
- if (IS_ERR(grf))
- return -EPROTONOSUPPORT;
- /*
- * warm-reset keeps the remap value,
- * so make sure it's disabled.
- */
- rk_clrsetreg(&grf->soc_con0,
- NOC_REMAP_MASK, 0 << NOC_REMAP_SHIFT);
-
- rk_clrreg(&cru->cru_mode_con, 0xffff);
- writel(0xeca8, &cru->cru_glb_srst_snd_value);
- break;
- case SYSRESET_COLD:
- rk_clrreg(&cru->cru_mode_con, 0xffff);
- writel(0xfdb9, &cru->cru_glb_srst_fst_value);
- break;
- default:
+ if (IS_ERR(grf))
return -EPROTONOSUPPORT;
- }
- return -EINPROGRESS;
+ return rockchip_sysreset_request(&data, type);
}
static struct sysreset_ops rk3066_sysreset = {
diff --git a/drivers/sysreset/sysreset_rk3188.c b/drivers/sysreset/sysreset_rk3188.c
index 053a634..e924a02 100644
--- a/drivers/sysreset/sysreset_rk3188.c
+++ b/drivers/sysreset/sysreset_rk3188.c
@@ -14,41 +14,28 @@
#include <asm/arch/cru_rk3188.h>
#include <asm/arch/grf_rk3188.h>
#include <asm/arch/hardware.h>
+#include <asm/arch/sysreset_common.h>
#include <linux/err.h>
int rk3188_sysreset_request(struct udevice *dev, enum sysreset_t type)
{
struct rk3188_cru *cru = rockchip_get_cru();
- struct rk3188_grf *grf;
+ struct rk3188_grf *grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
+ struct rockchip_sysreset_data data = {
+ .grf_soc_con0 = &grf->soc_con0,
+ .noc_remap_mask = NOC_REMAP_MASK,
+ .cru_mode_con = &cru->cru_mode_con,
+ .cru_glb_srst_snd_value = &cru->cru_glb_srst_snd_value,
+ .cru_glb_srst_fst_value = &cru->cru_glb_srst_fst_value
+ };
if (IS_ERR(cru))
return PTR_ERR(cru);
- switch (type) {
- case SYSRESET_WARM:
- grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
- if (IS_ERR(grf))
- return -EPROTONOSUPPORT;
- /*
- * warm-reset keeps the remap value,
- * so make sure it's disabled.
- */
- rk_clrsetreg(&grf->soc_con0,
- NOC_REMAP_MASK << NOC_REMAP_SHIFT,
- 0 << NOC_REMAP_SHIFT);
-
- rk_clrreg(&cru->cru_mode_con, 0xffff);
- writel(0xeca8, &cru->cru_glb_srst_snd_value);
- break;
- case SYSRESET_COLD:
- rk_clrreg(&cru->cru_mode_con, 0xffff);
- writel(0xfdb9, &cru->cru_glb_srst_fst_value);
- break;
- default:
+ if (IS_ERR(grf))
return -EPROTONOSUPPORT;
- }
- return -EINPROGRESS;
+ return rockchip_sysreset_request(&data, type);
}
static struct sysreset_ops rk3188_sysreset = {
--
2.7.4
More information about the U-Boot
mailing list