1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2022-2023 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_i2s0_clk,
22 	LPI_MUX_i2s0_data,
23 	LPI_MUX_i2s0_ws,
24 	LPI_MUX_i2s1_clk,
25 	LPI_MUX_i2s1_data,
26 	LPI_MUX_i2s1_ws,
27 	LPI_MUX_i2s2_clk,
28 	LPI_MUX_i2s2_data,
29 	LPI_MUX_i2s2_ws,
30 	LPI_MUX_i2s3_clk,
31 	LPI_MUX_i2s3_data,
32 	LPI_MUX_i2s3_ws,
33 	LPI_MUX_i2s4_clk,
34 	LPI_MUX_i2s4_data,
35 	LPI_MUX_i2s4_ws,
36 	LPI_MUX_slimbus_clk,
37 	LPI_MUX_slimbus_data,
38 	LPI_MUX_swr_rx_clk,
39 	LPI_MUX_swr_rx_data,
40 	LPI_MUX_swr_tx_clk,
41 	LPI_MUX_swr_tx_data,
42 	LPI_MUX_wsa_swr_clk,
43 	LPI_MUX_wsa_swr_data,
44 	LPI_MUX_wsa2_swr_clk,
45 	LPI_MUX_wsa2_swr_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 sm8550_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 gpio_groups[] = {
106 	"gpio0", "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7",
107 	"gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14",
108 	"gpio15", "gpio16", "gpio17", "gpio18", "gpio19", "gpio20", "gpio21",
109 	"gpio22",
110 };
111 
112 static const char * const dmic1_clk_groups[] = { "gpio6" };
113 static const char * const dmic1_data_groups[] = { "gpio7" };
114 static const char * const dmic2_clk_groups[] = { "gpio8" };
115 static const char * const dmic2_data_groups[] = { "gpio9" };
116 static const char * const dmic3_clk_groups[] = { "gpio12" };
117 static const char * const dmic3_data_groups[] = { "gpio13" };
118 static const char * const dmic4_clk_groups[] = { "gpio17" };
119 static const char * const dmic4_data_groups[] = { "gpio18" };
120 static const char * const i2s0_clk_groups[] = { "gpio0" };
121 static const char * const i2s0_ws_groups[] = { "gpio1" };
122 static const char * const i2s0_data_groups[] = { "gpio2", "gpio3", "gpio4", "gpio5" };
123 static const char * const i2s1_clk_groups[] = { "gpio6" };
124 static const char * const i2s1_ws_groups[] = { "gpio7" };
125 static const char * const i2s1_data_groups[] = { "gpio8", "gpio9" };
126 static const char * const i2s2_clk_groups[] = { "gpio10" };
127 static const char * const i2s2_ws_groups[] = { "gpio11" };
128 static const char * const i2s2_data_groups[] = { "gpio15", "gpio16" };
129 static const char * const i2s3_clk_groups[] = { "gpio12" };
130 static const char * const i2s3_ws_groups[] = { "gpio13" };
131 static const char * const i2s3_data_groups[] = { "gpio17", "gpio18" };
132 static const char * const i2s4_clk_groups[] = { "gpio19"};
133 static const char * const i2s4_ws_groups[] = { "gpio20"};
134 static const char * const i2s4_data_groups[] = { "gpio21", "gpio22"};
135 static const char * const slimbus_clk_groups[] = { "gpio19"};
136 static const char * const slimbus_data_groups[] = { "gpio20"};
137 static const char * const swr_tx_clk_groups[] = { "gpio0" };
138 static const char * const swr_tx_data_groups[] = { "gpio1", "gpio2", "gpio14" };
139 static const char * const swr_rx_clk_groups[] = { "gpio3" };
140 static const char * const swr_rx_data_groups[] = { "gpio4", "gpio5", "gpio15" };
141 static const char * const wsa_swr_clk_groups[] = { "gpio10" };
142 static const char * const wsa_swr_data_groups[] = { "gpio11" };
143 static const char * const wsa2_swr_clk_groups[] = { "gpio15" };
144 static const char * const wsa2_swr_data_groups[] = { "gpio16" };
145 static const char * const ext_mclk1_c_groups[] = { "gpio5" };
146 static const char * const ext_mclk1_b_groups[] = { "gpio9" };
147 static const char * const ext_mclk1_a_groups[] = { "gpio13" };
148 static const char * const ext_mclk1_d_groups[] = { "gpio14" };
149 static const char * const ext_mclk1_e_groups[] = { "gpio22" };
150 
151 static const struct lpi_pingroup sm8550_groups[] = {
152 	LPI_PINGROUP(0, 0, swr_tx_clk, i2s0_clk, _, _),
153 	LPI_PINGROUP(1, 2, swr_tx_data, i2s0_ws, _, _),
154 	LPI_PINGROUP(2, 4, swr_tx_data, i2s0_data, _, _),
155 	LPI_PINGROUP(3, 8, swr_rx_clk, i2s0_data, _, _),
156 	LPI_PINGROUP(4, 10, swr_rx_data, i2s0_data, _, _),
157 	LPI_PINGROUP(5, 12, swr_rx_data, ext_mclk1_c, i2s0_data, _),
158 	LPI_PINGROUP(6, LPI_NO_SLEW, dmic1_clk, i2s1_clk, _,  _),
159 	LPI_PINGROUP(7, LPI_NO_SLEW, dmic1_data, i2s1_ws, _, _),
160 	LPI_PINGROUP(8, LPI_NO_SLEW, dmic2_clk, i2s1_data, _, _),
161 	LPI_PINGROUP(9, LPI_NO_SLEW, dmic2_data, i2s1_data, ext_mclk1_b, _),
162 	LPI_PINGROUP(10, 16, i2s2_clk, wsa_swr_clk, _, _),
163 	LPI_PINGROUP(11, 18, i2s2_ws, wsa_swr_data, _, _),
164 	LPI_PINGROUP(12, LPI_NO_SLEW, dmic3_clk, i2s3_clk, _, _),
165 	LPI_PINGROUP(13, LPI_NO_SLEW, dmic3_data, i2s3_ws, ext_mclk1_a, _),
166 	LPI_PINGROUP(14, 6, swr_tx_data, ext_mclk1_d, _, _),
167 	LPI_PINGROUP(15, 20, i2s2_data, wsa2_swr_clk, _, _),
168 	LPI_PINGROUP(16, 22, i2s2_data, wsa2_swr_data, _, _),
169 	LPI_PINGROUP(17, LPI_NO_SLEW, dmic4_clk, i2s3_data, _, _),
170 	LPI_PINGROUP(18, LPI_NO_SLEW, dmic4_data, i2s3_data, _, _),
171 	LPI_PINGROUP(19, LPI_NO_SLEW, i2s4_clk, slimbus_clk, _, _),
172 	LPI_PINGROUP(20, LPI_NO_SLEW, i2s4_ws, slimbus_data, _, _),
173 	LPI_PINGROUP(21, LPI_NO_SLEW, i2s4_data, _, _, _),
174 	LPI_PINGROUP(22, LPI_NO_SLEW, i2s4_data, ext_mclk1_e, _, _),
175 };
176 
177 static const struct lpi_function sm8550_functions[] = {
178 	LPI_FUNCTION(gpio),
179 	LPI_FUNCTION(dmic1_clk),
180 	LPI_FUNCTION(dmic1_data),
181 	LPI_FUNCTION(dmic2_clk),
182 	LPI_FUNCTION(dmic2_data),
183 	LPI_FUNCTION(dmic3_clk),
184 	LPI_FUNCTION(dmic3_data),
185 	LPI_FUNCTION(dmic4_clk),
186 	LPI_FUNCTION(dmic4_data),
187 	LPI_FUNCTION(i2s0_clk),
188 	LPI_FUNCTION(i2s0_data),
189 	LPI_FUNCTION(i2s0_ws),
190 	LPI_FUNCTION(i2s1_clk),
191 	LPI_FUNCTION(i2s1_data),
192 	LPI_FUNCTION(i2s1_ws),
193 	LPI_FUNCTION(i2s2_clk),
194 	LPI_FUNCTION(i2s2_data),
195 	LPI_FUNCTION(i2s2_ws),
196 	LPI_FUNCTION(i2s3_clk),
197 	LPI_FUNCTION(i2s3_data),
198 	LPI_FUNCTION(i2s3_ws),
199 	LPI_FUNCTION(i2s4_clk),
200 	LPI_FUNCTION(i2s4_data),
201 	LPI_FUNCTION(i2s4_ws),
202 	LPI_FUNCTION(slimbus_clk),
203 	LPI_FUNCTION(slimbus_data),
204 	LPI_FUNCTION(swr_rx_clk),
205 	LPI_FUNCTION(swr_rx_data),
206 	LPI_FUNCTION(swr_tx_clk),
207 	LPI_FUNCTION(swr_tx_data),
208 	LPI_FUNCTION(wsa_swr_clk),
209 	LPI_FUNCTION(wsa_swr_data),
210 	LPI_FUNCTION(wsa2_swr_clk),
211 	LPI_FUNCTION(wsa2_swr_data),
212 	LPI_FUNCTION(ext_mclk1_a),
213 	LPI_FUNCTION(ext_mclk1_b),
214 	LPI_FUNCTION(ext_mclk1_c),
215 	LPI_FUNCTION(ext_mclk1_d),
216 	LPI_FUNCTION(ext_mclk1_e),
217 };
218 
219 static const struct lpi_pinctrl_variant_data sm8550_lpi_data = {
220 	.pins = sm8550_lpi_pins,
221 	.npins = ARRAY_SIZE(sm8550_lpi_pins),
222 	.groups = sm8550_groups,
223 	.ngroups = ARRAY_SIZE(sm8550_groups),
224 	.functions = sm8550_functions,
225 	.nfunctions = ARRAY_SIZE(sm8550_functions),
226 };
227 
228 static const struct of_device_id lpi_pinctrl_of_match[] = {
229 	{
230 	       .compatible = "qcom,sm8550-lpass-lpi-pinctrl",
231 	       .data = &sm8550_lpi_data,
232 	},
233 	{ }
234 };
235 MODULE_DEVICE_TABLE(of, lpi_pinctrl_of_match);
236 
237 static struct platform_driver lpi_pinctrl_driver = {
238 	.driver = {
239 		   .name = "qcom-sm8550-lpass-lpi-pinctrl",
240 		   .of_match_table = lpi_pinctrl_of_match,
241 	},
242 	.probe = lpi_pinctrl_probe,
243 	.remove = lpi_pinctrl_remove,
244 };
245 
246 module_platform_driver(lpi_pinctrl_driver);
247 MODULE_DESCRIPTION("Qualcomm SM8550 LPI GPIO pin control driver");
248 MODULE_LICENSE("GPL");
249