162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright 2019~2020 NXP
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#include <dt-bindings/pinctrl/pads-imx8dxl.h>
762306a36Sopenharmony_ci#include <linux/err.h>
862306a36Sopenharmony_ci#include <linux/firmware/imx/sci.h>
962306a36Sopenharmony_ci#include <linux/init.h>
1062306a36Sopenharmony_ci#include <linux/io.h>
1162306a36Sopenharmony_ci#include <linux/mod_devicetable.h>
1262306a36Sopenharmony_ci#include <linux/module.h>
1362306a36Sopenharmony_ci#include <linux/pinctrl/pinctrl.h>
1462306a36Sopenharmony_ci#include <linux/platform_device.h>
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#include "pinctrl-imx.h"
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cistatic const struct pinctrl_pin_desc imx8dxl_pinctrl_pads[] = {
1962306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_PCIE_CTRL0_PERST_B),
2062306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_PCIE_CTRL0_CLKREQ_B),
2162306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_PCIE_CTRL0_WAKE_B),
2262306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_COMP_CTL_GPIO_1V8_3V3_PCIESEP),
2362306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_USB_SS3_TC0),
2462306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_USB_SS3_TC1),
2562306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_USB_SS3_TC2),
2662306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_USB_SS3_TC3),
2762306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_COMP_CTL_GPIO_3V3_USB3IO),
2862306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_EMMC0_CLK),
2962306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_EMMC0_CMD),
3062306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_EMMC0_DATA0),
3162306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_EMMC0_DATA1),
3262306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_EMMC0_DATA2),
3362306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_EMMC0_DATA3),
3462306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_EMMC0_DATA4),
3562306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_EMMC0_DATA5),
3662306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_EMMC0_DATA6),
3762306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_EMMC0_DATA7),
3862306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_EMMC0_STROBE),
3962306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_EMMC0_RESET_B),
4062306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_COMP_CTL_GPIO_1V8_3V3_SD1FIX0),
4162306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_USDHC1_RESET_B),
4262306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_USDHC1_VSELECT),
4362306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_CTL_NAND_RE_P_N),
4462306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_USDHC1_WP),
4562306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_USDHC1_CD_B),
4662306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_CTL_NAND_DQS_P_N),
4762306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_COMP_CTL_GPIO_1V8_3V3_VSELSEP),
4862306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET0_RGMII_TXC),
4962306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET0_RGMII_TX_CTL),
5062306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET0_RGMII_TXD0),
5162306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET0_RGMII_TXD1),
5262306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET0_RGMII_TXD2),
5362306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET0_RGMII_TXD3),
5462306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_COMP_CTL_GPIO_1V8_3V3_ENET_ENETB0),
5562306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET0_RGMII_RXC),
5662306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET0_RGMII_RX_CTL),
5762306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET0_RGMII_RXD0),
5862306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET0_RGMII_RXD1),
5962306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET0_RGMII_RXD2),
6062306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET0_RGMII_RXD3),
6162306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_COMP_CTL_GPIO_1V8_3V3_ENET_ENETB1),
6262306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET0_REFCLK_125M_25M),
6362306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET0_MDIO),
6462306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET0_MDC),
6562306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_COMP_CTL_GPIO_1V8_3V3_GPIOCT),
6662306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET1_RGMII_TXC),
6762306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET1_RGMII_TXD2),
6862306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET1_RGMII_TX_CTL),
6962306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET1_RGMII_TXD3),
7062306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET1_RGMII_RXC),
7162306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET1_RGMII_RXD3),
7262306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET1_RGMII_RXD2),
7362306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET1_RGMII_RXD1),
7462306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET1_RGMII_TXD0),
7562306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET1_RGMII_TXD1),
7662306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET1_RGMII_RXD0),
7762306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET1_RGMII_RX_CTL),
7862306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ENET1_REFCLK_125M_25M),
7962306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_COMP_CTL_GPIO_1V8_3V3_GPIORHB),
8062306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SPI3_SCK),
8162306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SPI3_SDO),
8262306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SPI3_SDI),
8362306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SPI3_CS0),
8462306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SPI3_CS1),
8562306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_MCLK_IN1),
8662306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_MCLK_IN0),
8762306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_MCLK_OUT0),
8862306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_UART1_TX),
8962306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_UART1_RX),
9062306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_UART1_RTS_B),
9162306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_UART1_CTS_B),
9262306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_COMP_CTL_GPIO_1V8_3V3_GPIORHK),
9362306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SPI0_SCK),
9462306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SPI0_SDI),
9562306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SPI0_SDO),
9662306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SPI0_CS1),
9762306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SPI0_CS0),
9862306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_COMP_CTL_GPIO_1V8_3V3_GPIORHT),
9962306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ADC_IN1),
10062306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ADC_IN0),
10162306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ADC_IN3),
10262306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ADC_IN2),
10362306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ADC_IN5),
10462306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_ADC_IN4),
10562306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_FLEXCAN0_RX),
10662306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_FLEXCAN0_TX),
10762306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_FLEXCAN1_RX),
10862306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_FLEXCAN1_TX),
10962306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_FLEXCAN2_RX),
11062306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_FLEXCAN2_TX),
11162306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_UART0_RX),
11262306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_UART0_TX),
11362306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_UART2_TX),
11462306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_UART2_RX),
11562306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_COMP_CTL_GPIO_1V8_3V3_GPIOLH),
11662306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_JTAG_TRST_B),
11762306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_PMIC_I2C_SCL),
11862306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_PMIC_I2C_SDA),
11962306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_PMIC_INT_B),
12062306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SCU_GPIO0_00),
12162306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SCU_GPIO0_01),
12262306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SCU_PMIC_STANDBY),
12362306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SCU_BOOT_MODE1),
12462306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SCU_BOOT_MODE0),
12562306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SCU_BOOT_MODE2),
12662306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SNVS_TAMPER_OUT1),
12762306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SNVS_TAMPER_OUT2),
12862306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SNVS_TAMPER_OUT3),
12962306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SNVS_TAMPER_OUT4),
13062306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SNVS_TAMPER_IN0),
13162306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SNVS_TAMPER_IN1),
13262306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SNVS_TAMPER_IN2),
13362306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SNVS_TAMPER_IN3),
13462306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SPI1_SCK),
13562306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SPI1_SDO),
13662306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SPI1_SDI),
13762306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_SPI1_CS0),
13862306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_COMP_CTL_GPIO_1V8_3V3_GPIORHD),
13962306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_QSPI0A_DATA1),
14062306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_QSPI0A_DATA0),
14162306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_QSPI0A_DATA3),
14262306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_QSPI0A_DATA2),
14362306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_QSPI0A_SS0_B),
14462306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_QSPI0A_DQS),
14562306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_QSPI0A_SCLK),
14662306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_COMP_CTL_GPIO_1V8_3V3_QSPI0A),
14762306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_QSPI0B_SCLK),
14862306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_QSPI0B_DQS),
14962306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_QSPI0B_DATA1),
15062306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_QSPI0B_DATA0),
15162306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_QSPI0B_DATA3),
15262306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_QSPI0B_DATA2),
15362306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_QSPI0B_SS0_B),
15462306a36Sopenharmony_ci	IMX_PINCTRL_PIN(IMX8DXL_COMP_CTL_GPIO_1V8_3V3_QSPI0B)
15562306a36Sopenharmony_ci};
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_cistatic const struct imx_pinctrl_soc_info imx8dxl_pinctrl_info = {
15962306a36Sopenharmony_ci	.pins = imx8dxl_pinctrl_pads,
16062306a36Sopenharmony_ci	.npins = ARRAY_SIZE(imx8dxl_pinctrl_pads),
16162306a36Sopenharmony_ci	.flags = IMX_USE_SCU,
16262306a36Sopenharmony_ci	.imx_pinconf_get = imx_pinconf_get_scu,
16362306a36Sopenharmony_ci	.imx_pinconf_set = imx_pinconf_set_scu,
16462306a36Sopenharmony_ci	.imx_pinctrl_parse_pin = imx_pinctrl_parse_pin_scu,
16562306a36Sopenharmony_ci};
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_cistatic const struct of_device_id imx8dxl_pinctrl_of_match[] = {
16862306a36Sopenharmony_ci	{ .compatible = "fsl,imx8dxl-iomuxc", },
16962306a36Sopenharmony_ci	{ /* sentinel */ }
17062306a36Sopenharmony_ci};
17162306a36Sopenharmony_ciMODULE_DEVICE_TABLE(of, imx8dxl_pinctrl_of_match);
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_cistatic int imx8dxl_pinctrl_probe(struct platform_device *pdev)
17462306a36Sopenharmony_ci{
17562306a36Sopenharmony_ci	int ret;
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci	ret = imx_pinctrl_sc_ipc_init(pdev);
17862306a36Sopenharmony_ci	if (ret)
17962306a36Sopenharmony_ci		return ret;
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci	return imx_pinctrl_probe(pdev, &imx8dxl_pinctrl_info);
18262306a36Sopenharmony_ci}
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_cistatic struct platform_driver imx8dxl_pinctrl_driver = {
18562306a36Sopenharmony_ci	.driver = {
18662306a36Sopenharmony_ci		.name = "fsl,imx8dxl-iomuxc",
18762306a36Sopenharmony_ci		.of_match_table = imx8dxl_pinctrl_of_match,
18862306a36Sopenharmony_ci		.suppress_bind_attrs = true,
18962306a36Sopenharmony_ci	},
19062306a36Sopenharmony_ci	.probe = imx8dxl_pinctrl_probe,
19162306a36Sopenharmony_ci};
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_cistatic int __init imx8dxl_pinctrl_init(void)
19462306a36Sopenharmony_ci{
19562306a36Sopenharmony_ci	return platform_driver_register(&imx8dxl_pinctrl_driver);
19662306a36Sopenharmony_ci}
19762306a36Sopenharmony_ciarch_initcall(imx8dxl_pinctrl_init);
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ciMODULE_AUTHOR("Anson Huang <Anson.Huang@nxp.com>");
20062306a36Sopenharmony_ciMODULE_DESCRIPTION("NXP i.MX8DXL pinctrl driver");
20162306a36Sopenharmony_ciMODULE_LICENSE("GPL v2");
202