1*67f40373SSrinivas Kandagatla // SPDX-License-Identifier: GPL-2.0-only
2*67f40373SSrinivas Kandagatla /*
3*67f40373SSrinivas Kandagatla  * Copyright (c) 2022 Linaro Ltd.
4*67f40373SSrinivas Kandagatla  */
5*67f40373SSrinivas Kandagatla 
6*67f40373SSrinivas Kandagatla #include <linux/gpio/driver.h>
7*67f40373SSrinivas Kandagatla #include <linux/module.h>
8*67f40373SSrinivas Kandagatla #include <linux/platform_device.h>
9*67f40373SSrinivas Kandagatla 
10*67f40373SSrinivas Kandagatla #include "pinctrl-lpass-lpi.h"
11*67f40373SSrinivas Kandagatla 
12*67f40373SSrinivas Kandagatla enum lpass_lpi_functions {
13*67f40373SSrinivas Kandagatla 	LPI_MUX_dmic1_clk,
14*67f40373SSrinivas Kandagatla 	LPI_MUX_dmic1_data,
15*67f40373SSrinivas Kandagatla 	LPI_MUX_dmic2_clk,
16*67f40373SSrinivas Kandagatla 	LPI_MUX_dmic2_data,
17*67f40373SSrinivas Kandagatla 	LPI_MUX_dmic3_clk,
18*67f40373SSrinivas Kandagatla 	LPI_MUX_dmic3_data,
19*67f40373SSrinivas Kandagatla 	LPI_MUX_dmic4_clk,
20*67f40373SSrinivas Kandagatla 	LPI_MUX_dmic4_data,
21*67f40373SSrinivas Kandagatla 	LPI_MUX_i2s1_clk,
22*67f40373SSrinivas Kandagatla 	LPI_MUX_i2s1_data,
23*67f40373SSrinivas Kandagatla 	LPI_MUX_i2s1_ws,
24*67f40373SSrinivas Kandagatla 	LPI_MUX_i2s2_clk,
25*67f40373SSrinivas Kandagatla 	LPI_MUX_i2s2_data,
26*67f40373SSrinivas Kandagatla 	LPI_MUX_i2s2_ws,
27*67f40373SSrinivas Kandagatla 	LPI_MUX_i2s3_clk,
28*67f40373SSrinivas Kandagatla 	LPI_MUX_i2s3_data,
29*67f40373SSrinivas Kandagatla 	LPI_MUX_i2s3_ws,
30*67f40373SSrinivas Kandagatla 	LPI_MUX_qua_mi2s_data,
31*67f40373SSrinivas Kandagatla 	LPI_MUX_qua_mi2s_sclk,
32*67f40373SSrinivas Kandagatla 	LPI_MUX_qua_mi2s_ws,
33*67f40373SSrinivas Kandagatla 	LPI_MUX_swr_rx_clk,
34*67f40373SSrinivas Kandagatla 	LPI_MUX_swr_rx_data,
35*67f40373SSrinivas Kandagatla 	LPI_MUX_swr_tx_clk,
36*67f40373SSrinivas Kandagatla 	LPI_MUX_swr_tx_data,
37*67f40373SSrinivas Kandagatla 	LPI_MUX_wsa_swr_clk,
38*67f40373SSrinivas Kandagatla 	LPI_MUX_wsa_swr_data,
39*67f40373SSrinivas Kandagatla 	LPI_MUX_wsa2_swr_clk,
40*67f40373SSrinivas Kandagatla 	LPI_MUX_wsa2_swr_data,
41*67f40373SSrinivas Kandagatla 	LPI_MUX_ext_mclk1_a,
42*67f40373SSrinivas Kandagatla 	LPI_MUX_ext_mclk1_b,
43*67f40373SSrinivas Kandagatla 	LPI_MUX_ext_mclk1_c,
44*67f40373SSrinivas Kandagatla 	LPI_MUX_gpio,
45*67f40373SSrinivas Kandagatla 	LPI_MUX__,
46*67f40373SSrinivas Kandagatla };
47*67f40373SSrinivas Kandagatla 
48*67f40373SSrinivas Kandagatla static int gpio0_pins[] = { 0 };
49*67f40373SSrinivas Kandagatla static int gpio1_pins[] = { 1 };
50*67f40373SSrinivas Kandagatla static int gpio2_pins[] = { 2 };
51*67f40373SSrinivas Kandagatla static int gpio3_pins[] = { 3 };
52*67f40373SSrinivas Kandagatla static int gpio4_pins[] = { 4 };
53*67f40373SSrinivas Kandagatla static int gpio5_pins[] = { 5 };
54*67f40373SSrinivas Kandagatla static int gpio6_pins[] = { 6 };
55*67f40373SSrinivas Kandagatla static int gpio7_pins[] = { 7 };
56*67f40373SSrinivas Kandagatla static int gpio8_pins[] = { 8 };
57*67f40373SSrinivas Kandagatla static int gpio9_pins[] = { 9 };
58*67f40373SSrinivas Kandagatla static int gpio10_pins[] = { 10 };
59*67f40373SSrinivas Kandagatla static int gpio11_pins[] = { 11 };
60*67f40373SSrinivas Kandagatla static int gpio12_pins[] = { 12 };
61*67f40373SSrinivas Kandagatla static int gpio13_pins[] = { 13 };
62*67f40373SSrinivas Kandagatla static int gpio14_pins[] = { 14 };
63*67f40373SSrinivas Kandagatla static int gpio15_pins[] = { 15 };
64*67f40373SSrinivas Kandagatla static int gpio16_pins[] = { 16 };
65*67f40373SSrinivas Kandagatla static int gpio17_pins[] = { 17 };
66*67f40373SSrinivas Kandagatla static int gpio18_pins[] = { 18 };
67*67f40373SSrinivas Kandagatla 
68*67f40373SSrinivas Kandagatla static const struct pinctrl_pin_desc sc8280xp_lpi_pins[] = {
69*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(0, "gpio0"),
70*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(1, "gpio1"),
71*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(2, "gpio2"),
72*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(3, "gpio3"),
73*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(4, "gpio4"),
74*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(5, "gpio5"),
75*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(6, "gpio6"),
76*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(7, "gpio7"),
77*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(8, "gpio8"),
78*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(9, "gpio9"),
79*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(10, "gpio10"),
80*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(11, "gpio11"),
81*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(12, "gpio12"),
82*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(13, "gpio13"),
83*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(14, "gpio14"),
84*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(15, "gpio15"),
85*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(16, "gpio16"),
86*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(17, "gpio17"),
87*67f40373SSrinivas Kandagatla 	PINCTRL_PIN(18, "gpio18"),
88*67f40373SSrinivas Kandagatla };
89*67f40373SSrinivas Kandagatla 
90*67f40373SSrinivas Kandagatla static const char * const swr_tx_clk_groups[] = { "gpio0" };
91*67f40373SSrinivas Kandagatla static const char * const swr_tx_data_groups[] = { "gpio1", "gpio2", "gpio14" };
92*67f40373SSrinivas Kandagatla static const char * const swr_rx_clk_groups[] = { "gpio3" };
93*67f40373SSrinivas Kandagatla static const char * const swr_rx_data_groups[] = { "gpio4", "gpio5" };
94*67f40373SSrinivas Kandagatla static const char * const dmic1_clk_groups[] = { "gpio6" };
95*67f40373SSrinivas Kandagatla static const char * const dmic1_data_groups[] = { "gpio7" };
96*67f40373SSrinivas Kandagatla static const char * const dmic2_clk_groups[] = { "gpio8" };
97*67f40373SSrinivas Kandagatla static const char * const dmic2_data_groups[] = { "gpio9" };
98*67f40373SSrinivas Kandagatla static const char * const dmic4_clk_groups[] = { "gpio17" };
99*67f40373SSrinivas Kandagatla static const char * const dmic4_data_groups[] = { "gpio18" };
100*67f40373SSrinivas Kandagatla static const char * const i2s2_clk_groups[] = { "gpio10" };
101*67f40373SSrinivas Kandagatla static const char * const i2s2_ws_groups[] = { "gpio11" };
102*67f40373SSrinivas Kandagatla static const char * const dmic3_clk_groups[] = { "gpio12" };
103*67f40373SSrinivas Kandagatla static const char * const dmic3_data_groups[] = { "gpio13" };
104*67f40373SSrinivas Kandagatla static const char * const qua_mi2s_sclk_groups[] = { "gpio0" };
105*67f40373SSrinivas Kandagatla static const char * const qua_mi2s_ws_groups[] = { "gpio1" };
106*67f40373SSrinivas Kandagatla static const char * const qua_mi2s_data_groups[] = { "gpio2", "gpio3", "gpio4", "gpio5" };
107*67f40373SSrinivas Kandagatla static const char * const i2s1_clk_groups[] = { "gpio6" };
108*67f40373SSrinivas Kandagatla static const char * const i2s1_ws_groups[] = { "gpio7" };
109*67f40373SSrinivas Kandagatla static const char * const i2s1_data_groups[] = { "gpio8", "gpio9" };
110*67f40373SSrinivas Kandagatla static const char * const wsa_swr_clk_groups[] = { "gpio10" };
111*67f40373SSrinivas Kandagatla static const char * const wsa_swr_data_groups[] = { "gpio11" };
112*67f40373SSrinivas Kandagatla static const char * const wsa2_swr_clk_groups[] = { "gpio15" };
113*67f40373SSrinivas Kandagatla static const char * const wsa2_swr_data_groups[] = { "gpio16" };
114*67f40373SSrinivas Kandagatla static const char * const i2s2_data_groups[] = { "gpio15", "gpio16" };
115*67f40373SSrinivas Kandagatla static const char * const i2s3_clk_groups[] = { "gpio12"};
116*67f40373SSrinivas Kandagatla static const char * const i2s3_ws_groups[] = { "gpio13"};
117*67f40373SSrinivas Kandagatla static const char * const i2s3_data_groups[] = { "gpio17", "gpio18"};
118*67f40373SSrinivas Kandagatla static const char * const ext_mclk1_c_groups[] = { "gpio5" };
119*67f40373SSrinivas Kandagatla static const char * const ext_mclk1_b_groups[] = { "gpio9" };
120*67f40373SSrinivas Kandagatla static const char * const ext_mclk1_a_groups[] = { "gpio13" };
121*67f40373SSrinivas Kandagatla 
122*67f40373SSrinivas Kandagatla static const struct lpi_pingroup sc8280xp_groups[] = {
123*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(0, 0, swr_tx_clk, qua_mi2s_sclk, _, _),
124*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(1, 2, swr_tx_data, qua_mi2s_ws, _, _),
125*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(2, 4, swr_tx_data, qua_mi2s_data, _, _),
126*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(3, 8, swr_rx_clk, qua_mi2s_data, _, _),
127*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(4, 10, swr_rx_data, qua_mi2s_data, _, _),
128*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(5, 12, swr_rx_data, ext_mclk1_c, qua_mi2s_data, _),
129*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(6, LPI_NO_SLEW, dmic1_clk, i2s1_clk, _,  _),
130*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(7, LPI_NO_SLEW, dmic1_data, i2s1_ws, _, _),
131*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(8, LPI_NO_SLEW, dmic2_clk, i2s1_data, _, _),
132*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(9, LPI_NO_SLEW, dmic2_data, i2s1_data, ext_mclk1_b, _),
133*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(10, 16, i2s2_clk, wsa_swr_clk, _, _),
134*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(11, 18, i2s2_ws, wsa_swr_data, _, _),
135*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(12, LPI_NO_SLEW, dmic3_clk, i2s3_clk, _, _),
136*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(13, LPI_NO_SLEW, dmic3_data, i2s3_ws, ext_mclk1_a, _),
137*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(14, 6, swr_tx_data, _, _, _),
138*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(15, 20, i2s2_data, wsa2_swr_clk, _, _),
139*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(16, 22, i2s2_data, wsa2_swr_data, _, _),
140*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(17, LPI_NO_SLEW, dmic4_clk, i2s3_data, _, _),
141*67f40373SSrinivas Kandagatla 	LPI_PINGROUP(18, LPI_NO_SLEW, dmic4_data, i2s3_data, _, _),
142*67f40373SSrinivas Kandagatla };
143*67f40373SSrinivas Kandagatla 
144*67f40373SSrinivas Kandagatla static const struct lpi_function sc8280xp_functions[] = {
145*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(dmic1_clk),
146*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(dmic1_data),
147*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(dmic2_clk),
148*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(dmic2_data),
149*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(dmic3_clk),
150*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(dmic3_data),
151*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(dmic4_clk),
152*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(dmic4_data),
153*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(i2s1_clk),
154*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(i2s1_data),
155*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(i2s1_ws),
156*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(i2s2_clk),
157*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(i2s2_data),
158*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(i2s2_ws),
159*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(i2s3_clk),
160*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(i2s3_data),
161*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(i2s3_ws),
162*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(qua_mi2s_data),
163*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(qua_mi2s_sclk),
164*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(qua_mi2s_ws),
165*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(swr_rx_clk),
166*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(swr_rx_data),
167*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(swr_tx_clk),
168*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(swr_tx_data),
169*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(wsa_swr_clk),
170*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(wsa_swr_data),
171*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(wsa2_swr_clk),
172*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(wsa2_swr_data),
173*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(ext_mclk1_a),
174*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(ext_mclk1_b),
175*67f40373SSrinivas Kandagatla 	LPI_FUNCTION(ext_mclk1_c),
176*67f40373SSrinivas Kandagatla };
177*67f40373SSrinivas Kandagatla 
178*67f40373SSrinivas Kandagatla static const struct lpi_pinctrl_variant_data sc8280xp_lpi_data = {
179*67f40373SSrinivas Kandagatla 	.pins = sc8280xp_lpi_pins,
180*67f40373SSrinivas Kandagatla 	.npins = ARRAY_SIZE(sc8280xp_lpi_pins),
181*67f40373SSrinivas Kandagatla 	.groups = sc8280xp_groups,
182*67f40373SSrinivas Kandagatla 	.ngroups = ARRAY_SIZE(sc8280xp_groups),
183*67f40373SSrinivas Kandagatla 	.functions = sc8280xp_functions,
184*67f40373SSrinivas Kandagatla 	.nfunctions = ARRAY_SIZE(sc8280xp_functions),
185*67f40373SSrinivas Kandagatla };
186*67f40373SSrinivas Kandagatla 
187*67f40373SSrinivas Kandagatla static const struct of_device_id lpi_pinctrl_of_match[] = {
188*67f40373SSrinivas Kandagatla 	{
189*67f40373SSrinivas Kandagatla 	       .compatible = "qcom,sc8280xp-lpass-lpi-pinctrl",
190*67f40373SSrinivas Kandagatla 	       .data = &sc8280xp_lpi_data,
191*67f40373SSrinivas Kandagatla 	},
192*67f40373SSrinivas Kandagatla 	{ }
193*67f40373SSrinivas Kandagatla };
194*67f40373SSrinivas Kandagatla MODULE_DEVICE_TABLE(of, lpi_pinctrl_of_match);
195*67f40373SSrinivas Kandagatla 
196*67f40373SSrinivas Kandagatla static struct platform_driver lpi_pinctrl_driver = {
197*67f40373SSrinivas Kandagatla 	.driver = {
198*67f40373SSrinivas Kandagatla 		   .name = "qcom-sc8280xp-lpass-lpi-pinctrl",
199*67f40373SSrinivas Kandagatla 		   .of_match_table = lpi_pinctrl_of_match,
200*67f40373SSrinivas Kandagatla 	},
201*67f40373SSrinivas Kandagatla 	.probe = lpi_pinctrl_probe,
202*67f40373SSrinivas Kandagatla 	.remove = lpi_pinctrl_remove,
203*67f40373SSrinivas Kandagatla };
204*67f40373SSrinivas Kandagatla 
205*67f40373SSrinivas Kandagatla module_platform_driver(lpi_pinctrl_driver);
206*67f40373SSrinivas Kandagatla MODULE_DESCRIPTION("QTI SC8280XP LPI GPIO pin control driver");
207*67f40373SSrinivas Kandagatla MODULE_LICENSE("GPL");
208