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