162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2014 STMicroelectronics (R&D) Limited 462306a36Sopenharmony_ci * Author: Giuseppe Cavallaro <peppe.cavallaro@st.com> 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci#include <linux/module.h> 762306a36Sopenharmony_ci#include <linux/of.h> 862306a36Sopenharmony_ci#include <linux/of_platform.h> 962306a36Sopenharmony_ci#include <linux/platform_device.h> 1062306a36Sopenharmony_ci#include <dt-bindings/reset/stih407-resets.h> 1162306a36Sopenharmony_ci#include "reset-syscfg.h" 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci/* STiH407 Peripheral powerdown definitions. */ 1462306a36Sopenharmony_cistatic const char stih407_core[] = "st,stih407-core-syscfg"; 1562306a36Sopenharmony_cistatic const char stih407_sbc_reg[] = "st,stih407-sbc-reg-syscfg"; 1662306a36Sopenharmony_cistatic const char stih407_lpm[] = "st,stih407-lpm-syscfg"; 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci#define STIH407_PDN_0(_bit) \ 1962306a36Sopenharmony_ci _SYSCFG_RST_CH(stih407_core, SYSCFG_5000, _bit, SYSSTAT_5500, _bit) 2062306a36Sopenharmony_ci#define STIH407_PDN_1(_bit) \ 2162306a36Sopenharmony_ci _SYSCFG_RST_CH(stih407_core, SYSCFG_5001, _bit, SYSSTAT_5501, _bit) 2262306a36Sopenharmony_ci#define STIH407_PDN_ETH(_bit, _stat) \ 2362306a36Sopenharmony_ci _SYSCFG_RST_CH(stih407_sbc_reg, SYSCFG_4032, _bit, SYSSTAT_4520, _stat) 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci/* Powerdown requests control 0 */ 2662306a36Sopenharmony_ci#define SYSCFG_5000 0x0 2762306a36Sopenharmony_ci#define SYSSTAT_5500 0x7d0 2862306a36Sopenharmony_ci/* Powerdown requests control 1 (High Speed Links) */ 2962306a36Sopenharmony_ci#define SYSCFG_5001 0x4 3062306a36Sopenharmony_ci#define SYSSTAT_5501 0x7d4 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci/* Ethernet powerdown/status/reset */ 3362306a36Sopenharmony_ci#define SYSCFG_4032 0x80 3462306a36Sopenharmony_ci#define SYSSTAT_4520 0x820 3562306a36Sopenharmony_ci#define SYSCFG_4002 0x8 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_cistatic const struct syscfg_reset_channel_data stih407_powerdowns[] = { 3862306a36Sopenharmony_ci [STIH407_EMISS_POWERDOWN] = STIH407_PDN_0(1), 3962306a36Sopenharmony_ci [STIH407_NAND_POWERDOWN] = STIH407_PDN_0(0), 4062306a36Sopenharmony_ci [STIH407_USB3_POWERDOWN] = STIH407_PDN_1(6), 4162306a36Sopenharmony_ci [STIH407_USB2_PORT1_POWERDOWN] = STIH407_PDN_1(5), 4262306a36Sopenharmony_ci [STIH407_USB2_PORT0_POWERDOWN] = STIH407_PDN_1(4), 4362306a36Sopenharmony_ci [STIH407_PCIE1_POWERDOWN] = STIH407_PDN_1(3), 4462306a36Sopenharmony_ci [STIH407_PCIE0_POWERDOWN] = STIH407_PDN_1(2), 4562306a36Sopenharmony_ci [STIH407_SATA1_POWERDOWN] = STIH407_PDN_1(1), 4662306a36Sopenharmony_ci [STIH407_SATA0_POWERDOWN] = STIH407_PDN_1(0), 4762306a36Sopenharmony_ci [STIH407_ETH1_POWERDOWN] = STIH407_PDN_ETH(0, 2), 4862306a36Sopenharmony_ci}; 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci/* Reset Generator control 0/1 */ 5162306a36Sopenharmony_ci#define SYSCFG_5128 0x200 5262306a36Sopenharmony_ci#define SYSCFG_5131 0x20c 5362306a36Sopenharmony_ci#define SYSCFG_5132 0x210 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci#define LPM_SYSCFG_1 0x4 /* Softreset IRB & SBC UART */ 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci#define STIH407_SRST_CORE(_reg, _bit) \ 5862306a36Sopenharmony_ci _SYSCFG_RST_CH_NO_ACK(stih407_core, _reg, _bit) 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci#define STIH407_SRST_SBC(_reg, _bit) \ 6162306a36Sopenharmony_ci _SYSCFG_RST_CH_NO_ACK(stih407_sbc_reg, _reg, _bit) 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci#define STIH407_SRST_LPM(_reg, _bit) \ 6462306a36Sopenharmony_ci _SYSCFG_RST_CH_NO_ACK(stih407_lpm, _reg, _bit) 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_cistatic const struct syscfg_reset_channel_data stih407_softresets[] = { 6762306a36Sopenharmony_ci [STIH407_ETH1_SOFTRESET] = STIH407_SRST_SBC(SYSCFG_4002, 4), 6862306a36Sopenharmony_ci [STIH407_MMC1_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 3), 6962306a36Sopenharmony_ci [STIH407_USB2_PORT0_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 28), 7062306a36Sopenharmony_ci [STIH407_USB2_PORT1_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 29), 7162306a36Sopenharmony_ci [STIH407_PICOPHY_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 30), 7262306a36Sopenharmony_ci [STIH407_IRB_SOFTRESET] = STIH407_SRST_LPM(LPM_SYSCFG_1, 6), 7362306a36Sopenharmony_ci [STIH407_PCIE0_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 6), 7462306a36Sopenharmony_ci [STIH407_PCIE1_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 15), 7562306a36Sopenharmony_ci [STIH407_SATA0_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 7), 7662306a36Sopenharmony_ci [STIH407_SATA1_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 16), 7762306a36Sopenharmony_ci [STIH407_MIPHY0_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 4), 7862306a36Sopenharmony_ci [STIH407_MIPHY1_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 13), 7962306a36Sopenharmony_ci [STIH407_MIPHY2_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 22), 8062306a36Sopenharmony_ci [STIH407_SATA0_PWR_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 5), 8162306a36Sopenharmony_ci [STIH407_SATA1_PWR_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 14), 8262306a36Sopenharmony_ci [STIH407_DELTA_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 3), 8362306a36Sopenharmony_ci [STIH407_BLITTER_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 10), 8462306a36Sopenharmony_ci [STIH407_HDTVOUT_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 11), 8562306a36Sopenharmony_ci [STIH407_HDQVDP_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 12), 8662306a36Sopenharmony_ci [STIH407_VDP_AUX_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 14), 8762306a36Sopenharmony_ci [STIH407_COMPO_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 15), 8862306a36Sopenharmony_ci [STIH407_HDMI_TX_PHY_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 21), 8962306a36Sopenharmony_ci [STIH407_JPEG_DEC_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 23), 9062306a36Sopenharmony_ci [STIH407_VP8_DEC_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 24), 9162306a36Sopenharmony_ci [STIH407_GPU_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 30), 9262306a36Sopenharmony_ci [STIH407_HVA_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 0), 9362306a36Sopenharmony_ci [STIH407_ERAM_HVA_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5132, 1), 9462306a36Sopenharmony_ci [STIH407_LPM_SOFTRESET] = STIH407_SRST_SBC(SYSCFG_4002, 2), 9562306a36Sopenharmony_ci [STIH407_KEYSCAN_SOFTRESET] = STIH407_SRST_LPM(LPM_SYSCFG_1, 8), 9662306a36Sopenharmony_ci [STIH407_ST231_AUD_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 26), 9762306a36Sopenharmony_ci [STIH407_ST231_DMU_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 27), 9862306a36Sopenharmony_ci [STIH407_ST231_GP0_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5131, 28), 9962306a36Sopenharmony_ci [STIH407_ST231_GP1_SOFTRESET] = STIH407_SRST_CORE(SYSCFG_5128, 2), 10062306a36Sopenharmony_ci}; 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ci/* PicoPHY reset/control */ 10362306a36Sopenharmony_ci#define SYSCFG_5061 0x0f4 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_cistatic const struct syscfg_reset_channel_data stih407_picophyresets[] = { 10662306a36Sopenharmony_ci [STIH407_PICOPHY0_RESET] = STIH407_SRST_CORE(SYSCFG_5061, 5), 10762306a36Sopenharmony_ci [STIH407_PICOPHY1_RESET] = STIH407_SRST_CORE(SYSCFG_5061, 6), 10862306a36Sopenharmony_ci [STIH407_PICOPHY2_RESET] = STIH407_SRST_CORE(SYSCFG_5061, 7), 10962306a36Sopenharmony_ci}; 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_cistatic const struct syscfg_reset_controller_data stih407_powerdown_controller = { 11262306a36Sopenharmony_ci .wait_for_ack = true, 11362306a36Sopenharmony_ci .nr_channels = ARRAY_SIZE(stih407_powerdowns), 11462306a36Sopenharmony_ci .channels = stih407_powerdowns, 11562306a36Sopenharmony_ci}; 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_cistatic const struct syscfg_reset_controller_data stih407_softreset_controller = { 11862306a36Sopenharmony_ci .wait_for_ack = false, 11962306a36Sopenharmony_ci .active_low = true, 12062306a36Sopenharmony_ci .nr_channels = ARRAY_SIZE(stih407_softresets), 12162306a36Sopenharmony_ci .channels = stih407_softresets, 12262306a36Sopenharmony_ci}; 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_cistatic const struct syscfg_reset_controller_data stih407_picophyreset_controller = { 12562306a36Sopenharmony_ci .wait_for_ack = false, 12662306a36Sopenharmony_ci .nr_channels = ARRAY_SIZE(stih407_picophyresets), 12762306a36Sopenharmony_ci .channels = stih407_picophyresets, 12862306a36Sopenharmony_ci}; 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_cistatic const struct of_device_id stih407_reset_match[] = { 13162306a36Sopenharmony_ci { 13262306a36Sopenharmony_ci .compatible = "st,stih407-powerdown", 13362306a36Sopenharmony_ci .data = &stih407_powerdown_controller, 13462306a36Sopenharmony_ci }, 13562306a36Sopenharmony_ci { 13662306a36Sopenharmony_ci .compatible = "st,stih407-softreset", 13762306a36Sopenharmony_ci .data = &stih407_softreset_controller, 13862306a36Sopenharmony_ci }, 13962306a36Sopenharmony_ci { 14062306a36Sopenharmony_ci .compatible = "st,stih407-picophyreset", 14162306a36Sopenharmony_ci .data = &stih407_picophyreset_controller, 14262306a36Sopenharmony_ci }, 14362306a36Sopenharmony_ci { /* sentinel */ }, 14462306a36Sopenharmony_ci}; 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_cistatic struct platform_driver stih407_reset_driver = { 14762306a36Sopenharmony_ci .probe = syscfg_reset_probe, 14862306a36Sopenharmony_ci .driver = { 14962306a36Sopenharmony_ci .name = "reset-stih407", 15062306a36Sopenharmony_ci .of_match_table = stih407_reset_match, 15162306a36Sopenharmony_ci }, 15262306a36Sopenharmony_ci}; 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_cistatic int __init stih407_reset_init(void) 15562306a36Sopenharmony_ci{ 15662306a36Sopenharmony_ci return platform_driver_register(&stih407_reset_driver); 15762306a36Sopenharmony_ci} 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ciarch_initcall(stih407_reset_init); 160