18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2014 STMicroelectronics (R&D) Limited
48c2ecf20Sopenharmony_ci * Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci#include <linux/module.h>
78c2ecf20Sopenharmony_ci#include <linux/of.h>
88c2ecf20Sopenharmony_ci#include <linux/of_platform.h>
98c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
108c2ecf20Sopenharmony_ci#include <dt-bindings/reset/stih407-resets.h>
118c2ecf20Sopenharmony_ci#include "reset-syscfg.h"
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/* STiH407 Peripheral powerdown definitions. */
148c2ecf20Sopenharmony_cistatic const char stih407_core[] = "st,stih407-core-syscfg";
158c2ecf20Sopenharmony_cistatic const char stih407_sbc_reg[] = "st,stih407-sbc-reg-syscfg";
168c2ecf20Sopenharmony_cistatic const char stih407_lpm[] = "st,stih407-lpm-syscfg";
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#define STIH407_PDN_0(_bit) \
198c2ecf20Sopenharmony_ci	_SYSCFG_RST_CH(stih407_core, SYSCFG_5000, _bit, SYSSTAT_5500, _bit)
208c2ecf20Sopenharmony_ci#define STIH407_PDN_1(_bit) \
218c2ecf20Sopenharmony_ci	_SYSCFG_RST_CH(stih407_core, SYSCFG_5001, _bit, SYSSTAT_5501, _bit)
228c2ecf20Sopenharmony_ci#define STIH407_PDN_ETH(_bit, _stat) \
238c2ecf20Sopenharmony_ci	_SYSCFG_RST_CH(stih407_sbc_reg, SYSCFG_4032, _bit, SYSSTAT_4520, _stat)
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/* Powerdown requests control 0 */
268c2ecf20Sopenharmony_ci#define SYSCFG_5000	0x0
278c2ecf20Sopenharmony_ci#define SYSSTAT_5500	0x7d0
288c2ecf20Sopenharmony_ci/* Powerdown requests control 1 (High Speed Links) */
298c2ecf20Sopenharmony_ci#define SYSCFG_5001	0x4
308c2ecf20Sopenharmony_ci#define SYSSTAT_5501	0x7d4
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci/* Ethernet powerdown/status/reset */
338c2ecf20Sopenharmony_ci#define SYSCFG_4032	0x80
348c2ecf20Sopenharmony_ci#define SYSSTAT_4520	0x820
358c2ecf20Sopenharmony_ci#define SYSCFG_4002	0x8
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistatic const struct syscfg_reset_channel_data stih407_powerdowns[] = {
388c2ecf20Sopenharmony_ci	[STIH407_EMISS_POWERDOWN] = STIH407_PDN_0(1),
398c2ecf20Sopenharmony_ci	[STIH407_NAND_POWERDOWN] = STIH407_PDN_0(0),
408c2ecf20Sopenharmony_ci	[STIH407_USB3_POWERDOWN] = STIH407_PDN_1(6),
418c2ecf20Sopenharmony_ci	[STIH407_USB2_PORT1_POWERDOWN] = STIH407_PDN_1(5),
428c2ecf20Sopenharmony_ci	[STIH407_USB2_PORT0_POWERDOWN] = STIH407_PDN_1(4),
438c2ecf20Sopenharmony_ci	[STIH407_PCIE1_POWERDOWN] = STIH407_PDN_1(3),
448c2ecf20Sopenharmony_ci	[STIH407_PCIE0_POWERDOWN] = STIH407_PDN_1(2),
458c2ecf20Sopenharmony_ci	[STIH407_SATA1_POWERDOWN] = STIH407_PDN_1(1),
468c2ecf20Sopenharmony_ci	[STIH407_SATA0_POWERDOWN] = STIH407_PDN_1(0),
478c2ecf20Sopenharmony_ci	[STIH407_ETH1_POWERDOWN] = STIH407_PDN_ETH(0, 2),
488c2ecf20Sopenharmony_ci};
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/* Reset Generator control 0/1 */
518c2ecf20Sopenharmony_ci#define SYSCFG_5128	0x200
528c2ecf20Sopenharmony_ci#define SYSCFG_5131	0x20c
538c2ecf20Sopenharmony_ci#define SYSCFG_5132	0x210
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#define LPM_SYSCFG_1	0x4	/* Softreset IRB & SBC UART */
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#define STIH407_SRST_CORE(_reg, _bit) \
588c2ecf20Sopenharmony_ci	_SYSCFG_RST_CH_NO_ACK(stih407_core, _reg, _bit)
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define STIH407_SRST_SBC(_reg, _bit) \
618c2ecf20Sopenharmony_ci	_SYSCFG_RST_CH_NO_ACK(stih407_sbc_reg, _reg, _bit)
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#define STIH407_SRST_LPM(_reg, _bit) \
648c2ecf20Sopenharmony_ci	_SYSCFG_RST_CH_NO_ACK(stih407_lpm, _reg, _bit)
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_cistatic const struct syscfg_reset_channel_data stih407_softresets[] = {
678c2ecf20Sopenharmony_ci	[STIH407_ETH1_SOFTRESET] = STIH407_SRST_SBC(SYSCFG_4002, 4),
688c2ecf20Sopenharmony_ci	[STIH407_MMC1_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 3),
698c2ecf20Sopenharmony_ci	[STIH407_USB2_PORT0_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 28),
708c2ecf20Sopenharmony_ci	[STIH407_USB2_PORT1_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 29),
718c2ecf20Sopenharmony_ci	[STIH407_PICOPHY_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 30),
728c2ecf20Sopenharmony_ci	[STIH407_IRB_SOFTRESET] = STIH407_SRST_LPM(LPM_SYSCFG_1, 6),
738c2ecf20Sopenharmony_ci	[STIH407_PCIE0_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 6),
748c2ecf20Sopenharmony_ci	[STIH407_PCIE1_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 15),
758c2ecf20Sopenharmony_ci	[STIH407_SATA0_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 7),
768c2ecf20Sopenharmony_ci	[STIH407_SATA1_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 16),
778c2ecf20Sopenharmony_ci	[STIH407_MIPHY0_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 4),
788c2ecf20Sopenharmony_ci	[STIH407_MIPHY1_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 13),
798c2ecf20Sopenharmony_ci	[STIH407_MIPHY2_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 22),
808c2ecf20Sopenharmony_ci	[STIH407_SATA0_PWR_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 5),
818c2ecf20Sopenharmony_ci	[STIH407_SATA1_PWR_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 14),
828c2ecf20Sopenharmony_ci	[STIH407_DELTA_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 3),
838c2ecf20Sopenharmony_ci	[STIH407_BLITTER_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 10),
848c2ecf20Sopenharmony_ci	[STIH407_HDTVOUT_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 11),
858c2ecf20Sopenharmony_ci	[STIH407_HDQVDP_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 12),
868c2ecf20Sopenharmony_ci	[STIH407_VDP_AUX_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 14),
878c2ecf20Sopenharmony_ci	[STIH407_COMPO_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 15),
888c2ecf20Sopenharmony_ci	[STIH407_HDMI_TX_PHY_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 21),
898c2ecf20Sopenharmony_ci	[STIH407_JPEG_DEC_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 23),
908c2ecf20Sopenharmony_ci	[STIH407_VP8_DEC_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 24),
918c2ecf20Sopenharmony_ci	[STIH407_GPU_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 30),
928c2ecf20Sopenharmony_ci	[STIH407_HVA_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 0),
938c2ecf20Sopenharmony_ci	[STIH407_ERAM_HVA_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 1),
948c2ecf20Sopenharmony_ci	[STIH407_LPM_SOFTRESET] = STIH407_SRST_SBC(SYSCFG_4002, 2),
958c2ecf20Sopenharmony_ci	[STIH407_KEYSCAN_SOFTRESET] = STIH407_SRST_LPM(LPM_SYSCFG_1, 8),
968c2ecf20Sopenharmony_ci	[STIH407_ST231_AUD_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 26),
978c2ecf20Sopenharmony_ci	[STIH407_ST231_DMU_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 27),
988c2ecf20Sopenharmony_ci	[STIH407_ST231_GP0_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 28),
998c2ecf20Sopenharmony_ci	[STIH407_ST231_GP1_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5128, 2),
1008c2ecf20Sopenharmony_ci};
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci/* PicoPHY reset/control */
1038c2ecf20Sopenharmony_ci#define SYSCFG_5061	0x0f4
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_cistatic const struct syscfg_reset_channel_data stih407_picophyresets[] = {
1068c2ecf20Sopenharmony_ci	[STIH407_PICOPHY0_RESET] = STIH407_SRST_CORE(SYSCFG_5061, 5),
1078c2ecf20Sopenharmony_ci	[STIH407_PICOPHY1_RESET] = STIH407_SRST_CORE(SYSCFG_5061, 6),
1088c2ecf20Sopenharmony_ci	[STIH407_PICOPHY2_RESET] = STIH407_SRST_CORE(SYSCFG_5061, 7),
1098c2ecf20Sopenharmony_ci};
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cistatic const struct syscfg_reset_controller_data stih407_powerdown_controller = {
1128c2ecf20Sopenharmony_ci	.wait_for_ack = true,
1138c2ecf20Sopenharmony_ci	.nr_channels = ARRAY_SIZE(stih407_powerdowns),
1148c2ecf20Sopenharmony_ci	.channels = stih407_powerdowns,
1158c2ecf20Sopenharmony_ci};
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_cistatic const struct syscfg_reset_controller_data stih407_softreset_controller = {
1188c2ecf20Sopenharmony_ci	.wait_for_ack = false,
1198c2ecf20Sopenharmony_ci	.active_low = true,
1208c2ecf20Sopenharmony_ci	.nr_channels = ARRAY_SIZE(stih407_softresets),
1218c2ecf20Sopenharmony_ci	.channels = stih407_softresets,
1228c2ecf20Sopenharmony_ci};
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistatic const struct syscfg_reset_controller_data stih407_picophyreset_controller = {
1258c2ecf20Sopenharmony_ci	.wait_for_ack = false,
1268c2ecf20Sopenharmony_ci	.nr_channels = ARRAY_SIZE(stih407_picophyresets),
1278c2ecf20Sopenharmony_ci	.channels = stih407_picophyresets,
1288c2ecf20Sopenharmony_ci};
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_cistatic const struct of_device_id stih407_reset_match[] = {
1318c2ecf20Sopenharmony_ci	{
1328c2ecf20Sopenharmony_ci		.compatible = "st,stih407-powerdown",
1338c2ecf20Sopenharmony_ci		.data = &stih407_powerdown_controller,
1348c2ecf20Sopenharmony_ci	},
1358c2ecf20Sopenharmony_ci	{
1368c2ecf20Sopenharmony_ci		.compatible = "st,stih407-softreset",
1378c2ecf20Sopenharmony_ci		.data = &stih407_softreset_controller,
1388c2ecf20Sopenharmony_ci	},
1398c2ecf20Sopenharmony_ci	{
1408c2ecf20Sopenharmony_ci		.compatible = "st,stih407-picophyreset",
1418c2ecf20Sopenharmony_ci		.data = &stih407_picophyreset_controller,
1428c2ecf20Sopenharmony_ci	},
1438c2ecf20Sopenharmony_ci	{ /* sentinel */ },
1448c2ecf20Sopenharmony_ci};
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_cistatic struct platform_driver stih407_reset_driver = {
1478c2ecf20Sopenharmony_ci	.probe = syscfg_reset_probe,
1488c2ecf20Sopenharmony_ci	.driver = {
1498c2ecf20Sopenharmony_ci		.name = "reset-stih407",
1508c2ecf20Sopenharmony_ci		.of_match_table = stih407_reset_match,
1518c2ecf20Sopenharmony_ci	},
1528c2ecf20Sopenharmony_ci};
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_cistatic int __init stih407_reset_init(void)
1558c2ecf20Sopenharmony_ci{
1568c2ecf20Sopenharmony_ci	return platform_driver_register(&stih407_reset_driver);
1578c2ecf20Sopenharmony_ci}
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ciarch_initcall(stih407_reset_init);
160