162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2022-2023 Linaro Ltd.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#include <linux/gpio/driver.h>
762306a36Sopenharmony_ci#include <linux/module.h>
862306a36Sopenharmony_ci#include <linux/platform_device.h>
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include "pinctrl-lpass-lpi.h"
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_cienum lpass_lpi_functions {
1362306a36Sopenharmony_ci	LPI_MUX_dmic1_clk,
1462306a36Sopenharmony_ci	LPI_MUX_dmic1_data,
1562306a36Sopenharmony_ci	LPI_MUX_dmic2_clk,
1662306a36Sopenharmony_ci	LPI_MUX_dmic2_data,
1762306a36Sopenharmony_ci	LPI_MUX_dmic3_clk,
1862306a36Sopenharmony_ci	LPI_MUX_dmic3_data,
1962306a36Sopenharmony_ci	LPI_MUX_dmic4_clk,
2062306a36Sopenharmony_ci	LPI_MUX_dmic4_data,
2162306a36Sopenharmony_ci	LPI_MUX_i2s0_clk,
2262306a36Sopenharmony_ci	LPI_MUX_i2s0_data,
2362306a36Sopenharmony_ci	LPI_MUX_i2s0_ws,
2462306a36Sopenharmony_ci	LPI_MUX_i2s1_clk,
2562306a36Sopenharmony_ci	LPI_MUX_i2s1_data,
2662306a36Sopenharmony_ci	LPI_MUX_i2s1_ws,
2762306a36Sopenharmony_ci	LPI_MUX_i2s2_clk,
2862306a36Sopenharmony_ci	LPI_MUX_i2s2_data,
2962306a36Sopenharmony_ci	LPI_MUX_i2s2_ws,
3062306a36Sopenharmony_ci	LPI_MUX_i2s3_clk,
3162306a36Sopenharmony_ci	LPI_MUX_i2s3_data,
3262306a36Sopenharmony_ci	LPI_MUX_i2s3_ws,
3362306a36Sopenharmony_ci	LPI_MUX_i2s4_clk,
3462306a36Sopenharmony_ci	LPI_MUX_i2s4_data,
3562306a36Sopenharmony_ci	LPI_MUX_i2s4_ws,
3662306a36Sopenharmony_ci	LPI_MUX_slimbus_clk,
3762306a36Sopenharmony_ci	LPI_MUX_slimbus_data,
3862306a36Sopenharmony_ci	LPI_MUX_swr_rx_clk,
3962306a36Sopenharmony_ci	LPI_MUX_swr_rx_data,
4062306a36Sopenharmony_ci	LPI_MUX_swr_tx_clk,
4162306a36Sopenharmony_ci	LPI_MUX_swr_tx_data,
4262306a36Sopenharmony_ci	LPI_MUX_wsa_swr_clk,
4362306a36Sopenharmony_ci	LPI_MUX_wsa_swr_data,
4462306a36Sopenharmony_ci	LPI_MUX_wsa2_swr_clk,
4562306a36Sopenharmony_ci	LPI_MUX_wsa2_swr_data,
4662306a36Sopenharmony_ci	LPI_MUX_ext_mclk1_a,
4762306a36Sopenharmony_ci	LPI_MUX_ext_mclk1_b,
4862306a36Sopenharmony_ci	LPI_MUX_ext_mclk1_c,
4962306a36Sopenharmony_ci	LPI_MUX_ext_mclk1_d,
5062306a36Sopenharmony_ci	LPI_MUX_ext_mclk1_e,
5162306a36Sopenharmony_ci	LPI_MUX_gpio,
5262306a36Sopenharmony_ci	LPI_MUX__,
5362306a36Sopenharmony_ci};
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_cistatic int gpio0_pins[] = { 0 };
5662306a36Sopenharmony_cistatic int gpio1_pins[] = { 1 };
5762306a36Sopenharmony_cistatic int gpio2_pins[] = { 2 };
5862306a36Sopenharmony_cistatic int gpio3_pins[] = { 3 };
5962306a36Sopenharmony_cistatic int gpio4_pins[] = { 4 };
6062306a36Sopenharmony_cistatic int gpio5_pins[] = { 5 };
6162306a36Sopenharmony_cistatic int gpio6_pins[] = { 6 };
6262306a36Sopenharmony_cistatic int gpio7_pins[] = { 7 };
6362306a36Sopenharmony_cistatic int gpio8_pins[] = { 8 };
6462306a36Sopenharmony_cistatic int gpio9_pins[] = { 9 };
6562306a36Sopenharmony_cistatic int gpio10_pins[] = { 10 };
6662306a36Sopenharmony_cistatic int gpio11_pins[] = { 11 };
6762306a36Sopenharmony_cistatic int gpio12_pins[] = { 12 };
6862306a36Sopenharmony_cistatic int gpio13_pins[] = { 13 };
6962306a36Sopenharmony_cistatic int gpio14_pins[] = { 14 };
7062306a36Sopenharmony_cistatic int gpio15_pins[] = { 15 };
7162306a36Sopenharmony_cistatic int gpio16_pins[] = { 16 };
7262306a36Sopenharmony_cistatic int gpio17_pins[] = { 17 };
7362306a36Sopenharmony_cistatic int gpio18_pins[] = { 18 };
7462306a36Sopenharmony_cistatic int gpio19_pins[] = { 19 };
7562306a36Sopenharmony_cistatic int gpio20_pins[] = { 20 };
7662306a36Sopenharmony_cistatic int gpio21_pins[] = { 21 };
7762306a36Sopenharmony_cistatic int gpio22_pins[] = { 22 };
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_cistatic const struct pinctrl_pin_desc sm8550_lpi_pins[] = {
8062306a36Sopenharmony_ci	PINCTRL_PIN(0, "gpio0"),
8162306a36Sopenharmony_ci	PINCTRL_PIN(1, "gpio1"),
8262306a36Sopenharmony_ci	PINCTRL_PIN(2, "gpio2"),
8362306a36Sopenharmony_ci	PINCTRL_PIN(3, "gpio3"),
8462306a36Sopenharmony_ci	PINCTRL_PIN(4, "gpio4"),
8562306a36Sopenharmony_ci	PINCTRL_PIN(5, "gpio5"),
8662306a36Sopenharmony_ci	PINCTRL_PIN(6, "gpio6"),
8762306a36Sopenharmony_ci	PINCTRL_PIN(7, "gpio7"),
8862306a36Sopenharmony_ci	PINCTRL_PIN(8, "gpio8"),
8962306a36Sopenharmony_ci	PINCTRL_PIN(9, "gpio9"),
9062306a36Sopenharmony_ci	PINCTRL_PIN(10, "gpio10"),
9162306a36Sopenharmony_ci	PINCTRL_PIN(11, "gpio11"),
9262306a36Sopenharmony_ci	PINCTRL_PIN(12, "gpio12"),
9362306a36Sopenharmony_ci	PINCTRL_PIN(13, "gpio13"),
9462306a36Sopenharmony_ci	PINCTRL_PIN(14, "gpio14"),
9562306a36Sopenharmony_ci	PINCTRL_PIN(15, "gpio15"),
9662306a36Sopenharmony_ci	PINCTRL_PIN(16, "gpio16"),
9762306a36Sopenharmony_ci	PINCTRL_PIN(17, "gpio17"),
9862306a36Sopenharmony_ci	PINCTRL_PIN(18, "gpio18"),
9962306a36Sopenharmony_ci	PINCTRL_PIN(19, "gpio19"),
10062306a36Sopenharmony_ci	PINCTRL_PIN(20, "gpio20"),
10162306a36Sopenharmony_ci	PINCTRL_PIN(21, "gpio21"),
10262306a36Sopenharmony_ci	PINCTRL_PIN(22, "gpio22"),
10362306a36Sopenharmony_ci};
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_cistatic const char * const gpio_groups[] = {
10662306a36Sopenharmony_ci	"gpio0", "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7",
10762306a36Sopenharmony_ci	"gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14",
10862306a36Sopenharmony_ci	"gpio15", "gpio16", "gpio17", "gpio18", "gpio19", "gpio20", "gpio21",
10962306a36Sopenharmony_ci	"gpio22",
11062306a36Sopenharmony_ci};
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_cistatic const char * const dmic1_clk_groups[] = { "gpio6" };
11362306a36Sopenharmony_cistatic const char * const dmic1_data_groups[] = { "gpio7" };
11462306a36Sopenharmony_cistatic const char * const dmic2_clk_groups[] = { "gpio8" };
11562306a36Sopenharmony_cistatic const char * const dmic2_data_groups[] = { "gpio9" };
11662306a36Sopenharmony_cistatic const char * const dmic3_clk_groups[] = { "gpio12" };
11762306a36Sopenharmony_cistatic const char * const dmic3_data_groups[] = { "gpio13" };
11862306a36Sopenharmony_cistatic const char * const dmic4_clk_groups[] = { "gpio17" };
11962306a36Sopenharmony_cistatic const char * const dmic4_data_groups[] = { "gpio18" };
12062306a36Sopenharmony_cistatic const char * const i2s0_clk_groups[] = { "gpio0" };
12162306a36Sopenharmony_cistatic const char * const i2s0_ws_groups[] = { "gpio1" };
12262306a36Sopenharmony_cistatic const char * const i2s0_data_groups[] = { "gpio2", "gpio3", "gpio4", "gpio5" };
12362306a36Sopenharmony_cistatic const char * const i2s1_clk_groups[] = { "gpio6" };
12462306a36Sopenharmony_cistatic const char * const i2s1_ws_groups[] = { "gpio7" };
12562306a36Sopenharmony_cistatic const char * const i2s1_data_groups[] = { "gpio8", "gpio9" };
12662306a36Sopenharmony_cistatic const char * const i2s2_clk_groups[] = { "gpio10" };
12762306a36Sopenharmony_cistatic const char * const i2s2_ws_groups[] = { "gpio11" };
12862306a36Sopenharmony_cistatic const char * const i2s2_data_groups[] = { "gpio15", "gpio16" };
12962306a36Sopenharmony_cistatic const char * const i2s3_clk_groups[] = { "gpio12" };
13062306a36Sopenharmony_cistatic const char * const i2s3_ws_groups[] = { "gpio13" };
13162306a36Sopenharmony_cistatic const char * const i2s3_data_groups[] = { "gpio17", "gpio18" };
13262306a36Sopenharmony_cistatic const char * const i2s4_clk_groups[] = { "gpio19"};
13362306a36Sopenharmony_cistatic const char * const i2s4_ws_groups[] = { "gpio20"};
13462306a36Sopenharmony_cistatic const char * const i2s4_data_groups[] = { "gpio21", "gpio22"};
13562306a36Sopenharmony_cistatic const char * const slimbus_clk_groups[] = { "gpio19"};
13662306a36Sopenharmony_cistatic const char * const slimbus_data_groups[] = { "gpio20"};
13762306a36Sopenharmony_cistatic const char * const swr_tx_clk_groups[] = { "gpio0" };
13862306a36Sopenharmony_cistatic const char * const swr_tx_data_groups[] = { "gpio1", "gpio2", "gpio14" };
13962306a36Sopenharmony_cistatic const char * const swr_rx_clk_groups[] = { "gpio3" };
14062306a36Sopenharmony_cistatic const char * const swr_rx_data_groups[] = { "gpio4", "gpio5", "gpio15" };
14162306a36Sopenharmony_cistatic const char * const wsa_swr_clk_groups[] = { "gpio10" };
14262306a36Sopenharmony_cistatic const char * const wsa_swr_data_groups[] = { "gpio11" };
14362306a36Sopenharmony_cistatic const char * const wsa2_swr_clk_groups[] = { "gpio15" };
14462306a36Sopenharmony_cistatic const char * const wsa2_swr_data_groups[] = { "gpio16" };
14562306a36Sopenharmony_cistatic const char * const ext_mclk1_c_groups[] = { "gpio5" };
14662306a36Sopenharmony_cistatic const char * const ext_mclk1_b_groups[] = { "gpio9" };
14762306a36Sopenharmony_cistatic const char * const ext_mclk1_a_groups[] = { "gpio13" };
14862306a36Sopenharmony_cistatic const char * const ext_mclk1_d_groups[] = { "gpio14" };
14962306a36Sopenharmony_cistatic const char * const ext_mclk1_e_groups[] = { "gpio22" };
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_cistatic const struct lpi_pingroup sm8550_groups[] = {
15262306a36Sopenharmony_ci	LPI_PINGROUP(0, 0, swr_tx_clk, i2s0_clk, _, _),
15362306a36Sopenharmony_ci	LPI_PINGROUP(1, 2, swr_tx_data, i2s0_ws, _, _),
15462306a36Sopenharmony_ci	LPI_PINGROUP(2, 4, swr_tx_data, i2s0_data, _, _),
15562306a36Sopenharmony_ci	LPI_PINGROUP(3, 8, swr_rx_clk, i2s0_data, _, _),
15662306a36Sopenharmony_ci	LPI_PINGROUP(4, 10, swr_rx_data, i2s0_data, _, _),
15762306a36Sopenharmony_ci	LPI_PINGROUP(5, 12, swr_rx_data, ext_mclk1_c, i2s0_data, _),
15862306a36Sopenharmony_ci	LPI_PINGROUP(6, LPI_NO_SLEW, dmic1_clk, i2s1_clk, _,  _),
15962306a36Sopenharmony_ci	LPI_PINGROUP(7, LPI_NO_SLEW, dmic1_data, i2s1_ws, _, _),
16062306a36Sopenharmony_ci	LPI_PINGROUP(8, LPI_NO_SLEW, dmic2_clk, i2s1_data, _, _),
16162306a36Sopenharmony_ci	LPI_PINGROUP(9, LPI_NO_SLEW, dmic2_data, i2s1_data, ext_mclk1_b, _),
16262306a36Sopenharmony_ci	LPI_PINGROUP(10, 16, i2s2_clk, wsa_swr_clk, _, _),
16362306a36Sopenharmony_ci	LPI_PINGROUP(11, 18, i2s2_ws, wsa_swr_data, _, _),
16462306a36Sopenharmony_ci	LPI_PINGROUP(12, LPI_NO_SLEW, dmic3_clk, i2s3_clk, _, _),
16562306a36Sopenharmony_ci	LPI_PINGROUP(13, LPI_NO_SLEW, dmic3_data, i2s3_ws, ext_mclk1_a, _),
16662306a36Sopenharmony_ci	LPI_PINGROUP(14, 6, swr_tx_data, ext_mclk1_d, _, _),
16762306a36Sopenharmony_ci	LPI_PINGROUP(15, 20, i2s2_data, wsa2_swr_clk, _, _),
16862306a36Sopenharmony_ci	LPI_PINGROUP(16, 22, i2s2_data, wsa2_swr_data, _, _),
16962306a36Sopenharmony_ci	LPI_PINGROUP(17, LPI_NO_SLEW, dmic4_clk, i2s3_data, _, _),
17062306a36Sopenharmony_ci	LPI_PINGROUP(18, LPI_NO_SLEW, dmic4_data, i2s3_data, _, _),
17162306a36Sopenharmony_ci	LPI_PINGROUP(19, LPI_NO_SLEW, i2s4_clk, slimbus_clk, _, _),
17262306a36Sopenharmony_ci	LPI_PINGROUP(20, LPI_NO_SLEW, i2s4_ws, slimbus_data, _, _),
17362306a36Sopenharmony_ci	LPI_PINGROUP(21, LPI_NO_SLEW, i2s4_data, _, _, _),
17462306a36Sopenharmony_ci	LPI_PINGROUP(22, LPI_NO_SLEW, i2s4_data, ext_mclk1_e, _, _),
17562306a36Sopenharmony_ci};
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_cistatic const struct lpi_function sm8550_functions[] = {
17862306a36Sopenharmony_ci	LPI_FUNCTION(gpio),
17962306a36Sopenharmony_ci	LPI_FUNCTION(dmic1_clk),
18062306a36Sopenharmony_ci	LPI_FUNCTION(dmic1_data),
18162306a36Sopenharmony_ci	LPI_FUNCTION(dmic2_clk),
18262306a36Sopenharmony_ci	LPI_FUNCTION(dmic2_data),
18362306a36Sopenharmony_ci	LPI_FUNCTION(dmic3_clk),
18462306a36Sopenharmony_ci	LPI_FUNCTION(dmic3_data),
18562306a36Sopenharmony_ci	LPI_FUNCTION(dmic4_clk),
18662306a36Sopenharmony_ci	LPI_FUNCTION(dmic4_data),
18762306a36Sopenharmony_ci	LPI_FUNCTION(i2s0_clk),
18862306a36Sopenharmony_ci	LPI_FUNCTION(i2s0_data),
18962306a36Sopenharmony_ci	LPI_FUNCTION(i2s0_ws),
19062306a36Sopenharmony_ci	LPI_FUNCTION(i2s1_clk),
19162306a36Sopenharmony_ci	LPI_FUNCTION(i2s1_data),
19262306a36Sopenharmony_ci	LPI_FUNCTION(i2s1_ws),
19362306a36Sopenharmony_ci	LPI_FUNCTION(i2s2_clk),
19462306a36Sopenharmony_ci	LPI_FUNCTION(i2s2_data),
19562306a36Sopenharmony_ci	LPI_FUNCTION(i2s2_ws),
19662306a36Sopenharmony_ci	LPI_FUNCTION(i2s3_clk),
19762306a36Sopenharmony_ci	LPI_FUNCTION(i2s3_data),
19862306a36Sopenharmony_ci	LPI_FUNCTION(i2s3_ws),
19962306a36Sopenharmony_ci	LPI_FUNCTION(i2s4_clk),
20062306a36Sopenharmony_ci	LPI_FUNCTION(i2s4_data),
20162306a36Sopenharmony_ci	LPI_FUNCTION(i2s4_ws),
20262306a36Sopenharmony_ci	LPI_FUNCTION(slimbus_clk),
20362306a36Sopenharmony_ci	LPI_FUNCTION(slimbus_data),
20462306a36Sopenharmony_ci	LPI_FUNCTION(swr_rx_clk),
20562306a36Sopenharmony_ci	LPI_FUNCTION(swr_rx_data),
20662306a36Sopenharmony_ci	LPI_FUNCTION(swr_tx_clk),
20762306a36Sopenharmony_ci	LPI_FUNCTION(swr_tx_data),
20862306a36Sopenharmony_ci	LPI_FUNCTION(wsa_swr_clk),
20962306a36Sopenharmony_ci	LPI_FUNCTION(wsa_swr_data),
21062306a36Sopenharmony_ci	LPI_FUNCTION(wsa2_swr_clk),
21162306a36Sopenharmony_ci	LPI_FUNCTION(wsa2_swr_data),
21262306a36Sopenharmony_ci	LPI_FUNCTION(ext_mclk1_a),
21362306a36Sopenharmony_ci	LPI_FUNCTION(ext_mclk1_b),
21462306a36Sopenharmony_ci	LPI_FUNCTION(ext_mclk1_c),
21562306a36Sopenharmony_ci	LPI_FUNCTION(ext_mclk1_d),
21662306a36Sopenharmony_ci	LPI_FUNCTION(ext_mclk1_e),
21762306a36Sopenharmony_ci};
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_cistatic const struct lpi_pinctrl_variant_data sm8550_lpi_data = {
22062306a36Sopenharmony_ci	.pins = sm8550_lpi_pins,
22162306a36Sopenharmony_ci	.npins = ARRAY_SIZE(sm8550_lpi_pins),
22262306a36Sopenharmony_ci	.groups = sm8550_groups,
22362306a36Sopenharmony_ci	.ngroups = ARRAY_SIZE(sm8550_groups),
22462306a36Sopenharmony_ci	.functions = sm8550_functions,
22562306a36Sopenharmony_ci	.nfunctions = ARRAY_SIZE(sm8550_functions),
22662306a36Sopenharmony_ci};
22762306a36Sopenharmony_ci
22862306a36Sopenharmony_cistatic const struct of_device_id lpi_pinctrl_of_match[] = {
22962306a36Sopenharmony_ci	{
23062306a36Sopenharmony_ci	       .compatible = "qcom,sm8550-lpass-lpi-pinctrl",
23162306a36Sopenharmony_ci	       .data = &sm8550_lpi_data,
23262306a36Sopenharmony_ci	},
23362306a36Sopenharmony_ci	{ }
23462306a36Sopenharmony_ci};
23562306a36Sopenharmony_ciMODULE_DEVICE_TABLE(of, lpi_pinctrl_of_match);
23662306a36Sopenharmony_ci
23762306a36Sopenharmony_cistatic struct platform_driver lpi_pinctrl_driver = {
23862306a36Sopenharmony_ci	.driver = {
23962306a36Sopenharmony_ci		   .name = "qcom-sm8550-lpass-lpi-pinctrl",
24062306a36Sopenharmony_ci		   .of_match_table = lpi_pinctrl_of_match,
24162306a36Sopenharmony_ci	},
24262306a36Sopenharmony_ci	.probe = lpi_pinctrl_probe,
24362306a36Sopenharmony_ci	.remove = lpi_pinctrl_remove,
24462306a36Sopenharmony_ci};
24562306a36Sopenharmony_ci
24662306a36Sopenharmony_cimodule_platform_driver(lpi_pinctrl_driver);
24762306a36Sopenharmony_ciMODULE_DESCRIPTION("Qualcomm SM8550 LPI GPIO pin control driver");
24862306a36Sopenharmony_ciMODULE_LICENSE("GPL");
249