From patchwork Wed Nov 29 05:43:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Tai X-Patchwork-Id: 748812 Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D398D19B7; Tue, 28 Nov 2023 21:44:41 -0800 (PST) X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 3AT5iOiX52554686, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36506.realtek.com.tw[172.21.6.27]) by rtits2.realtek.com.tw (8.15.2/2.95/5.92) with ESMTPS id 3AT5iOiX52554686 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Nov 2023 13:44:24 +0800 Received: from RTEXMBS03.realtek.com.tw (172.21.6.96) by RTEXH36506.realtek.com.tw (172.21.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.17; Wed, 29 Nov 2023 13:44:24 +0800 Received: from james-bs01.realtek.com.tw (172.21.190.247) by RTEXMBS03.realtek.com.tw (172.21.6.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 29 Nov 2023 13:44:23 +0800 From: James Tai To: Thomas Gleixner , Marc Zyngier , "Rob Herring" , Krzysztof Kozlowski , Conor Dooley , James Tai CC: , , "kernel test robot" Subject: [PATCH v3 1/6] dt-bindings: interrupt-controller: Add support for Realtek DHC SoCs Date: Wed, 29 Nov 2023 13:43:34 +0800 Message-ID: <20231129054339.3054202-2-james.tai@realtek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129054339.3054202-1-james.tai@realtek.com> References: <20231129054339.3054202-1-james.tai@realtek.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: RTEXH36506.realtek.com.tw (172.21.6.27) To RTEXMBS03.realtek.com.tw (172.21.6.96) X-KSE-ServerInfo: RTEXMBS03.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback Add the YAML documentation for Realtek DHC (Digital Home Center) SoCs. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202311180921.ayKhiFHL-lkp@intel.com/ CC: Thomas Gleixner CC: Marc Zyngier CC: Rob Herring CC: Krzysztof Kozlowski CC: Conor Dooley CC: linux-kernel@vger.kernel.org CC: devicetree@vger.kernel.org Signed-off-by: James Tai --- v2 to v3 change: - Retested the bindings using the new version of the dtschema - Fixed the order of property items - Removed redundant files and replaced them with 'realtek,intc.yaml' - Replaced 'interrupts-extended' with 'interrupts' - Added a description for 'interrupts' - Reduced the example code v1 to v2 change: - Tested the bindings using 'make dt_binding_check' - Fixed code style issues .../interrupt-controller/realtek,intc.yaml | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/realtek,intc.yaml diff --git a/Documentation/devicetree/bindings/interrupt-controller/realtek,intc.yaml b/Documentation/devicetree/bindings/interrupt-controller/realtek,intc.yaml new file mode 100644 index 000000000000..3aa863b1549d --- /dev/null +++ b/Documentation/devicetree/bindings/interrupt-controller/realtek,intc.yaml @@ -0,0 +1,76 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/interrupt-controller/realtek,intc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Realtek DHC SoCs Interrupt Controller + +maintainers: + - James Tai + +description: + This interrupt controller is a component of Realtek DHC (Digital Home Center) + SoCs and is designed to receive interrupts from peripheral devices. + + Each DHC SoC has two sets of interrupt controllers, each capable of + handling up to 32 interrupts. + +allOf: + - $ref: /schemas/interrupt-controller.yaml# + +properties: + compatible: + enum: + - realtek,rtd1319-intc-iso + - realtek,rtd1319-intc-misc + - realtek,rtd1319d-intc-iso + - realtek,rtd1319d-intc-misc + - realtek,rtd1325-intc-iso + - realtek,rtd1325-intc-misc + - realtek,rtd1619b-intc-iso + - realtek,rtd1619b-intc-misc + + reg: + maxItems: 1 + + interrupt-controller: true + + '#interrupt-cells': + const: 1 + + '#address-cells': + const: 0 + + interrupts: + description: | + Contains the GIC SPI IRQs mapped to the external interrupt lines. + minItems: 2 + maxItems: 4 + +required: + - compatible + - reg + - interrupt-controller + - '#interrupt-cells' + - '#address-cells' + - interrupts + +additionalProperties: false + +examples: + - | + #include + #include + + realtek_iso_intc: interrupt-controller@40 { + compatible = "realtek,rtd1319-intc-iso"; + reg = <0x00 0x40>; + interrupt-parent = <&gic>; + interrupts = , + ; + interrupt-controller; + #address-cells = <0>; + #interrupt-cells = <1>; + }; +... From patchwork Wed Nov 29 05:43:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Tai X-Patchwork-Id: 748811 Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E82019AB; Tue, 28 Nov 2023 21:44:49 -0800 (PST) X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 3AT5iYvsD2554701, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36506.realtek.com.tw[172.21.6.27]) by rtits2.realtek.com.tw (8.15.2/2.95/5.92) with ESMTPS id 3AT5iYvsD2554701 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Nov 2023 13:44:34 +0800 Received: from RTEXMBS03.realtek.com.tw (172.21.6.96) by RTEXH36506.realtek.com.tw (172.21.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.17; Wed, 29 Nov 2023 13:44:35 +0800 Received: from james-bs01.realtek.com.tw (172.21.190.247) by RTEXMBS03.realtek.com.tw (172.21.6.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 29 Nov 2023 13:44:34 +0800 From: James Tai To: Thomas Gleixner , Marc Zyngier , "Rob Herring" , Krzysztof Kozlowski , Conor Dooley , James Tai CC: , , "kernel test robot" Subject: [PATCH v3 3/6] irqchip: Introduce RTD1319 support using the Realtek common interrupt controller driver Date: Wed, 29 Nov 2023 13:43:36 +0800 Message-ID: <20231129054339.3054202-4-james.tai@realtek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129054339.3054202-1-james.tai@realtek.com> References: <20231129054339.3054202-1-james.tai@realtek.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: RTEXH36506.realtek.com.tw (172.21.6.27) To RTEXMBS03.realtek.com.tw (172.21.6.96) X-KSE-ServerInfo: RTEXMBS03.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback Add support for the RTD1319 platform. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202311061208.hJmxGqym-lkp@intel.com/ CC: Thomas Gleixner CC: Marc Zyngier CC: linux-kernel@vger.kernel.org Signed-off-by: James Tai --- v2 to v3 change: - Unchanged v1 to v2 change: - Resolved kernel test robot build warnings - Replaced magic number with macro - Fixed code style issues drivers/irqchip/Kconfig | 6 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-realtek-rtd1319.c | 218 ++++++++++++++++++++++++++ 3 files changed, 225 insertions(+) create mode 100644 drivers/irqchip/irq-realtek-rtd1319.c diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig index 267c3429b48d..05856ce885fa 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -222,6 +222,12 @@ config REALTEK_DHC_INTC tristate select IRQ_DOMAIN +config REALTEK_RTD1319_INTC + tristate "Realtek RTD1319 interrupt controller" + select REALTEK_DHC_INTC + help + Support for Realtek RTD1319 Interrupt Controller. + config RENESAS_INTC_IRQPIN bool "Renesas INTC External IRQ Pin Support" if COMPILE_TEST select IRQ_DOMAIN diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile index f6774af7fde2..6a2650b0a924 100644 --- a/drivers/irqchip/Makefile +++ b/drivers/irqchip/Makefile @@ -48,6 +48,7 @@ obj-$(CONFIG_IXP4XX_IRQ) += irq-ixp4xx.o obj-$(CONFIG_JCORE_AIC) += irq-jcore-aic.o obj-$(CONFIG_RDA_INTC) += irq-rda-intc.o obj-$(CONFIG_REALTEK_DHC_INTC) += irq-realtek-intc-common.o +obj-$(CONFIG_REALTEK_RTD1319_INTC) += irq-realtek-rtd1319.o obj-$(CONFIG_RENESAS_INTC_IRQPIN) += irq-renesas-intc-irqpin.o obj-$(CONFIG_RENESAS_IRQC) += irq-renesas-irqc.o obj-$(CONFIG_RENESAS_RZA1_IRQC) += irq-renesas-rza1.o diff --git a/drivers/irqchip/irq-realtek-rtd1319.c b/drivers/irqchip/irq-realtek-rtd1319.c new file mode 100644 index 000000000000..23c13c218b04 --- /dev/null +++ b/drivers/irqchip/irq-realtek-rtd1319.c @@ -0,0 +1,218 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Realtek RTD1319 interrupt controller driver + * + * Copyright (c) 2023 Realtek Semiconductor Corporation + */ + +#include +#include +#include +#include +#include + +#include "irq-realtek-intc-common.h" + +#define ISO_NORMAL_MASK 0xffffcffe +#define ISO_RTC_MASK 0x00003001 +#define MISC_NMI_WDT_MASK 0x00000004 +#define MISC_NORMAL_MASK 0xffffc0d2 +#define MISC_UART1_MASK 0x00000028 +#define MISC_UART2_MASK 0x00002100 + +#define ISO_ISR_EN_OFFSET 0x40 +#define ISO_ISR_OFFSET 0 +#define ISO_ISR_UMSK_OFFSET 0x4 +#define MISC_ISR_EN_OFFSET 0x80 +#define MISC_ISR_OFFSET 0xc +#define MISC_ISR_UMSK_OFFSET 0x8 + +enum rtd1319_iso_isr_bits { + RTD1319_ISO_ISR_TC3_SHIFT = 1, + RTD1319_ISO_ISR_UR0_SHIFT = 2, + RTD1319_ISO_ISR_LSADC0_SHIFT = 3, + RTD1319_ISO_ISR_IRDA_SHIFT = 5, + RTD1319_ISO_ISR_SPI1_SHIFT = 6, + RTD1319_ISO_ISR_WDOG_NMI_SHIFT = 7, + RTD1319_ISO_ISR_I2C0_SHIFT = 8, + RTD1319_ISO_ISR_TC4_SHIFT = 9, + RTD1319_ISO_ISR_TC7_SHIFT = 10, + RTD1319_ISO_ISR_I2C1_SHIFT = 11, + RTD1319_ISO_ISR_RTC_HSEC_SHIFT = 12, + RTD1319_ISO_ISR_RTC_ALARM_SHIFT = 13, + RTD1319_ISO_ISR_GPIOA_SHIFT = 19, + RTD1319_ISO_ISR_GPIODA_SHIFT = 20, + RTD1319_ISO_ISR_ISO_MISC_SHIFT = 21, + RTD1319_ISO_ISR_CBUS_SHIFT = 22, + RTD1319_ISO_ISR_ETN_SHIFT = 23, + RTD1319_ISO_ISR_USB_HOST_SHIFT = 24, + RTD1319_ISO_ISR_USB_U3_DRD_SHIFT = 25, + RTD1319_ISO_ISR_USB_U2_DRD_SHIFT = 26, + RTD1319_ISO_ISR_PORB_HV_SHIFT = 28, + RTD1319_ISO_ISR_PORB_DV_SHIFT = 29, + RTD1319_ISO_ISR_PORB_AV_SHIFT = 30, + RTD1319_ISO_ISR_I2C1_REQ_SHIFT = 31, +}; + +static const u32 rtd1319_iso_isr_to_scpu_int_en_mask[32] = { + [RTD1319_ISO_ISR_SPI1_SHIFT] = BIT(1), + [RTD1319_ISO_ISR_UR0_SHIFT] = BIT(2), + [RTD1319_ISO_ISR_LSADC0_SHIFT] = BIT(3), + [RTD1319_ISO_ISR_IRDA_SHIFT] = BIT(5), + [RTD1319_ISO_ISR_I2C0_SHIFT] = BIT(8), + [RTD1319_ISO_ISR_I2C1_SHIFT] = BIT(11), + [RTD1319_ISO_ISR_RTC_HSEC_SHIFT] = BIT(12), + [RTD1319_ISO_ISR_RTC_ALARM_SHIFT] = BIT(13), + [RTD1319_ISO_ISR_GPIOA_SHIFT] = BIT(19), + [RTD1319_ISO_ISR_GPIODA_SHIFT] = BIT(20), + [RTD1319_ISO_ISR_PORB_HV_SHIFT] = BIT(28), + [RTD1319_ISO_ISR_PORB_DV_SHIFT] = BIT(29), + [RTD1319_ISO_ISR_PORB_AV_SHIFT] = BIT(30), + [RTD1319_ISO_ISR_I2C1_REQ_SHIFT] = BIT(31), +}; + +enum rtd1319_misc_isr_bits { + RTD1319_ISR_WDOG_NMI_SHIFT = 2, + RTD1319_ISR_UR1_SHIFT = 3, + RTD1319_ISR_TC5_SHIFT = 4, + RTD1319_ISR_UR1_TO_SHIFT = 5, + RTD1319_ISR_TC0_SHIFT = 6, + RTD1319_ISR_TC1_SHIFT = 7, + RTD1319_ISR_UR2_SHIFT = 8, + RTD1319_ISR_RTC_HSEC_SHIFT = 9, + RTD1319_ISR_RTC_MIN_SHIFT = 10, + RTD1319_ISR_RTC_HOUR_SHIFT = 11, + RTD1319_ISR_RTC_DATE_SHIFT = 12, + RTD1319_ISR_UR2_TO_SHIFT = 13, + RTD1319_ISR_I2C5_SHIFT = 14, + RTD1319_ISR_I2C3_SHIFT = 23, + RTD1319_ISR_SC0_SHIFT = 24, + RTD1319_ISR_SC1_SHIFT = 25, + RTD1319_ISR_SPI_SHIFT = 27, + RTD1319_ISR_FAN_SHIFT = 29, +}; + +static const u32 rtd1319_misc_isr_to_scpu_int_en_mask[32] = { + [RTD1319_ISR_UR1_SHIFT] = BIT(3), + [RTD1319_ISR_UR1_TO_SHIFT] = BIT(5), + [RTD1319_ISR_UR2_TO_SHIFT] = BIT(6), + [RTD1319_ISR_UR2_SHIFT] = BIT(7), + [RTD1319_ISR_RTC_MIN_SHIFT] = BIT(10), + [RTD1319_ISR_RTC_HOUR_SHIFT] = BIT(11), + [RTD1319_ISR_RTC_DATE_SHIFT] = BIT(12), + [RTD1319_ISR_I2C5_SHIFT] = BIT(14), + [RTD1319_ISR_SC0_SHIFT] = BIT(24), + [RTD1319_ISR_SC1_SHIFT] = BIT(25), + [RTD1319_ISR_SPI_SHIFT] = BIT(27), + [RTD1319_ISR_I2C3_SHIFT] = BIT(28), + [RTD1319_ISR_FAN_SHIFT] = BIT(29), + [RTD1319_ISR_WDOG_NMI_SHIFT] = IRQ_ALWAYS_ENABLED, +}; + +static struct realtek_intc_subset_cfg rtd1319_intc_iso_cfgs[] = { + { ISO_NORMAL_MASK, }, + { ISO_RTC_MASK, }, +}; + +static const struct realtek_intc_info rtd1319_intc_iso_info = { + .isr_offset = ISO_ISR_OFFSET, + .umsk_isr_offset = ISO_ISR_UMSK_OFFSET, + .scpu_int_en_offset = ISO_ISR_EN_OFFSET, + .isr_to_scpu_int_en_mask = rtd1319_iso_isr_to_scpu_int_en_mask, + .cfg = rtd1319_intc_iso_cfgs, + .cfg_num = ARRAY_SIZE(rtd1319_intc_iso_cfgs), +}; + +static struct realtek_intc_subset_cfg rtd1319_intc_misc_cfgs[] = { + { MISC_NORMAL_MASK, }, + { MISC_NMI_WDT_MASK, }, + { MISC_UART1_MASK, }, + { MISC_UART2_MASK, }, +}; + +static const struct realtek_intc_info rtd1319_intc_misc_info = { + .isr_offset = MISC_ISR_OFFSET, + .umsk_isr_offset = MISC_ISR_UMSK_OFFSET, + .scpu_int_en_offset = MISC_ISR_EN_OFFSET, + .isr_to_scpu_int_en_mask = rtd1319_misc_isr_to_scpu_int_en_mask, + .cfg = rtd1319_intc_misc_cfgs, + .cfg_num = ARRAY_SIZE(rtd1319_intc_misc_cfgs), +}; + +static const struct of_device_id realtek_intc_rtd1319_dt_matches[] = { + { + .compatible = "realtek,rtd1319-intc-iso", + .data = &rtd1319_intc_iso_info, + }, { + .compatible = "realtek,rtd1319-intc-misc", + .data = &rtd1319_intc_misc_info, + }, + { /* sentinel */ } +}; + +static int realtek_intc_rtd1319_suspend(struct device *dev) +{ + struct realtek_intc_data *data = dev_get_drvdata(dev); + const struct realtek_intc_info *info = data->info; + + data->saved_en = readl(data->base + info->scpu_int_en_offset); + + writel(DISABLE_INTC, data->base + info->scpu_int_en_offset); + writel(CLEAN_INTC_STATUS, data->base + info->umsk_isr_offset); + writel(CLEAN_INTC_STATUS, data->base + info->isr_offset); + + return 0; +} + +static int realtek_intc_rtd1319_resume(struct device *dev) +{ + struct realtek_intc_data *data = dev_get_drvdata(dev); + const struct realtek_intc_info *info = data->info; + + writel(CLEAN_INTC_STATUS, data->base + info->umsk_isr_offset); + writel(CLEAN_INTC_STATUS, data->base + info->isr_offset); + writel(data->saved_en, data->base + info->scpu_int_en_offset); + + return 0; +} + +static const struct dev_pm_ops realtek_intc_rtd1319_pm_ops = { + .suspend_noirq = realtek_intc_rtd1319_suspend, + .resume_noirq = realtek_intc_rtd1319_resume, +}; + +static int rtd1319_intc_probe(struct platform_device *pdev) +{ + const struct realtek_intc_info *info; + + info = of_device_get_match_data(&pdev->dev); + if (!info) + return -EINVAL; + + return realtek_intc_probe(pdev, info); +} + +static struct platform_driver realtek_intc_rtd1319_driver = { + .probe = rtd1319_intc_probe, + .driver = { + .name = "realtek_intc_rtd1319", + .of_match_table = realtek_intc_rtd1319_dt_matches, + .suppress_bind_attrs = true, + .pm = &realtek_intc_rtd1319_pm_ops, + }, +}; + +static int __init realtek_intc_rtd1319_init(void) +{ + return platform_driver_register(&realtek_intc_rtd1319_driver); +} +core_initcall(realtek_intc_rtd1319_init); + +static void __exit realtek_intc_rtd1319_exit(void) +{ + platform_driver_unregister(&realtek_intc_rtd1319_driver); +} +module_exit(realtek_intc_rtd1319_exit); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Realtek RTD1319 Interrupt Controller Driver"); From patchwork Wed Nov 29 05:43:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Tai X-Patchwork-Id: 748810 Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F3A31BCE; Tue, 28 Nov 2023 21:44:51 -0800 (PST) X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 3AT5icP432554707, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36506.realtek.com.tw[172.21.6.27]) by rtits2.realtek.com.tw (8.15.2/2.95/5.92) with ESMTPS id 3AT5icP432554707 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Nov 2023 13:44:38 +0800 Received: from RTEXMBS03.realtek.com.tw (172.21.6.96) by RTEXH36506.realtek.com.tw (172.21.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.17; Wed, 29 Nov 2023 13:44:39 +0800 Received: from james-bs01.realtek.com.tw (172.21.190.247) by RTEXMBS03.realtek.com.tw (172.21.6.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 29 Nov 2023 13:44:38 +0800 From: James Tai To: Thomas Gleixner , Marc Zyngier , "Rob Herring" , Krzysztof Kozlowski , Conor Dooley , James Tai CC: , , "kernel test robot" Subject: [PATCH v3 5/6] irqchip: Introduce RTD1325 support using the Realtek common interrupt controller driver Date: Wed, 29 Nov 2023 13:43:38 +0800 Message-ID: <20231129054339.3054202-6-james.tai@realtek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129054339.3054202-1-james.tai@realtek.com> References: <20231129054339.3054202-1-james.tai@realtek.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: RTEXH36506.realtek.com.tw (172.21.6.27) To RTEXMBS03.realtek.com.tw (172.21.6.96) X-KSE-ServerInfo: RTEXMBS03.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback Add support for the RTD1325 platform. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202311061408.qjl1jfVl-lkp@intel.com/ CC: Thomas Gleixner CC: Marc Zyngier CC: linux-kernel@vger.kernel.org Signed-off-by: James Tai --- v2 to v3 change: - Unchanged v1 to v2 change: - Resolved kernel test robot build warnings - Replaced magic number with macro - Fixed code style issues drivers/irqchip/Kconfig | 6 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-realtek-rtd1325.c | 227 ++++++++++++++++++++++++++ 3 files changed, 234 insertions(+) create mode 100644 drivers/irqchip/irq-realtek-rtd1325.c diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig index c6552c513442..65e2d67d1505 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -234,6 +234,12 @@ config REALTEK_RTD1319D_INTC help Support for Realtek RTD1319D Interrupt Controller. +config REALTEK_RTD1325_INTC + tristate "Realtek RTD1325 interrupt controller" + select REALTEK_DHC_INTC + help + Support for Realtek RTD1325 Interrupt Controller. + config RENESAS_INTC_IRQPIN bool "Renesas INTC External IRQ Pin Support" if COMPILE_TEST select IRQ_DOMAIN diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile index c8adaed4c1b2..eaa12928d60b 100644 --- a/drivers/irqchip/Makefile +++ b/drivers/irqchip/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_RDA_INTC) += irq-rda-intc.o obj-$(CONFIG_REALTEK_DHC_INTC) += irq-realtek-intc-common.o obj-$(CONFIG_REALTEK_RTD1319_INTC) += irq-realtek-rtd1319.o obj-$(CONFIG_REALTEK_RTD1319D_INTC) += irq-realtek-rtd1319d.o +obj-$(CONFIG_REALTEK_RTD1325_INTC) += irq-realtek-rtd1325.o obj-$(CONFIG_RENESAS_INTC_IRQPIN) += irq-renesas-intc-irqpin.o obj-$(CONFIG_RENESAS_IRQC) += irq-renesas-irqc.o obj-$(CONFIG_RENESAS_RZA1_IRQC) += irq-renesas-rza1.o diff --git a/drivers/irqchip/irq-realtek-rtd1325.c b/drivers/irqchip/irq-realtek-rtd1325.c new file mode 100644 index 000000000000..7ff164795634 --- /dev/null +++ b/drivers/irqchip/irq-realtek-rtd1325.c @@ -0,0 +1,227 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Realtek RTD1325 interrupt controller driver + * + * Copyright (c) 2023 Realtek Semiconductor Corporation + */ + +#include +#include +#include +#include +#include + +#include "irq-realtek-intc-common.h" + +#define ISO_NMI_WDT_MASK 0x08008090 +#define ISO_NORMAL_MASK 0xf7ff7f6e +#define MISC_NORMAL_MASK 0xffe0ded6 +#define MISC_UART1_MASK 0x00000028 +#define MISC_UART2_MASK 0x00002100 + +#define ISO_ISR_EN_OFFSET 0x40 +#define ISO_ISR_OFFSET 0 +#define ISO_ISR_UMSK_OFFSET 0x4 +#define MISC_ISR_EN_OFFSET 0x80 +#define MISC_ISR_OFFSET 0xc +#define MISC_ISR_UMSK_OFFSET 0x8 + +enum rtd1325_iso_isr_bits { + RTD1325_ISO_ISR_TC3_SHIFT = 1, + RTD1325_ISO_ISR_UR0_SHIFT = 2, + RTD1325_ISO_ISR_LSADC0_SHIFT = 3, + RTD1325_ISO_ISR_WDOG1_NMI_SHIFT = 4, + RTD1325_ISO_ISR_IRDA_SHIFT = 5, + RTD1325_ISO_ISR_SPI1_SHIFT = 6, + RTD1325_ISO_ISR_WDOG2_NMI_SHIFT = 7, + RTD1325_ISO_ISR_I2C0_SHIFT = 8, + RTD1325_ISO_ISR_TC4_SHIFT = 9, + RTD1325_ISO_ISR_TC7_SHIFT = 10, + RTD1325_ISO_ISR_I2C1_SHIFT = 11, + RTD1325_ISO_ISR_HIFI_WAKEUP_SHIFT = 14, + RTD1325_ISO_ISR_WDOG4_NMI_SHIFT = 15, + RTD1325_ISO_ISR_TC8_SHIFT = 16, + RTD1325_ISO_ISR_VFD_SHIFT = 17, + RTD1325_ISO_ISR_VTC_SHIFT = 18, + RTD1325_ISO_ISR_GPIOA_SHIFT = 19, + RTD1325_ISO_ISR_GPIODA_SHIFT = 20, + RTD1325_ISO_ISR_ISO_MISC_SHIFT = 21, + RTD1325_ISO_ISR_CBUS_SHIFT = 22, + RTD1325_ISO_ISR_ETN_SHIFT = 23, + RTD1325_ISO_ISR_USB_HOST_SHIFT = 24, + RTD1325_ISO_ISR_USB_U3_DRD_SHIFT = 25, + RTD1325_ISO_ISR_USB_U2_DRD_SHIFT = 26, + RTD1325_ISO_ISR_WDOG3_NMI_SHIFT = 27, + RTD1325_ISO_ISR_PORB_HV_CEN_SHIFT = 28, + RTD1325_ISO_ISR_PORB_DV_CEN_SHIFT = 29, + RTD1325_ISO_ISR_PORB_AV_CEN_SHIFT = 30, + RTD1325_ISO_ISR_I2C1_REQ_SHIFT = 31, +}; + +static const u32 rtd1325_iso_isr_to_scpu_int_en_mask[32] = { + [RTD1325_ISO_ISR_SPI1_SHIFT] = BIT(1), + [RTD1325_ISO_ISR_UR0_SHIFT] = BIT(2), + [RTD1325_ISO_ISR_LSADC0_SHIFT] = BIT(3), + [RTD1325_ISO_ISR_IRDA_SHIFT] = BIT(5), + [RTD1325_ISO_ISR_I2C0_SHIFT] = BIT(8), + [RTD1325_ISO_ISR_I2C1_SHIFT] = BIT(11), + [RTD1325_ISO_ISR_VFD_SHIFT] = BIT(17), + [RTD1325_ISO_ISR_GPIOA_SHIFT] = BIT(19), + [RTD1325_ISO_ISR_GPIODA_SHIFT] = BIT(20), + [RTD1325_ISO_ISR_PORB_HV_CEN_SHIFT] = BIT(28), + [RTD1325_ISO_ISR_PORB_DV_CEN_SHIFT] = BIT(29), + [RTD1325_ISO_ISR_PORB_AV_CEN_SHIFT] = BIT(30), + [RTD1325_ISO_ISR_I2C1_REQ_SHIFT] = BIT(31), + [RTD1325_ISO_ISR_WDOG1_NMI_SHIFT] = IRQ_ALWAYS_ENABLED, + [RTD1325_ISO_ISR_WDOG2_NMI_SHIFT] = IRQ_ALWAYS_ENABLED, + [RTD1325_ISO_ISR_WDOG3_NMI_SHIFT] = IRQ_ALWAYS_ENABLED, + [RTD1325_ISO_ISR_WDOG4_NMI_SHIFT] = IRQ_ALWAYS_ENABLED, +}; + +enum rtd1325_misc_isr_bits { + RTD1325_ISR_UR1_SHIFT = 3, + RTD1325_ISR_TC5_SHIFT = 4, + RTD1325_ISR_UR1_TO_SHIFT = 5, + RTD1325_ISR_TC0_SHIFT = 6, + RTD1325_ISR_TC1_SHIFT = 7, + RTD1325_ISR_UR2_SHIFT = 8, + RTD1325_ISR_UR2_TO_SHIFT = 13, + RTD1325_ISR_I2C5_SHIFT = 14, + RTD1325_ISR_I2C4_SHIFT = 15, + RTD1325_ISR_DRTC_HSEC_SHIFT = 16, + RTD1325_ISR_DRTC_MIN_SHIFT = 17, + RTD1325_ISR_DRTC_HOUR_SHIFT = 18, + RTD1325_ISR_DRTC_DATE_SHIFT = 19, + RTD1325_ISR_DRTC_ALARM_SHIFT = 20, + RTD1325_ISR_I2C3_SHIFT = 23, + RTD1325_ISR_SC0_SHIFT = 24, + RTD1325_ISR_SC1_SHIFT = 25, + RTD1325_ISR_SPI_SHIFT = 27, + RTD1325_ISR_FAN_SHIFT = 29, +}; + +static const u32 rtd1325_misc_isr_to_scpu_int_en_mask[32] = { + [RTD1325_ISR_UR1_SHIFT] = BIT(3), + [RTD1325_ISR_UR1_TO_SHIFT] = BIT(5), + [RTD1325_ISR_UR2_TO_SHIFT] = BIT(6), + [RTD1325_ISR_UR2_SHIFT] = BIT(7), + [RTD1325_ISR_I2C5_SHIFT] = BIT(14), + [RTD1325_ISR_I2C4_SHIFT] = BIT(15), + [RTD1325_ISR_DRTC_HSEC_SHIFT] = BIT(16), + [RTD1325_ISR_DRTC_MIN_SHIFT] = BIT(17), + [RTD1325_ISR_DRTC_HOUR_SHIFT] = BIT(18), + [RTD1325_ISR_DRTC_DATE_SHIFT] = BIT(19), + [RTD1325_ISR_DRTC_ALARM_SHIFT] = BIT(20), + [RTD1325_ISR_SC0_SHIFT] = BIT(24), + [RTD1325_ISR_SC1_SHIFT] = BIT(25), + [RTD1325_ISR_SPI_SHIFT] = BIT(27), + [RTD1325_ISR_I2C3_SHIFT] = BIT(28), + [RTD1325_ISR_FAN_SHIFT] = BIT(29), +}; + +static struct realtek_intc_subset_cfg rtd1325_intc_iso_cfgs[] = { + { ISO_NORMAL_MASK, }, + { ISO_NMI_WDT_MASK, }, +}; + +static const struct realtek_intc_info rtd1325_intc_iso_info = { + .isr_offset = ISO_ISR_OFFSET, + .umsk_isr_offset = ISO_ISR_UMSK_OFFSET, + .scpu_int_en_offset = ISO_ISR_EN_OFFSET, + .isr_to_scpu_int_en_mask = rtd1325_iso_isr_to_scpu_int_en_mask, + .cfg = rtd1325_intc_iso_cfgs, + .cfg_num = ARRAY_SIZE(rtd1325_intc_iso_cfgs), +}; + +static struct realtek_intc_subset_cfg rtd1325_intc_misc_cfgs[] = { + { MISC_NORMAL_MASK, }, + { MISC_UART1_MASK, }, + { MISC_UART2_MASK, }, +}; + +static const struct realtek_intc_info rtd1325_intc_misc_info = { + .isr_offset = MISC_ISR_OFFSET, + .umsk_isr_offset = MISC_ISR_UMSK_OFFSET, + .scpu_int_en_offset = MISC_ISR_EN_OFFSET, + .isr_to_scpu_int_en_mask = rtd1325_misc_isr_to_scpu_int_en_mask, + .cfg = rtd1325_intc_misc_cfgs, + .cfg_num = ARRAY_SIZE(rtd1325_intc_misc_cfgs), +}; + +static const struct of_device_id realtek_intc_rtd1325_dt_matches[] = { + { + .compatible = "realtek,rtd1325-intc-iso", + .data = &rtd1325_intc_iso_info, + }, { + .compatible = "realtek,rtd1325-intc-misc", + .data = &rtd1325_intc_misc_info, + }, + { /* sentinel */ } +}; + +static int realtek_intc_rtd1325_suspend(struct device *dev) +{ + struct realtek_intc_data *data = dev_get_drvdata(dev); + const struct realtek_intc_info *info = data->info; + + data->saved_en = readl(data->base + info->scpu_int_en_offset); + + writel(DISABLE_INTC, data->base + info->scpu_int_en_offset); + writel(CLEAN_INTC_STATUS, data->base + info->umsk_isr_offset); + writel(CLEAN_INTC_STATUS, data->base + info->isr_offset); + + return 0; +} + +static int realtek_intc_rtd1325_resume(struct device *dev) +{ + struct realtek_intc_data *data = dev_get_drvdata(dev); + const struct realtek_intc_info *info = data->info; + + writel(CLEAN_INTC_STATUS, data->base + info->umsk_isr_offset); + writel(CLEAN_INTC_STATUS, data->base + info->isr_offset); + writel(data->saved_en, data->base + info->scpu_int_en_offset); + + return 0; +} + +static const struct dev_pm_ops realtek_intc_rtd1325_pm_ops = { + .suspend_noirq = realtek_intc_rtd1325_suspend, + .resume_noirq = realtek_intc_rtd1325_resume, +}; + +static int rtd1325_intc_probe(struct platform_device *pdev) +{ + const struct realtek_intc_info *info; + + info = of_device_get_match_data(&pdev->dev); + if (!info) + return -EINVAL; + + return realtek_intc_probe(pdev, info); +} + +static struct platform_driver realtek_intc_rtd1325_driver = { + .probe = rtd1325_intc_probe, + .driver = { + .name = "realtek_intc_rtd1325", + .of_match_table = realtek_intc_rtd1325_dt_matches, + .suppress_bind_attrs = true, + .pm = &realtek_intc_rtd1325_pm_ops, + }, +}; + +static int __init realtek_intc_rtd1325_init(void) +{ + return platform_driver_register(&realtek_intc_rtd1325_driver); +} +core_initcall(realtek_intc_rtd1325_init); + +static void __exit realtek_intc_rtd1325_exit(void) +{ + platform_driver_unregister(&realtek_intc_rtd1325_driver); +} +module_exit(realtek_intc_rtd1325_exit); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Realtek RTD1325 Interrupt Controller Driver");