18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Pinctrl data for the NVIDIA Tegra194 pinmux
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2019, NVIDIA CORPORATION.  All rights reserved.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify it
88c2ecf20Sopenharmony_ci * under the terms and conditions of the GNU General Public License,
98c2ecf20Sopenharmony_ci * version 2, as published by the Free Software Foundation.
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * This program is distributed in the hope it will be useful, but WITHOUT
128c2ecf20Sopenharmony_ci * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
138c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
148c2ecf20Sopenharmony_ci * more details.
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <linux/init.h>
188c2ecf20Sopenharmony_ci#include <linux/of.h>
198c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
208c2ecf20Sopenharmony_ci#include <linux/pinctrl/pinctrl.h>
218c2ecf20Sopenharmony_ci#include <linux/pinctrl/pinmux.h>
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#include "pinctrl-tegra.h"
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/* Define unique ID for each pins */
268c2ecf20Sopenharmony_cienum pin_id {
278c2ecf20Sopenharmony_ci	TEGRA_PIN_PEX_L5_CLKREQ_N_PGG0,
288c2ecf20Sopenharmony_ci	TEGRA_PIN_PEX_L5_RST_N_PGG1,
298c2ecf20Sopenharmony_ci};
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/* Table for pin descriptor */
328c2ecf20Sopenharmony_cistatic const struct pinctrl_pin_desc tegra194_pins[] = {
338c2ecf20Sopenharmony_ci	PINCTRL_PIN(TEGRA_PIN_PEX_L5_CLKREQ_N_PGG0, "PEX_L5_CLKREQ_N_PGG0"),
348c2ecf20Sopenharmony_ci	PINCTRL_PIN(TEGRA_PIN_PEX_L5_RST_N_PGG1, "PEX_L5_RST_N_PGG1"),
358c2ecf20Sopenharmony_ci};
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistatic const unsigned int pex_l5_clkreq_n_pgg0_pins[] = {
388c2ecf20Sopenharmony_ci	TEGRA_PIN_PEX_L5_CLKREQ_N_PGG0,
398c2ecf20Sopenharmony_ci};
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cistatic const unsigned int pex_l5_rst_n_pgg1_pins[] = {
428c2ecf20Sopenharmony_ci	TEGRA_PIN_PEX_L5_RST_N_PGG1,
438c2ecf20Sopenharmony_ci};
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/* Define unique ID for each function */
468c2ecf20Sopenharmony_cienum tegra_mux_dt {
478c2ecf20Sopenharmony_ci	TEGRA_MUX_RSVD0,
488c2ecf20Sopenharmony_ci	TEGRA_MUX_RSVD1,
498c2ecf20Sopenharmony_ci	TEGRA_MUX_RSVD2,
508c2ecf20Sopenharmony_ci	TEGRA_MUX_RSVD3,
518c2ecf20Sopenharmony_ci	TEGRA_MUX_PE5,
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/* Make list of each function name */
558c2ecf20Sopenharmony_ci#define TEGRA_PIN_FUNCTION(lid)			\
568c2ecf20Sopenharmony_ci	{					\
578c2ecf20Sopenharmony_ci		.name = #lid,			\
588c2ecf20Sopenharmony_ci	}
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistatic struct tegra_function tegra194_functions[] = {
618c2ecf20Sopenharmony_ci	TEGRA_PIN_FUNCTION(rsvd0),
628c2ecf20Sopenharmony_ci	TEGRA_PIN_FUNCTION(rsvd1),
638c2ecf20Sopenharmony_ci	TEGRA_PIN_FUNCTION(rsvd2),
648c2ecf20Sopenharmony_ci	TEGRA_PIN_FUNCTION(rsvd3),
658c2ecf20Sopenharmony_ci	TEGRA_PIN_FUNCTION(pe5),
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#define DRV_PINGROUP_ENTRY_Y(r, drvdn_b, drvdn_w, drvup_b,	\
698c2ecf20Sopenharmony_ci			     drvup_w, slwr_b, slwr_w, slwf_b,	\
708c2ecf20Sopenharmony_ci			     slwf_w, bank)			\
718c2ecf20Sopenharmony_ci		.drv_reg = ((r)),				\
728c2ecf20Sopenharmony_ci		.drv_bank = bank,				\
738c2ecf20Sopenharmony_ci		.drvdn_bit = drvdn_b,				\
748c2ecf20Sopenharmony_ci		.drvdn_width = drvdn_w,				\
758c2ecf20Sopenharmony_ci		.drvup_bit = drvup_b,				\
768c2ecf20Sopenharmony_ci		.drvup_width = drvup_w,				\
778c2ecf20Sopenharmony_ci		.slwr_bit = slwr_b,				\
788c2ecf20Sopenharmony_ci		.slwr_width = slwr_w,				\
798c2ecf20Sopenharmony_ci		.slwf_bit = slwf_b,				\
808c2ecf20Sopenharmony_ci		.slwf_width = slwf_w
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci#define PIN_PINGROUP_ENTRY_Y(r, bank, pupd, e_lpbk, e_input,	\
838c2ecf20Sopenharmony_ci			     e_od, schmitt_b, drvtype)		\
848c2ecf20Sopenharmony_ci		.mux_reg = ((r)),				\
858c2ecf20Sopenharmony_ci		.lpmd_bit = -1,					\
868c2ecf20Sopenharmony_ci		.lock_bit = -1,					\
878c2ecf20Sopenharmony_ci		.hsm_bit = -1,					\
888c2ecf20Sopenharmony_ci		.mux_bank = bank,				\
898c2ecf20Sopenharmony_ci		.mux_bit = 0,					\
908c2ecf20Sopenharmony_ci		.pupd_reg = ((r)),				\
918c2ecf20Sopenharmony_ci		.pupd_bank = bank,				\
928c2ecf20Sopenharmony_ci		.pupd_bit = 2,					\
938c2ecf20Sopenharmony_ci		.tri_reg = ((r)),				\
948c2ecf20Sopenharmony_ci		.tri_bank = bank,				\
958c2ecf20Sopenharmony_ci		.tri_bit = 4,					\
968c2ecf20Sopenharmony_ci		.einput_bit = e_input,				\
978c2ecf20Sopenharmony_ci		.odrain_bit = e_od,				\
988c2ecf20Sopenharmony_ci		.sfsel_bit = 10,				\
998c2ecf20Sopenharmony_ci		.schmitt_bit = schmitt_b,			\
1008c2ecf20Sopenharmony_ci		.drvtype_bit = 13,				\
1018c2ecf20Sopenharmony_ci		.parked_bitmask = 0
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#define drive_pex_l5_clkreq_n_pgg0				\
1048c2ecf20Sopenharmony_ci	DRV_PINGROUP_ENTRY_Y(0x14004, 12, 5, 20, 5, -1, -1, -1, -1, 0)
1058c2ecf20Sopenharmony_ci#define drive_pex_l5_rst_n_pgg1					\
1068c2ecf20Sopenharmony_ci	DRV_PINGROUP_ENTRY_Y(0x1400c, 12, 5, 20, 5, -1, -1, -1, -1, 0)
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci#define PINGROUP(pg_name, f0, f1, f2, f3, r, bank, pupd, e_lpbk,	\
1098c2ecf20Sopenharmony_ci		 e_input, e_lpdr, e_od, schmitt_b, drvtype, io_rail)	\
1108c2ecf20Sopenharmony_ci	{								\
1118c2ecf20Sopenharmony_ci		.name = #pg_name,					\
1128c2ecf20Sopenharmony_ci		.pins = pg_name##_pins,					\
1138c2ecf20Sopenharmony_ci		.npins = ARRAY_SIZE(pg_name##_pins),			\
1148c2ecf20Sopenharmony_ci			.funcs = {					\
1158c2ecf20Sopenharmony_ci				TEGRA_MUX_##f0,				\
1168c2ecf20Sopenharmony_ci				TEGRA_MUX_##f1,				\
1178c2ecf20Sopenharmony_ci				TEGRA_MUX_##f2,				\
1188c2ecf20Sopenharmony_ci				TEGRA_MUX_##f3,				\
1198c2ecf20Sopenharmony_ci			},						\
1208c2ecf20Sopenharmony_ci		PIN_PINGROUP_ENTRY_Y(r, bank, pupd, e_lpbk,		\
1218c2ecf20Sopenharmony_ci				     e_input, e_od,			\
1228c2ecf20Sopenharmony_ci				     schmitt_b, drvtype),		\
1238c2ecf20Sopenharmony_ci		drive_##pg_name,					\
1248c2ecf20Sopenharmony_ci	}
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_cistatic const struct tegra_pingroup tegra194_groups[] = {
1278c2ecf20Sopenharmony_ci	PINGROUP(pex_l5_clkreq_n_pgg0, PE5, RSVD1, RSVD2, RSVD3, 0x14000, 0,
1288c2ecf20Sopenharmony_ci		 Y, -1, 6, 8, 11, 12, N, "vddio_pex_ctl_2"),
1298c2ecf20Sopenharmony_ci	PINGROUP(pex_l5_rst_n_pgg1, PE5, RSVD1, RSVD2, RSVD3, 0x14008, 0,
1308c2ecf20Sopenharmony_ci		 Y, -1, 6, 8, 11, 12, N, "vddio_pex_ctl_2"),
1318c2ecf20Sopenharmony_ci};
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_cistatic const struct tegra_pinctrl_soc_data tegra194_pinctrl = {
1348c2ecf20Sopenharmony_ci	.pins = tegra194_pins,
1358c2ecf20Sopenharmony_ci	.npins = ARRAY_SIZE(tegra194_pins),
1368c2ecf20Sopenharmony_ci	.functions = tegra194_functions,
1378c2ecf20Sopenharmony_ci	.nfunctions = ARRAY_SIZE(tegra194_functions),
1388c2ecf20Sopenharmony_ci	.groups = tegra194_groups,
1398c2ecf20Sopenharmony_ci	.ngroups = ARRAY_SIZE(tegra194_groups),
1408c2ecf20Sopenharmony_ci	.hsm_in_mux = true,
1418c2ecf20Sopenharmony_ci	.schmitt_in_mux = true,
1428c2ecf20Sopenharmony_ci	.drvtype_in_mux = true,
1438c2ecf20Sopenharmony_ci	.sfsel_in_mux = true,
1448c2ecf20Sopenharmony_ci};
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_cistatic int tegra194_pinctrl_probe(struct platform_device *pdev)
1478c2ecf20Sopenharmony_ci{
1488c2ecf20Sopenharmony_ci	return tegra_pinctrl_probe(pdev, &tegra194_pinctrl);
1498c2ecf20Sopenharmony_ci}
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_cistatic const struct of_device_id tegra194_pinctrl_of_match[] = {
1528c2ecf20Sopenharmony_ci	{ .compatible = "nvidia,tegra194-pinmux", },
1538c2ecf20Sopenharmony_ci	{ },
1548c2ecf20Sopenharmony_ci};
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_cistatic struct platform_driver tegra194_pinctrl_driver = {
1578c2ecf20Sopenharmony_ci	.driver = {
1588c2ecf20Sopenharmony_ci		.name = "tegra194-pinctrl",
1598c2ecf20Sopenharmony_ci		.of_match_table = tegra194_pinctrl_of_match,
1608c2ecf20Sopenharmony_ci	},
1618c2ecf20Sopenharmony_ci	.probe = tegra194_pinctrl_probe,
1628c2ecf20Sopenharmony_ci};
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_cistatic int __init tegra194_pinctrl_init(void)
1658c2ecf20Sopenharmony_ci{
1668c2ecf20Sopenharmony_ci	return platform_driver_register(&tegra194_pinctrl_driver);
1678c2ecf20Sopenharmony_ci}
1688c2ecf20Sopenharmony_ciarch_initcall(tegra194_pinctrl_init);
169