blob: 4b847906b711fdf76a73ad4d29081b8b16b9cd50 [file] [log] [blame]
Thomas Gleixneraf873fc2019-05-28 09:57:21 -07001// SPDX-License-Identifier: GPL-2.0-only
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002/*
3 * Ingenic SoCs pinctrl driver
4 *
5 * Copyright (c) 2017 Paul Cercueil <paul@crapouillou.net>
周琰杰 (Zhou Yanjie)d7da2a12019-12-16 00:21:04 +08006 * Copyright (c) 2019 周琰杰 (Zhou Yanjie) <zhouyanjie@wanyeetech.com>
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02007 */
8
9#include <linux/compiler.h>
Linus Walleij28d6eeb2018-08-29 13:39:54 +020010#include <linux/gpio/driver.h>
Paul Cercueilb5c23aa2017-05-12 18:52:56 +020011#include <linux/interrupt.h>
12#include <linux/io.h>
13#include <linux/of_device.h>
Paul Cercueile72394e2018-08-21 18:42:32 +020014#include <linux/of_irq.h>
Paul Cercueilb5c23aa2017-05-12 18:52:56 +020015#include <linux/of_platform.h>
16#include <linux/pinctrl/pinctrl.h>
17#include <linux/pinctrl/pinmux.h>
18#include <linux/pinctrl/pinconf.h>
19#include <linux/pinctrl/pinconf-generic.h>
20#include <linux/platform_device.h>
21#include <linux/regmap.h>
22#include <linux/slab.h>
23
24#include "core.h"
25#include "pinconf.h"
26#include "pinmux.h"
27
Paul Cercueile72394e2018-08-21 18:42:32 +020028#define GPIO_PIN 0x00
29#define GPIO_MSK 0x20
30
Paul Cercueilb5c23aa2017-05-12 18:52:56 +020031#define JZ4740_GPIO_DATA 0x10
32#define JZ4740_GPIO_PULL_DIS 0x30
33#define JZ4740_GPIO_FUNC 0x40
34#define JZ4740_GPIO_SELECT 0x50
35#define JZ4740_GPIO_DIR 0x60
36#define JZ4740_GPIO_TRIG 0x70
37#define JZ4740_GPIO_FLAG 0x80
38
Zhou Yanjie0257595a2019-07-14 11:53:52 +080039#define JZ4760_GPIO_INT 0x10
40#define JZ4760_GPIO_PAT1 0x30
41#define JZ4760_GPIO_PAT0 0x40
42#define JZ4760_GPIO_FLAG 0x50
43#define JZ4760_GPIO_PEN 0x70
Paul Cercueilb5c23aa2017-05-12 18:52:56 +020044
周琰杰 (Zhou Yanjie)d7da2a12019-12-16 00:21:04 +080045#define X1830_GPIO_PEL 0x110
46#define X1830_GPIO_PEH 0x120
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +080047
Paul Cercueilb5c23aa2017-05-12 18:52:56 +020048#define REG_SET(x) ((x) + 0x4)
49#define REG_CLEAR(x) ((x) + 0x8)
50
周琰杰 (Zhou Yanjie)d7da2a12019-12-16 00:21:04 +080051#define REG_PZ_BASE(x) ((x) * 7)
52#define REG_PZ_GID2LD(x) ((x) * 7 + 0xf0)
53
54#define GPIO_PULL_DIS 0
55#define GPIO_PULL_UP 1
56#define GPIO_PULL_DOWN 2
57
Paul Cercueilb5c23aa2017-05-12 18:52:56 +020058#define PINS_PER_GPIO_CHIP 32
59
60enum jz_version {
61 ID_JZ4740,
Paul Cercueilf2a96762018-08-21 18:42:34 +020062 ID_JZ4725B,
Zhou Yanjie0257595a2019-07-14 11:53:52 +080063 ID_JZ4760,
64 ID_JZ4760B,
Paul Cercueilb5c23aa2017-05-12 18:52:56 +020065 ID_JZ4770,
66 ID_JZ4780,
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +080067 ID_X1000,
68 ID_X1000E,
Zhou Yanjie5d215952019-07-14 11:53:56 +080069 ID_X1500,
周琰杰 (Zhou Yanjie)d7da2a12019-12-16 00:21:04 +080070 ID_X1830,
Paul Cercueilb5c23aa2017-05-12 18:52:56 +020071};
72
73struct ingenic_chip_info {
74 unsigned int num_chips;
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +080075 unsigned int reg_offset;
Paul Cercueilb5c23aa2017-05-12 18:52:56 +020076
77 const struct group_desc *groups;
78 unsigned int num_groups;
79
80 const struct function_desc *functions;
81 unsigned int num_functions;
82
83 const u32 *pull_ups, *pull_downs;
84};
85
86struct ingenic_pinctrl {
87 struct device *dev;
88 struct regmap *map;
89 struct pinctrl_dev *pctl;
90 struct pinctrl_pin_desc *pdesc;
91 enum jz_version version;
92
93 const struct ingenic_chip_info *info;
94};
95
Paul Cercueile72394e2018-08-21 18:42:32 +020096struct ingenic_gpio_chip {
97 struct ingenic_pinctrl *jzpc;
98 struct gpio_chip gc;
99 struct irq_chip irq_chip;
100 unsigned int irq, reg_base;
101};
102
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200103static const u32 jz4740_pull_ups[4] = {
104 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
105};
106
107static const u32 jz4740_pull_downs[4] = {
108 0x00000000, 0x00000000, 0x00000000, 0x00000000,
109};
110
111static int jz4740_mmc_1bit_pins[] = { 0x69, 0x68, 0x6a, };
112static int jz4740_mmc_4bit_pins[] = { 0x6b, 0x6c, 0x6d, };
113static int jz4740_uart0_data_pins[] = { 0x7a, 0x79, };
114static int jz4740_uart0_hwflow_pins[] = { 0x7e, 0x7f, };
115static int jz4740_uart1_data_pins[] = { 0x7e, 0x7f, };
116static int jz4740_lcd_8bit_pins[] = {
117 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x52, 0x53, 0x54,
118};
119static int jz4740_lcd_16bit_pins[] = {
120 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x55,
121};
122static int jz4740_lcd_18bit_pins[] = { 0x50, 0x51, };
123static int jz4740_lcd_18bit_tft_pins[] = { 0x56, 0x57, 0x31, 0x32, };
124static int jz4740_nand_cs1_pins[] = { 0x39, };
125static int jz4740_nand_cs2_pins[] = { 0x3a, };
126static int jz4740_nand_cs3_pins[] = { 0x3b, };
127static int jz4740_nand_cs4_pins[] = { 0x3c, };
128static int jz4740_pwm_pwm0_pins[] = { 0x77, };
129static int jz4740_pwm_pwm1_pins[] = { 0x78, };
130static int jz4740_pwm_pwm2_pins[] = { 0x79, };
131static int jz4740_pwm_pwm3_pins[] = { 0x7a, };
132static int jz4740_pwm_pwm4_pins[] = { 0x7b, };
133static int jz4740_pwm_pwm5_pins[] = { 0x7c, };
134static int jz4740_pwm_pwm6_pins[] = { 0x7e, };
135static int jz4740_pwm_pwm7_pins[] = { 0x7f, };
136
137static int jz4740_mmc_1bit_funcs[] = { 0, 0, 0, };
138static int jz4740_mmc_4bit_funcs[] = { 0, 0, 0, };
139static int jz4740_uart0_data_funcs[] = { 1, 1, };
140static int jz4740_uart0_hwflow_funcs[] = { 1, 1, };
141static int jz4740_uart1_data_funcs[] = { 2, 2, };
142static int jz4740_lcd_8bit_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
143static int jz4740_lcd_16bit_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, };
144static int jz4740_lcd_18bit_funcs[] = { 0, 0, };
145static int jz4740_lcd_18bit_tft_funcs[] = { 0, 0, 0, 0, };
146static int jz4740_nand_cs1_funcs[] = { 0, };
147static int jz4740_nand_cs2_funcs[] = { 0, };
148static int jz4740_nand_cs3_funcs[] = { 0, };
149static int jz4740_nand_cs4_funcs[] = { 0, };
150static int jz4740_pwm_pwm0_funcs[] = { 0, };
151static int jz4740_pwm_pwm1_funcs[] = { 0, };
152static int jz4740_pwm_pwm2_funcs[] = { 0, };
153static int jz4740_pwm_pwm3_funcs[] = { 0, };
154static int jz4740_pwm_pwm4_funcs[] = { 0, };
155static int jz4740_pwm_pwm5_funcs[] = { 0, };
156static int jz4740_pwm_pwm6_funcs[] = { 0, };
157static int jz4740_pwm_pwm7_funcs[] = { 0, };
158
159#define INGENIC_PIN_GROUP(name, id) \
160 { \
161 name, \
162 id##_pins, \
163 ARRAY_SIZE(id##_pins), \
164 id##_funcs, \
165 }
166
167static const struct group_desc jz4740_groups[] = {
168 INGENIC_PIN_GROUP("mmc-1bit", jz4740_mmc_1bit),
169 INGENIC_PIN_GROUP("mmc-4bit", jz4740_mmc_4bit),
170 INGENIC_PIN_GROUP("uart0-data", jz4740_uart0_data),
171 INGENIC_PIN_GROUP("uart0-hwflow", jz4740_uart0_hwflow),
172 INGENIC_PIN_GROUP("uart1-data", jz4740_uart1_data),
173 INGENIC_PIN_GROUP("lcd-8bit", jz4740_lcd_8bit),
174 INGENIC_PIN_GROUP("lcd-16bit", jz4740_lcd_16bit),
175 INGENIC_PIN_GROUP("lcd-18bit", jz4740_lcd_18bit),
176 INGENIC_PIN_GROUP("lcd-18bit-tft", jz4740_lcd_18bit_tft),
177 { "lcd-no-pins", },
178 INGENIC_PIN_GROUP("nand-cs1", jz4740_nand_cs1),
179 INGENIC_PIN_GROUP("nand-cs2", jz4740_nand_cs2),
180 INGENIC_PIN_GROUP("nand-cs3", jz4740_nand_cs3),
181 INGENIC_PIN_GROUP("nand-cs4", jz4740_nand_cs4),
182 INGENIC_PIN_GROUP("pwm0", jz4740_pwm_pwm0),
183 INGENIC_PIN_GROUP("pwm1", jz4740_pwm_pwm1),
184 INGENIC_PIN_GROUP("pwm2", jz4740_pwm_pwm2),
185 INGENIC_PIN_GROUP("pwm3", jz4740_pwm_pwm3),
186 INGENIC_PIN_GROUP("pwm4", jz4740_pwm_pwm4),
187 INGENIC_PIN_GROUP("pwm5", jz4740_pwm_pwm5),
188 INGENIC_PIN_GROUP("pwm6", jz4740_pwm_pwm6),
189 INGENIC_PIN_GROUP("pwm7", jz4740_pwm_pwm7),
190};
191
192static const char *jz4740_mmc_groups[] = { "mmc-1bit", "mmc-4bit", };
193static const char *jz4740_uart0_groups[] = { "uart0-data", "uart0-hwflow", };
194static const char *jz4740_uart1_groups[] = { "uart1-data", };
195static const char *jz4740_lcd_groups[] = {
196 "lcd-8bit", "lcd-16bit", "lcd-18bit", "lcd-18bit-tft", "lcd-no-pins",
197};
198static const char *jz4740_nand_groups[] = {
199 "nand-cs1", "nand-cs2", "nand-cs3", "nand-cs4",
200};
201static const char *jz4740_pwm0_groups[] = { "pwm0", };
202static const char *jz4740_pwm1_groups[] = { "pwm1", };
203static const char *jz4740_pwm2_groups[] = { "pwm2", };
204static const char *jz4740_pwm3_groups[] = { "pwm3", };
205static const char *jz4740_pwm4_groups[] = { "pwm4", };
206static const char *jz4740_pwm5_groups[] = { "pwm5", };
207static const char *jz4740_pwm6_groups[] = { "pwm6", };
208static const char *jz4740_pwm7_groups[] = { "pwm7", };
209
210static const struct function_desc jz4740_functions[] = {
211 { "mmc", jz4740_mmc_groups, ARRAY_SIZE(jz4740_mmc_groups), },
212 { "uart0", jz4740_uart0_groups, ARRAY_SIZE(jz4740_uart0_groups), },
213 { "uart1", jz4740_uart1_groups, ARRAY_SIZE(jz4740_uart1_groups), },
214 { "lcd", jz4740_lcd_groups, ARRAY_SIZE(jz4740_lcd_groups), },
215 { "nand", jz4740_nand_groups, ARRAY_SIZE(jz4740_nand_groups), },
216 { "pwm0", jz4740_pwm0_groups, ARRAY_SIZE(jz4740_pwm0_groups), },
217 { "pwm1", jz4740_pwm1_groups, ARRAY_SIZE(jz4740_pwm1_groups), },
218 { "pwm2", jz4740_pwm2_groups, ARRAY_SIZE(jz4740_pwm2_groups), },
219 { "pwm3", jz4740_pwm3_groups, ARRAY_SIZE(jz4740_pwm3_groups), },
220 { "pwm4", jz4740_pwm4_groups, ARRAY_SIZE(jz4740_pwm4_groups), },
221 { "pwm5", jz4740_pwm5_groups, ARRAY_SIZE(jz4740_pwm5_groups), },
222 { "pwm6", jz4740_pwm6_groups, ARRAY_SIZE(jz4740_pwm6_groups), },
223 { "pwm7", jz4740_pwm7_groups, ARRAY_SIZE(jz4740_pwm7_groups), },
224};
225
226static const struct ingenic_chip_info jz4740_chip_info = {
227 .num_chips = 4,
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +0800228 .reg_offset = 0x100,
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200229 .groups = jz4740_groups,
230 .num_groups = ARRAY_SIZE(jz4740_groups),
231 .functions = jz4740_functions,
232 .num_functions = ARRAY_SIZE(jz4740_functions),
233 .pull_ups = jz4740_pull_ups,
234 .pull_downs = jz4740_pull_downs,
235};
236
Paul Cercueilf2a96762018-08-21 18:42:34 +0200237static int jz4725b_mmc0_1bit_pins[] = { 0x48, 0x49, 0x5c, };
238static int jz4725b_mmc0_4bit_pins[] = { 0x5d, 0x5b, 0x56, };
239static int jz4725b_mmc1_1bit_pins[] = { 0x7a, 0x7b, 0x7c, };
240static int jz4725b_mmc1_4bit_pins[] = { 0x7d, 0x7e, 0x7f, };
241static int jz4725b_uart_data_pins[] = { 0x4c, 0x4d, };
242static int jz4725b_nand_cs1_pins[] = { 0x55, };
243static int jz4725b_nand_cs2_pins[] = { 0x56, };
244static int jz4725b_nand_cs3_pins[] = { 0x57, };
245static int jz4725b_nand_cs4_pins[] = { 0x58, };
246static int jz4725b_nand_cle_ale_pins[] = { 0x48, 0x49 };
247static int jz4725b_nand_fre_fwe_pins[] = { 0x5c, 0x5d };
248static int jz4725b_pwm_pwm0_pins[] = { 0x4a, };
249static int jz4725b_pwm_pwm1_pins[] = { 0x4b, };
250static int jz4725b_pwm_pwm2_pins[] = { 0x4c, };
251static int jz4725b_pwm_pwm3_pins[] = { 0x4d, };
252static int jz4725b_pwm_pwm4_pins[] = { 0x4e, };
253static int jz4725b_pwm_pwm5_pins[] = { 0x4f, };
Paul Cercueila3240f02019-02-07 10:55:36 -0300254static int jz4725b_lcd_8bit_pins[] = {
255 0x72, 0x73, 0x74,
256 0x60, 0x61, 0x62, 0x63,
257 0x64, 0x65, 0x66, 0x67,
258};
259static int jz4725b_lcd_16bit_pins[] = {
260 0x68, 0x69, 0x6a, 0x6b,
261 0x6c, 0x6d, 0x6e, 0x6f,
262};
263static int jz4725b_lcd_18bit_pins[] = { 0x70, 0x71, };
264static int jz4725b_lcd_24bit_pins[] = { 0x76, 0x77, 0x78, 0x79, };
265static int jz4725b_lcd_special_pins[] = { 0x76, 0x77, 0x78, 0x79, };
266static int jz4725b_lcd_generic_pins[] = { 0x75, };
Paul Cercueilf2a96762018-08-21 18:42:34 +0200267
268static int jz4725b_mmc0_1bit_funcs[] = { 1, 1, 1, };
269static int jz4725b_mmc0_4bit_funcs[] = { 1, 0, 1, };
270static int jz4725b_mmc1_1bit_funcs[] = { 0, 0, 0, };
271static int jz4725b_mmc1_4bit_funcs[] = { 0, 0, 0, };
272static int jz4725b_uart_data_funcs[] = { 1, 1, };
273static int jz4725b_nand_cs1_funcs[] = { 0, };
274static int jz4725b_nand_cs2_funcs[] = { 0, };
275static int jz4725b_nand_cs3_funcs[] = { 0, };
276static int jz4725b_nand_cs4_funcs[] = { 0, };
277static int jz4725b_nand_cle_ale_funcs[] = { 0, 0, };
278static int jz4725b_nand_fre_fwe_funcs[] = { 0, 0, };
279static int jz4725b_pwm_pwm0_funcs[] = { 0, };
280static int jz4725b_pwm_pwm1_funcs[] = { 0, };
281static int jz4725b_pwm_pwm2_funcs[] = { 0, };
282static int jz4725b_pwm_pwm3_funcs[] = { 0, };
283static int jz4725b_pwm_pwm4_funcs[] = { 0, };
284static int jz4725b_pwm_pwm5_funcs[] = { 0, };
Paul Cercueila3240f02019-02-07 10:55:36 -0300285static int jz4725b_lcd_8bit_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
286static int jz4725b_lcd_16bit_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, };
287static int jz4725b_lcd_18bit_funcs[] = { 0, 0, };
288static int jz4725b_lcd_24bit_funcs[] = { 1, 1, 1, 1, };
289static int jz4725b_lcd_special_funcs[] = { 0, 0, 0, 0, };
290static int jz4725b_lcd_generic_funcs[] = { 0, };
Paul Cercueilf2a96762018-08-21 18:42:34 +0200291
292static const struct group_desc jz4725b_groups[] = {
293 INGENIC_PIN_GROUP("mmc0-1bit", jz4725b_mmc0_1bit),
294 INGENIC_PIN_GROUP("mmc0-4bit", jz4725b_mmc0_4bit),
295 INGENIC_PIN_GROUP("mmc1-1bit", jz4725b_mmc1_1bit),
296 INGENIC_PIN_GROUP("mmc1-4bit", jz4725b_mmc1_4bit),
297 INGENIC_PIN_GROUP("uart-data", jz4725b_uart_data),
298 INGENIC_PIN_GROUP("nand-cs1", jz4725b_nand_cs1),
299 INGENIC_PIN_GROUP("nand-cs2", jz4725b_nand_cs2),
300 INGENIC_PIN_GROUP("nand-cs3", jz4725b_nand_cs3),
301 INGENIC_PIN_GROUP("nand-cs4", jz4725b_nand_cs4),
302 INGENIC_PIN_GROUP("nand-cle-ale", jz4725b_nand_cle_ale),
303 INGENIC_PIN_GROUP("nand-fre-fwe", jz4725b_nand_fre_fwe),
304 INGENIC_PIN_GROUP("pwm0", jz4725b_pwm_pwm0),
305 INGENIC_PIN_GROUP("pwm1", jz4725b_pwm_pwm1),
306 INGENIC_PIN_GROUP("pwm2", jz4725b_pwm_pwm2),
307 INGENIC_PIN_GROUP("pwm3", jz4725b_pwm_pwm3),
308 INGENIC_PIN_GROUP("pwm4", jz4725b_pwm_pwm4),
309 INGENIC_PIN_GROUP("pwm5", jz4725b_pwm_pwm5),
Paul Cercueila3240f02019-02-07 10:55:36 -0300310 INGENIC_PIN_GROUP("lcd-8bit", jz4725b_lcd_8bit),
311 INGENIC_PIN_GROUP("lcd-16bit", jz4725b_lcd_16bit),
312 INGENIC_PIN_GROUP("lcd-18bit", jz4725b_lcd_18bit),
313 INGENIC_PIN_GROUP("lcd-24bit", jz4725b_lcd_24bit),
314 INGENIC_PIN_GROUP("lcd-special", jz4725b_lcd_special),
315 INGENIC_PIN_GROUP("lcd-generic", jz4725b_lcd_generic),
Paul Cercueilf2a96762018-08-21 18:42:34 +0200316};
317
318static const char *jz4725b_mmc0_groups[] = { "mmc0-1bit", "mmc0-4bit", };
319static const char *jz4725b_mmc1_groups[] = { "mmc1-1bit", "mmc1-4bit", };
320static const char *jz4725b_uart_groups[] = { "uart-data", };
321static const char *jz4725b_nand_groups[] = {
322 "nand-cs1", "nand-cs2", "nand-cs3", "nand-cs4",
323 "nand-cle-ale", "nand-fre-fwe",
324};
325static const char *jz4725b_pwm0_groups[] = { "pwm0", };
326static const char *jz4725b_pwm1_groups[] = { "pwm1", };
327static const char *jz4725b_pwm2_groups[] = { "pwm2", };
328static const char *jz4725b_pwm3_groups[] = { "pwm3", };
329static const char *jz4725b_pwm4_groups[] = { "pwm4", };
330static const char *jz4725b_pwm5_groups[] = { "pwm5", };
Paul Cercueila3240f02019-02-07 10:55:36 -0300331static const char *jz4725b_lcd_groups[] = {
332 "lcd-8bit", "lcd-16bit", "lcd-18bit", "lcd-24bit",
333 "lcd-special", "lcd-generic",
334};
Paul Cercueilf2a96762018-08-21 18:42:34 +0200335
336static const struct function_desc jz4725b_functions[] = {
337 { "mmc0", jz4725b_mmc0_groups, ARRAY_SIZE(jz4725b_mmc0_groups), },
338 { "mmc1", jz4725b_mmc1_groups, ARRAY_SIZE(jz4725b_mmc1_groups), },
339 { "uart", jz4725b_uart_groups, ARRAY_SIZE(jz4725b_uart_groups), },
340 { "nand", jz4725b_nand_groups, ARRAY_SIZE(jz4725b_nand_groups), },
341 { "pwm0", jz4725b_pwm0_groups, ARRAY_SIZE(jz4725b_pwm0_groups), },
342 { "pwm1", jz4725b_pwm1_groups, ARRAY_SIZE(jz4725b_pwm1_groups), },
343 { "pwm2", jz4725b_pwm2_groups, ARRAY_SIZE(jz4725b_pwm2_groups), },
344 { "pwm3", jz4725b_pwm3_groups, ARRAY_SIZE(jz4725b_pwm3_groups), },
345 { "pwm4", jz4725b_pwm4_groups, ARRAY_SIZE(jz4725b_pwm4_groups), },
346 { "pwm5", jz4725b_pwm5_groups, ARRAY_SIZE(jz4725b_pwm5_groups), },
Paul Cercueila3240f02019-02-07 10:55:36 -0300347 { "lcd", jz4725b_lcd_groups, ARRAY_SIZE(jz4725b_lcd_groups), },
Paul Cercueilf2a96762018-08-21 18:42:34 +0200348};
349
350static const struct ingenic_chip_info jz4725b_chip_info = {
351 .num_chips = 4,
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +0800352 .reg_offset = 0x100,
Paul Cercueilf2a96762018-08-21 18:42:34 +0200353 .groups = jz4725b_groups,
354 .num_groups = ARRAY_SIZE(jz4725b_groups),
355 .functions = jz4725b_functions,
356 .num_functions = ARRAY_SIZE(jz4725b_functions),
357 .pull_ups = jz4740_pull_ups,
358 .pull_downs = jz4740_pull_downs,
359};
360
Zhou Yanjie0257595a2019-07-14 11:53:52 +0800361static const u32 jz4760_pull_ups[6] = {
362 0xffffffff, 0xfffcf3ff, 0xffffffff, 0xffffcfff, 0xfffffb7c, 0xfffff00f,
363};
364
365static const u32 jz4760_pull_downs[6] = {
366 0x00000000, 0x00030c00, 0x00000000, 0x00003000, 0x00000483, 0x00000ff0,
367};
368
369static int jz4760_uart0_data_pins[] = { 0xa0, 0xa3, };
370static int jz4760_uart0_hwflow_pins[] = { 0xa1, 0xa2, };
371static int jz4760_uart1_data_pins[] = { 0x7a, 0x7c, };
372static int jz4760_uart1_hwflow_pins[] = { 0x7b, 0x7d, };
373static int jz4760_uart2_data_pins[] = { 0x5c, 0x5e, };
374static int jz4760_uart2_hwflow_pins[] = { 0x5d, 0x5f, };
375static int jz4760_uart3_data_pins[] = { 0x6c, 0x85, };
376static int jz4760_uart3_hwflow_pins[] = { 0x88, 0x89, };
377static int jz4760_mmc0_1bit_a_pins[] = { 0x12, 0x13, 0x14, };
378static int jz4760_mmc0_4bit_a_pins[] = { 0x15, 0x16, 0x17, };
379static int jz4760_mmc0_1bit_e_pins[] = { 0x9c, 0x9d, 0x94, };
380static int jz4760_mmc0_4bit_e_pins[] = { 0x95, 0x96, 0x97, };
381static int jz4760_mmc0_8bit_e_pins[] = { 0x98, 0x99, 0x9a, 0x9b, };
382static int jz4760_mmc1_1bit_d_pins[] = { 0x78, 0x79, 0x74, };
383static int jz4760_mmc1_4bit_d_pins[] = { 0x75, 0x76, 0x77, };
384static int jz4760_mmc1_1bit_e_pins[] = { 0x9c, 0x9d, 0x94, };
385static int jz4760_mmc1_4bit_e_pins[] = { 0x95, 0x96, 0x97, };
386static int jz4760_mmc1_8bit_e_pins[] = { 0x98, 0x99, 0x9a, 0x9b, };
387static int jz4760_mmc2_1bit_b_pins[] = { 0x3c, 0x3d, 0x34, };
388static int jz4760_mmc2_4bit_b_pins[] = { 0x35, 0x3e, 0x3f, };
389static int jz4760_mmc2_1bit_e_pins[] = { 0x9c, 0x9d, 0x94, };
390static int jz4760_mmc2_4bit_e_pins[] = { 0x95, 0x96, 0x97, };
391static int jz4760_mmc2_8bit_e_pins[] = { 0x98, 0x99, 0x9a, 0x9b, };
392static int jz4760_nemc_8bit_data_pins[] = {
393 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
394};
395static int jz4760_nemc_16bit_data_pins[] = {
396 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
397};
398static int jz4760_nemc_cle_ale_pins[] = { 0x20, 0x21, };
399static int jz4760_nemc_addr_pins[] = { 0x22, 0x23, 0x24, 0x25, };
400static int jz4760_nemc_rd_we_pins[] = { 0x10, 0x11, };
401static int jz4760_nemc_frd_fwe_pins[] = { 0x12, 0x13, };
402static int jz4760_nemc_wait_pins[] = { 0x1b, };
403static int jz4760_nemc_cs1_pins[] = { 0x15, };
404static int jz4760_nemc_cs2_pins[] = { 0x16, };
405static int jz4760_nemc_cs3_pins[] = { 0x17, };
406static int jz4760_nemc_cs4_pins[] = { 0x18, };
407static int jz4760_nemc_cs5_pins[] = { 0x19, };
408static int jz4760_nemc_cs6_pins[] = { 0x1a, };
409static int jz4760_i2c0_pins[] = { 0x7e, 0x7f, };
410static int jz4760_i2c1_pins[] = { 0x9e, 0x9f, };
411static int jz4760_cim_pins[] = {
412 0x26, 0x27, 0x28, 0x29,
413 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31,
414};
415static int jz4760_lcd_24bit_pins[] = {
416 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
417 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
418 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
419 0x58, 0x59, 0x5a, 0x5b,
420};
421static int jz4760_pwm_pwm0_pins[] = { 0x80, };
422static int jz4760_pwm_pwm1_pins[] = { 0x81, };
423static int jz4760_pwm_pwm2_pins[] = { 0x82, };
424static int jz4760_pwm_pwm3_pins[] = { 0x83, };
425static int jz4760_pwm_pwm4_pins[] = { 0x84, };
426static int jz4760_pwm_pwm5_pins[] = { 0x85, };
427static int jz4760_pwm_pwm6_pins[] = { 0x6a, };
428static int jz4760_pwm_pwm7_pins[] = { 0x6b, };
429
430static int jz4760_uart0_data_funcs[] = { 0, 0, };
431static int jz4760_uart0_hwflow_funcs[] = { 0, 0, };
432static int jz4760_uart1_data_funcs[] = { 0, 0, };
433static int jz4760_uart1_hwflow_funcs[] = { 0, 0, };
434static int jz4760_uart2_data_funcs[] = { 0, 0, };
435static int jz4760_uart2_hwflow_funcs[] = { 0, 0, };
436static int jz4760_uart3_data_funcs[] = { 0, 1, };
437static int jz4760_uart3_hwflow_funcs[] = { 0, 0, };
438static int jz4760_mmc0_1bit_a_funcs[] = { 1, 1, 0, };
439static int jz4760_mmc0_4bit_a_funcs[] = { 1, 1, 1, };
440static int jz4760_mmc0_1bit_e_funcs[] = { 0, 0, 0, };
441static int jz4760_mmc0_4bit_e_funcs[] = { 0, 0, 0, };
442static int jz4760_mmc0_8bit_e_funcs[] = { 0, 0, 0, 0, };
443static int jz4760_mmc1_1bit_d_funcs[] = { 0, 0, 0, };
444static int jz4760_mmc1_4bit_d_funcs[] = { 0, 0, 0, };
445static int jz4760_mmc1_1bit_e_funcs[] = { 1, 1, 1, };
446static int jz4760_mmc1_4bit_e_funcs[] = { 1, 1, 1, };
447static int jz4760_mmc1_8bit_e_funcs[] = { 1, 1, 1, 1, };
448static int jz4760_mmc2_1bit_b_funcs[] = { 0, 0, 0, };
449static int jz4760_mmc2_4bit_b_funcs[] = { 0, 0, 0, };
450static int jz4760_mmc2_1bit_e_funcs[] = { 2, 2, 2, };
451static int jz4760_mmc2_4bit_e_funcs[] = { 2, 2, 2, };
452static int jz4760_mmc2_8bit_e_funcs[] = { 2, 2, 2, 2, };
453static int jz4760_nemc_8bit_data_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, };
454static int jz4760_nemc_16bit_data_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, };
455static int jz4760_nemc_cle_ale_funcs[] = { 0, 0, };
456static int jz4760_nemc_addr_funcs[] = { 0, 0, 0, 0, };
457static int jz4760_nemc_rd_we_funcs[] = { 0, 0, };
458static int jz4760_nemc_frd_fwe_funcs[] = { 0, 0, };
459static int jz4760_nemc_wait_funcs[] = { 0, };
460static int jz4760_nemc_cs1_funcs[] = { 0, };
461static int jz4760_nemc_cs2_funcs[] = { 0, };
462static int jz4760_nemc_cs3_funcs[] = { 0, };
463static int jz4760_nemc_cs4_funcs[] = { 0, };
464static int jz4760_nemc_cs5_funcs[] = { 0, };
465static int jz4760_nemc_cs6_funcs[] = { 0, };
466static int jz4760_i2c0_funcs[] = { 0, 0, };
467static int jz4760_i2c1_funcs[] = { 0, 0, };
468static int jz4760_cim_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
469static int jz4760_lcd_24bit_funcs[] = {
470 0, 0, 0, 0, 0, 0, 0, 0,
471 0, 0, 0, 0, 0, 0, 0, 0,
472 0, 0, 0, 0, 0, 0, 0, 0,
473 0, 0, 0, 0,
474};
475static int jz4760_pwm_pwm0_funcs[] = { 0, };
476static int jz4760_pwm_pwm1_funcs[] = { 0, };
477static int jz4760_pwm_pwm2_funcs[] = { 0, };
478static int jz4760_pwm_pwm3_funcs[] = { 0, };
479static int jz4760_pwm_pwm4_funcs[] = { 0, };
480static int jz4760_pwm_pwm5_funcs[] = { 0, };
481static int jz4760_pwm_pwm6_funcs[] = { 0, };
482static int jz4760_pwm_pwm7_funcs[] = { 0, };
483
484static const struct group_desc jz4760_groups[] = {
485 INGENIC_PIN_GROUP("uart0-data", jz4760_uart0_data),
486 INGENIC_PIN_GROUP("uart0-hwflow", jz4760_uart0_hwflow),
487 INGENIC_PIN_GROUP("uart1-data", jz4760_uart1_data),
488 INGENIC_PIN_GROUP("uart1-hwflow", jz4760_uart1_hwflow),
489 INGENIC_PIN_GROUP("uart2-data", jz4760_uart2_data),
490 INGENIC_PIN_GROUP("uart2-hwflow", jz4760_uart2_hwflow),
491 INGENIC_PIN_GROUP("uart3-data", jz4760_uart3_data),
492 INGENIC_PIN_GROUP("uart3-hwflow", jz4760_uart3_hwflow),
493 INGENIC_PIN_GROUP("mmc0-1bit-a", jz4760_mmc0_1bit_a),
494 INGENIC_PIN_GROUP("mmc0-4bit-a", jz4760_mmc0_4bit_a),
495 INGENIC_PIN_GROUP("mmc0-1bit-e", jz4760_mmc0_1bit_e),
496 INGENIC_PIN_GROUP("mmc0-4bit-e", jz4760_mmc0_4bit_e),
497 INGENIC_PIN_GROUP("mmc0-8bit-e", jz4760_mmc0_8bit_e),
498 INGENIC_PIN_GROUP("mmc1-1bit-d", jz4760_mmc1_1bit_d),
499 INGENIC_PIN_GROUP("mmc1-4bit-d", jz4760_mmc1_4bit_d),
500 INGENIC_PIN_GROUP("mmc1-1bit-e", jz4760_mmc1_1bit_e),
501 INGENIC_PIN_GROUP("mmc1-4bit-e", jz4760_mmc1_4bit_e),
502 INGENIC_PIN_GROUP("mmc1-8bit-e", jz4760_mmc1_8bit_e),
503 INGENIC_PIN_GROUP("mmc2-1bit-b", jz4760_mmc2_1bit_b),
504 INGENIC_PIN_GROUP("mmc2-4bit-b", jz4760_mmc2_4bit_b),
505 INGENIC_PIN_GROUP("mmc2-1bit-e", jz4760_mmc2_1bit_e),
506 INGENIC_PIN_GROUP("mmc2-4bit-e", jz4760_mmc2_4bit_e),
507 INGENIC_PIN_GROUP("mmc2-8bit-e", jz4760_mmc2_8bit_e),
508 INGENIC_PIN_GROUP("nemc-8bit-data", jz4760_nemc_8bit_data),
509 INGENIC_PIN_GROUP("nemc-16bit-data", jz4760_nemc_16bit_data),
510 INGENIC_PIN_GROUP("nemc-cle-ale", jz4760_nemc_cle_ale),
511 INGENIC_PIN_GROUP("nemc-addr", jz4760_nemc_addr),
512 INGENIC_PIN_GROUP("nemc-rd-we", jz4760_nemc_rd_we),
513 INGENIC_PIN_GROUP("nemc-frd-fwe", jz4760_nemc_frd_fwe),
514 INGENIC_PIN_GROUP("nemc-wait", jz4760_nemc_wait),
515 INGENIC_PIN_GROUP("nemc-cs1", jz4760_nemc_cs1),
516 INGENIC_PIN_GROUP("nemc-cs2", jz4760_nemc_cs2),
517 INGENIC_PIN_GROUP("nemc-cs3", jz4760_nemc_cs3),
518 INGENIC_PIN_GROUP("nemc-cs4", jz4760_nemc_cs4),
519 INGENIC_PIN_GROUP("nemc-cs5", jz4760_nemc_cs5),
520 INGENIC_PIN_GROUP("nemc-cs6", jz4760_nemc_cs6),
521 INGENIC_PIN_GROUP("i2c0-data", jz4760_i2c0),
522 INGENIC_PIN_GROUP("i2c1-data", jz4760_i2c1),
523 INGENIC_PIN_GROUP("cim-data", jz4760_cim),
524 INGENIC_PIN_GROUP("lcd-24bit", jz4760_lcd_24bit),
525 { "lcd-no-pins", },
526 INGENIC_PIN_GROUP("pwm0", jz4760_pwm_pwm0),
527 INGENIC_PIN_GROUP("pwm1", jz4760_pwm_pwm1),
528 INGENIC_PIN_GROUP("pwm2", jz4760_pwm_pwm2),
529 INGENIC_PIN_GROUP("pwm3", jz4760_pwm_pwm3),
530 INGENIC_PIN_GROUP("pwm4", jz4760_pwm_pwm4),
531 INGENIC_PIN_GROUP("pwm5", jz4760_pwm_pwm5),
532 INGENIC_PIN_GROUP("pwm6", jz4760_pwm_pwm6),
533 INGENIC_PIN_GROUP("pwm7", jz4760_pwm_pwm7),
534};
535
536static const char *jz4760_uart0_groups[] = { "uart0-data", "uart0-hwflow", };
537static const char *jz4760_uart1_groups[] = { "uart1-data", "uart1-hwflow", };
538static const char *jz4760_uart2_groups[] = { "uart2-data", "uart2-hwflow", };
539static const char *jz4760_uart3_groups[] = { "uart3-data", "uart3-hwflow", };
540static const char *jz4760_mmc0_groups[] = {
541 "mmc0-1bit-a", "mmc0-4bit-a",
542 "mmc0-1bit-e", "mmc0-4bit-e", "mmc0-8bit-e",
543};
544static const char *jz4760_mmc1_groups[] = {
545 "mmc1-1bit-d", "mmc1-4bit-d",
546 "mmc1-1bit-e", "mmc1-4bit-e", "mmc1-8bit-e",
547};
548static const char *jz4760_mmc2_groups[] = {
549 "mmc2-1bit-b", "mmc2-4bit-b",
550 "mmc2-1bit-e", "mmc2-4bit-e", "mmc2-8bit-e",
551};
552static const char *jz4760_nemc_groups[] = {
553 "nemc-8bit-data", "nemc-16bit-data", "nemc-cle-ale",
554 "nemc-addr", "nemc-rd-we", "nemc-frd-fwe", "nemc-wait",
555};
556static const char *jz4760_cs1_groups[] = { "nemc-cs1", };
557static const char *jz4760_cs2_groups[] = { "nemc-cs2", };
558static const char *jz4760_cs3_groups[] = { "nemc-cs3", };
559static const char *jz4760_cs4_groups[] = { "nemc-cs4", };
560static const char *jz4760_cs5_groups[] = { "nemc-cs5", };
561static const char *jz4760_cs6_groups[] = { "nemc-cs6", };
562static const char *jz4760_i2c0_groups[] = { "i2c0-data", };
563static const char *jz4760_i2c1_groups[] = { "i2c1-data", };
564static const char *jz4760_cim_groups[] = { "cim-data", };
565static const char *jz4760_lcd_groups[] = { "lcd-24bit", "lcd-no-pins", };
566static const char *jz4760_pwm0_groups[] = { "pwm0", };
567static const char *jz4760_pwm1_groups[] = { "pwm1", };
568static const char *jz4760_pwm2_groups[] = { "pwm2", };
569static const char *jz4760_pwm3_groups[] = { "pwm3", };
570static const char *jz4760_pwm4_groups[] = { "pwm4", };
571static const char *jz4760_pwm5_groups[] = { "pwm5", };
572static const char *jz4760_pwm6_groups[] = { "pwm6", };
573static const char *jz4760_pwm7_groups[] = { "pwm7", };
574
575static const struct function_desc jz4760_functions[] = {
576 { "uart0", jz4760_uart0_groups, ARRAY_SIZE(jz4760_uart0_groups), },
577 { "uart1", jz4760_uart1_groups, ARRAY_SIZE(jz4760_uart1_groups), },
578 { "uart2", jz4760_uart2_groups, ARRAY_SIZE(jz4760_uart2_groups), },
579 { "uart3", jz4760_uart3_groups, ARRAY_SIZE(jz4760_uart3_groups), },
580 { "mmc0", jz4760_mmc0_groups, ARRAY_SIZE(jz4760_mmc0_groups), },
581 { "mmc1", jz4760_mmc1_groups, ARRAY_SIZE(jz4760_mmc1_groups), },
582 { "mmc2", jz4760_mmc2_groups, ARRAY_SIZE(jz4760_mmc2_groups), },
583 { "nemc", jz4760_nemc_groups, ARRAY_SIZE(jz4760_nemc_groups), },
584 { "nemc-cs1", jz4760_cs1_groups, ARRAY_SIZE(jz4760_cs1_groups), },
585 { "nemc-cs2", jz4760_cs2_groups, ARRAY_SIZE(jz4760_cs2_groups), },
586 { "nemc-cs3", jz4760_cs3_groups, ARRAY_SIZE(jz4760_cs3_groups), },
587 { "nemc-cs4", jz4760_cs4_groups, ARRAY_SIZE(jz4760_cs4_groups), },
588 { "nemc-cs5", jz4760_cs5_groups, ARRAY_SIZE(jz4760_cs5_groups), },
589 { "nemc-cs6", jz4760_cs6_groups, ARRAY_SIZE(jz4760_cs6_groups), },
590 { "i2c0", jz4760_i2c0_groups, ARRAY_SIZE(jz4760_i2c0_groups), },
591 { "i2c1", jz4760_i2c1_groups, ARRAY_SIZE(jz4760_i2c1_groups), },
592 { "cim", jz4760_cim_groups, ARRAY_SIZE(jz4760_cim_groups), },
593 { "lcd", jz4760_lcd_groups, ARRAY_SIZE(jz4760_lcd_groups), },
594 { "pwm0", jz4760_pwm0_groups, ARRAY_SIZE(jz4760_pwm0_groups), },
595 { "pwm1", jz4760_pwm1_groups, ARRAY_SIZE(jz4760_pwm1_groups), },
596 { "pwm2", jz4760_pwm2_groups, ARRAY_SIZE(jz4760_pwm2_groups), },
597 { "pwm3", jz4760_pwm3_groups, ARRAY_SIZE(jz4760_pwm3_groups), },
598 { "pwm4", jz4760_pwm4_groups, ARRAY_SIZE(jz4760_pwm4_groups), },
599 { "pwm5", jz4760_pwm5_groups, ARRAY_SIZE(jz4760_pwm5_groups), },
600 { "pwm6", jz4760_pwm6_groups, ARRAY_SIZE(jz4760_pwm6_groups), },
601 { "pwm7", jz4760_pwm7_groups, ARRAY_SIZE(jz4760_pwm7_groups), },
602};
603
604static const struct ingenic_chip_info jz4760_chip_info = {
605 .num_chips = 6,
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +0800606 .reg_offset = 0x100,
Zhou Yanjie0257595a2019-07-14 11:53:52 +0800607 .groups = jz4760_groups,
608 .num_groups = ARRAY_SIZE(jz4760_groups),
609 .functions = jz4760_functions,
610 .num_functions = ARRAY_SIZE(jz4760_functions),
611 .pull_ups = jz4760_pull_ups,
612 .pull_downs = jz4760_pull_downs,
613};
614
615static const struct ingenic_chip_info jz4760b_chip_info = {
616 .num_chips = 6,
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +0800617 .reg_offset = 0x100,
Zhou Yanjie0257595a2019-07-14 11:53:52 +0800618 .groups = jz4760_groups,
619 .num_groups = ARRAY_SIZE(jz4760_groups),
620 .functions = jz4760_functions,
621 .num_functions = ARRAY_SIZE(jz4760_functions),
622 .pull_ups = jz4760_pull_ups,
623 .pull_downs = jz4760_pull_downs,
624};
625
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200626static const u32 jz4770_pull_ups[6] = {
627 0x3fffffff, 0xfff0030c, 0xffffffff, 0xffff4fff, 0xfffffb7c, 0xffa7f00f,
628};
629
630static const u32 jz4770_pull_downs[6] = {
631 0x00000000, 0x000f0c03, 0x00000000, 0x0000b000, 0x00000483, 0x00580ff0,
632};
633
634static int jz4770_uart0_data_pins[] = { 0xa0, 0xa3, };
635static int jz4770_uart0_hwflow_pins[] = { 0xa1, 0xa2, };
636static int jz4770_uart1_data_pins[] = { 0x7a, 0x7c, };
637static int jz4770_uart1_hwflow_pins[] = { 0x7b, 0x7d, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800638static int jz4770_uart2_data_pins[] = { 0x5c, 0x5e, };
639static int jz4770_uart2_hwflow_pins[] = { 0x5d, 0x5f, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200640static int jz4770_uart3_data_pins[] = { 0x6c, 0x85, };
641static int jz4770_uart3_hwflow_pins[] = { 0x88, 0x89, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200642static int jz4770_mmc0_1bit_a_pins[] = { 0x12, 0x13, 0x14, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800643static int jz4770_mmc0_4bit_a_pins[] = { 0x15, 0x16, 0x17, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200644static int jz4770_mmc0_1bit_e_pins[] = { 0x9c, 0x9d, 0x94, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800645static int jz4770_mmc0_4bit_e_pins[] = { 0x95, 0x96, 0x97, };
646static int jz4770_mmc0_8bit_e_pins[] = { 0x98, 0x99, 0x9a, 0x9b, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200647static int jz4770_mmc1_1bit_d_pins[] = { 0x78, 0x79, 0x74, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800648static int jz4770_mmc1_4bit_d_pins[] = { 0x75, 0x76, 0x77, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200649static int jz4770_mmc1_1bit_e_pins[] = { 0x9c, 0x9d, 0x94, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800650static int jz4770_mmc1_4bit_e_pins[] = { 0x95, 0x96, 0x97, };
651static int jz4770_mmc1_8bit_e_pins[] = { 0x98, 0x99, 0x9a, 0x9b, };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800652static int jz4770_mmc2_1bit_b_pins[] = { 0x3c, 0x3d, 0x34, };
653static int jz4770_mmc2_4bit_b_pins[] = { 0x35, 0x3e, 0x3f, };
654static int jz4770_mmc2_1bit_e_pins[] = { 0x9c, 0x9d, 0x94, };
655static int jz4770_mmc2_4bit_e_pins[] = { 0x95, 0x96, 0x97, };
656static int jz4770_mmc2_8bit_e_pins[] = { 0x98, 0x99, 0x9a, 0x9b, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800657static int jz4770_nemc_8bit_data_pins[] = {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200658 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
659};
Zhou Yanjieff656e42019-01-28 23:19:57 +0800660static int jz4770_nemc_16bit_data_pins[] = {
661 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
662};
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200663static int jz4770_nemc_cle_ale_pins[] = { 0x20, 0x21, };
664static int jz4770_nemc_addr_pins[] = { 0x22, 0x23, 0x24, 0x25, };
665static int jz4770_nemc_rd_we_pins[] = { 0x10, 0x11, };
666static int jz4770_nemc_frd_fwe_pins[] = { 0x12, 0x13, };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800667static int jz4770_nemc_wait_pins[] = { 0x1b, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200668static int jz4770_nemc_cs1_pins[] = { 0x15, };
669static int jz4770_nemc_cs2_pins[] = { 0x16, };
670static int jz4770_nemc_cs3_pins[] = { 0x17, };
671static int jz4770_nemc_cs4_pins[] = { 0x18, };
672static int jz4770_nemc_cs5_pins[] = { 0x19, };
673static int jz4770_nemc_cs6_pins[] = { 0x1a, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800674static int jz4770_i2c0_pins[] = { 0x7e, 0x7f, };
675static int jz4770_i2c1_pins[] = { 0x9e, 0x9f, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200676static int jz4770_i2c2_pins[] = { 0xb0, 0xb1, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800677static int jz4770_cim_8bit_pins[] = {
678 0x26, 0x27, 0x28, 0x29,
679 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31,
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200680};
Zhou Yanjieff656e42019-01-28 23:19:57 +0800681static int jz4770_cim_12bit_pins[] = {
682 0x32, 0x33, 0xb0, 0xb1,
683};
684static int jz4770_lcd_24bit_pins[] = {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200685 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
686 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
687 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
Zhou Yanjieff656e42019-01-28 23:19:57 +0800688 0x58, 0x59, 0x5a, 0x5b,
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200689};
690static int jz4770_pwm_pwm0_pins[] = { 0x80, };
691static int jz4770_pwm_pwm1_pins[] = { 0x81, };
692static int jz4770_pwm_pwm2_pins[] = { 0x82, };
693static int jz4770_pwm_pwm3_pins[] = { 0x83, };
694static int jz4770_pwm_pwm4_pins[] = { 0x84, };
695static int jz4770_pwm_pwm5_pins[] = { 0x85, };
696static int jz4770_pwm_pwm6_pins[] = { 0x6a, };
697static int jz4770_pwm_pwm7_pins[] = { 0x6b, };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800698static int jz4770_mac_rmii_pins[] = {
699 0xa9, 0xab, 0xaa, 0xac, 0xa5, 0xa4, 0xad, 0xae, 0xa6, 0xa8,
700};
701static int jz4770_mac_mii_pins[] = { 0xa7, 0xaf, };
Paul Cercueilae75b532019-11-19 16:52:11 +0100702static int jz4770_otg_pins[] = { 0x8a, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200703
704static int jz4770_uart0_data_funcs[] = { 0, 0, };
705static int jz4770_uart0_hwflow_funcs[] = { 0, 0, };
706static int jz4770_uart1_data_funcs[] = { 0, 0, };
707static int jz4770_uart1_hwflow_funcs[] = { 0, 0, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800708static int jz4770_uart2_data_funcs[] = { 0, 0, };
709static int jz4770_uart2_hwflow_funcs[] = { 0, 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200710static int jz4770_uart3_data_funcs[] = { 0, 1, };
711static int jz4770_uart3_hwflow_funcs[] = { 0, 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200712static int jz4770_mmc0_1bit_a_funcs[] = { 1, 1, 0, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800713static int jz4770_mmc0_4bit_a_funcs[] = { 1, 1, 1, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200714static int jz4770_mmc0_1bit_e_funcs[] = { 0, 0, 0, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800715static int jz4770_mmc0_4bit_e_funcs[] = { 0, 0, 0, };
716static int jz4770_mmc0_8bit_e_funcs[] = { 0, 0, 0, 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200717static int jz4770_mmc1_1bit_d_funcs[] = { 0, 0, 0, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800718static int jz4770_mmc1_4bit_d_funcs[] = { 0, 0, 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200719static int jz4770_mmc1_1bit_e_funcs[] = { 1, 1, 1, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800720static int jz4770_mmc1_4bit_e_funcs[] = { 1, 1, 1, };
721static int jz4770_mmc1_8bit_e_funcs[] = { 1, 1, 1, 1, };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800722static int jz4770_mmc2_1bit_b_funcs[] = { 0, 0, 0, };
723static int jz4770_mmc2_4bit_b_funcs[] = { 0, 0, 0, };
724static int jz4770_mmc2_1bit_e_funcs[] = { 2, 2, 2, };
725static int jz4770_mmc2_4bit_e_funcs[] = { 2, 2, 2, };
726static int jz4770_mmc2_8bit_e_funcs[] = { 2, 2, 2, 2, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800727static int jz4770_nemc_8bit_data_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, };
728static int jz4770_nemc_16bit_data_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200729static int jz4770_nemc_cle_ale_funcs[] = { 0, 0, };
730static int jz4770_nemc_addr_funcs[] = { 0, 0, 0, 0, };
731static int jz4770_nemc_rd_we_funcs[] = { 0, 0, };
732static int jz4770_nemc_frd_fwe_funcs[] = { 0, 0, };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800733static int jz4770_nemc_wait_funcs[] = { 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200734static int jz4770_nemc_cs1_funcs[] = { 0, };
735static int jz4770_nemc_cs2_funcs[] = { 0, };
736static int jz4770_nemc_cs3_funcs[] = { 0, };
737static int jz4770_nemc_cs4_funcs[] = { 0, };
738static int jz4770_nemc_cs5_funcs[] = { 0, };
739static int jz4770_nemc_cs6_funcs[] = { 0, };
740static int jz4770_i2c0_funcs[] = { 0, 0, };
741static int jz4770_i2c1_funcs[] = { 0, 0, };
742static int jz4770_i2c2_funcs[] = { 2, 2, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800743static int jz4770_cim_8bit_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
744static int jz4770_cim_12bit_funcs[] = { 0, 0, 0, 0, };
745static int jz4770_lcd_24bit_funcs[] = {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200746 0, 0, 0, 0, 0, 0, 0, 0,
747 0, 0, 0, 0, 0, 0, 0, 0,
Zhou Yanjieff656e42019-01-28 23:19:57 +0800748 0, 0, 0, 0, 0, 0, 0, 0,
749 0, 0, 0, 0,
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200750};
751static int jz4770_pwm_pwm0_funcs[] = { 0, };
752static int jz4770_pwm_pwm1_funcs[] = { 0, };
753static int jz4770_pwm_pwm2_funcs[] = { 0, };
754static int jz4770_pwm_pwm3_funcs[] = { 0, };
755static int jz4770_pwm_pwm4_funcs[] = { 0, };
756static int jz4770_pwm_pwm5_funcs[] = { 0, };
757static int jz4770_pwm_pwm6_funcs[] = { 0, };
758static int jz4770_pwm_pwm7_funcs[] = { 0, };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800759static int jz4770_mac_rmii_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
760static int jz4770_mac_mii_funcs[] = { 0, 0, };
Paul Cercueilae75b532019-11-19 16:52:11 +0100761static int jz4770_otg_funcs[] = { 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200762
763static const struct group_desc jz4770_groups[] = {
764 INGENIC_PIN_GROUP("uart0-data", jz4770_uart0_data),
765 INGENIC_PIN_GROUP("uart0-hwflow", jz4770_uart0_hwflow),
766 INGENIC_PIN_GROUP("uart1-data", jz4770_uart1_data),
767 INGENIC_PIN_GROUP("uart1-hwflow", jz4770_uart1_hwflow),
768 INGENIC_PIN_GROUP("uart2-data", jz4770_uart2_data),
769 INGENIC_PIN_GROUP("uart2-hwflow", jz4770_uart2_hwflow),
770 INGENIC_PIN_GROUP("uart3-data", jz4770_uart3_data),
771 INGENIC_PIN_GROUP("uart3-hwflow", jz4770_uart3_hwflow),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200772 INGENIC_PIN_GROUP("mmc0-1bit-a", jz4770_mmc0_1bit_a),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800773 INGENIC_PIN_GROUP("mmc0-4bit-a", jz4770_mmc0_4bit_a),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200774 INGENIC_PIN_GROUP("mmc0-1bit-e", jz4770_mmc0_1bit_e),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800775 INGENIC_PIN_GROUP("mmc0-4bit-e", jz4770_mmc0_4bit_e),
776 INGENIC_PIN_GROUP("mmc0-8bit-e", jz4770_mmc0_8bit_e),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200777 INGENIC_PIN_GROUP("mmc1-1bit-d", jz4770_mmc1_1bit_d),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800778 INGENIC_PIN_GROUP("mmc1-4bit-d", jz4770_mmc1_4bit_d),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200779 INGENIC_PIN_GROUP("mmc1-1bit-e", jz4770_mmc1_1bit_e),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800780 INGENIC_PIN_GROUP("mmc1-4bit-e", jz4770_mmc1_4bit_e),
781 INGENIC_PIN_GROUP("mmc1-8bit-e", jz4770_mmc1_8bit_e),
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800782 INGENIC_PIN_GROUP("mmc2-1bit-b", jz4770_mmc2_1bit_b),
783 INGENIC_PIN_GROUP("mmc2-4bit-b", jz4770_mmc2_4bit_b),
784 INGENIC_PIN_GROUP("mmc2-1bit-e", jz4770_mmc2_1bit_e),
785 INGENIC_PIN_GROUP("mmc2-4bit-e", jz4770_mmc2_4bit_e),
786 INGENIC_PIN_GROUP("mmc2-8bit-e", jz4770_mmc2_8bit_e),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800787 INGENIC_PIN_GROUP("nemc-8bit-data", jz4770_nemc_8bit_data),
788 INGENIC_PIN_GROUP("nemc-16bit-data", jz4770_nemc_16bit_data),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200789 INGENIC_PIN_GROUP("nemc-cle-ale", jz4770_nemc_cle_ale),
790 INGENIC_PIN_GROUP("nemc-addr", jz4770_nemc_addr),
791 INGENIC_PIN_GROUP("nemc-rd-we", jz4770_nemc_rd_we),
792 INGENIC_PIN_GROUP("nemc-frd-fwe", jz4770_nemc_frd_fwe),
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800793 INGENIC_PIN_GROUP("nemc-wait", jz4770_nemc_wait),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200794 INGENIC_PIN_GROUP("nemc-cs1", jz4770_nemc_cs1),
795 INGENIC_PIN_GROUP("nemc-cs2", jz4770_nemc_cs2),
796 INGENIC_PIN_GROUP("nemc-cs3", jz4770_nemc_cs3),
797 INGENIC_PIN_GROUP("nemc-cs4", jz4770_nemc_cs4),
798 INGENIC_PIN_GROUP("nemc-cs5", jz4770_nemc_cs5),
799 INGENIC_PIN_GROUP("nemc-cs6", jz4770_nemc_cs6),
800 INGENIC_PIN_GROUP("i2c0-data", jz4770_i2c0),
801 INGENIC_PIN_GROUP("i2c1-data", jz4770_i2c1),
802 INGENIC_PIN_GROUP("i2c2-data", jz4770_i2c2),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800803 INGENIC_PIN_GROUP("cim-data-8bit", jz4770_cim_8bit),
804 INGENIC_PIN_GROUP("cim-data-12bit", jz4770_cim_12bit),
805 INGENIC_PIN_GROUP("lcd-24bit", jz4770_lcd_24bit),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200806 { "lcd-no-pins", },
807 INGENIC_PIN_GROUP("pwm0", jz4770_pwm_pwm0),
808 INGENIC_PIN_GROUP("pwm1", jz4770_pwm_pwm1),
809 INGENIC_PIN_GROUP("pwm2", jz4770_pwm_pwm2),
810 INGENIC_PIN_GROUP("pwm3", jz4770_pwm_pwm3),
811 INGENIC_PIN_GROUP("pwm4", jz4770_pwm_pwm4),
812 INGENIC_PIN_GROUP("pwm5", jz4770_pwm_pwm5),
813 INGENIC_PIN_GROUP("pwm6", jz4770_pwm_pwm6),
814 INGENIC_PIN_GROUP("pwm7", jz4770_pwm_pwm7),
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800815 INGENIC_PIN_GROUP("mac-rmii", jz4770_mac_rmii),
816 INGENIC_PIN_GROUP("mac-mii", jz4770_mac_mii),
Paul Cercueilae75b532019-11-19 16:52:11 +0100817 INGENIC_PIN_GROUP("otg-vbus", jz4770_otg),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200818};
819
820static const char *jz4770_uart0_groups[] = { "uart0-data", "uart0-hwflow", };
821static const char *jz4770_uart1_groups[] = { "uart1-data", "uart1-hwflow", };
822static const char *jz4770_uart2_groups[] = { "uart2-data", "uart2-hwflow", };
823static const char *jz4770_uart3_groups[] = { "uart3-data", "uart3-hwflow", };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200824static const char *jz4770_mmc0_groups[] = {
Zhou Yanjieff656e42019-01-28 23:19:57 +0800825 "mmc0-1bit-a", "mmc0-4bit-a",
826 "mmc0-1bit-e", "mmc0-4bit-e", "mmc0-8bit-e",
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200827};
828static const char *jz4770_mmc1_groups[] = {
Zhou Yanjieff656e42019-01-28 23:19:57 +0800829 "mmc1-1bit-d", "mmc1-4bit-d",
830 "mmc1-1bit-e", "mmc1-4bit-e", "mmc1-8bit-e",
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200831};
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800832static const char *jz4770_mmc2_groups[] = {
833 "mmc2-1bit-b", "mmc2-4bit-b",
834 "mmc2-1bit-e", "mmc2-4bit-e", "mmc2-8bit-e",
835};
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200836static const char *jz4770_nemc_groups[] = {
Zhou Yanjieff656e42019-01-28 23:19:57 +0800837 "nemc-8bit-data", "nemc-16bit-data", "nemc-cle-ale",
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800838 "nemc-addr", "nemc-rd-we", "nemc-frd-fwe", "nemc-wait",
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200839};
840static const char *jz4770_cs1_groups[] = { "nemc-cs1", };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800841static const char *jz4770_cs2_groups[] = { "nemc-cs2", };
842static const char *jz4770_cs3_groups[] = { "nemc-cs3", };
843static const char *jz4770_cs4_groups[] = { "nemc-cs4", };
844static const char *jz4770_cs5_groups[] = { "nemc-cs5", };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200845static const char *jz4770_cs6_groups[] = { "nemc-cs6", };
846static const char *jz4770_i2c0_groups[] = { "i2c0-data", };
847static const char *jz4770_i2c1_groups[] = { "i2c1-data", };
848static const char *jz4770_i2c2_groups[] = { "i2c2-data", };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800849static const char *jz4770_cim_groups[] = { "cim-data-8bit", "cim-data-12bit", };
850static const char *jz4770_lcd_groups[] = { "lcd-24bit", "lcd-no-pins", };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200851static const char *jz4770_pwm0_groups[] = { "pwm0", };
852static const char *jz4770_pwm1_groups[] = { "pwm1", };
853static const char *jz4770_pwm2_groups[] = { "pwm2", };
854static const char *jz4770_pwm3_groups[] = { "pwm3", };
855static const char *jz4770_pwm4_groups[] = { "pwm4", };
856static const char *jz4770_pwm5_groups[] = { "pwm5", };
857static const char *jz4770_pwm6_groups[] = { "pwm6", };
858static const char *jz4770_pwm7_groups[] = { "pwm7", };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800859static const char *jz4770_mac_groups[] = { "mac-rmii", "mac-mii", };
Paul Cercueilae75b532019-11-19 16:52:11 +0100860static const char *jz4770_otg_groups[] = { "otg-vbus", };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200861
862static const struct function_desc jz4770_functions[] = {
863 { "uart0", jz4770_uart0_groups, ARRAY_SIZE(jz4770_uart0_groups), },
864 { "uart1", jz4770_uart1_groups, ARRAY_SIZE(jz4770_uart1_groups), },
865 { "uart2", jz4770_uart2_groups, ARRAY_SIZE(jz4770_uart2_groups), },
866 { "uart3", jz4770_uart3_groups, ARRAY_SIZE(jz4770_uart3_groups), },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200867 { "mmc0", jz4770_mmc0_groups, ARRAY_SIZE(jz4770_mmc0_groups), },
868 { "mmc1", jz4770_mmc1_groups, ARRAY_SIZE(jz4770_mmc1_groups), },
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800869 { "mmc2", jz4770_mmc2_groups, ARRAY_SIZE(jz4770_mmc2_groups), },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200870 { "nemc", jz4770_nemc_groups, ARRAY_SIZE(jz4770_nemc_groups), },
871 { "nemc-cs1", jz4770_cs1_groups, ARRAY_SIZE(jz4770_cs1_groups), },
Zhou Yanjieff656e42019-01-28 23:19:57 +0800872 { "nemc-cs2", jz4770_cs2_groups, ARRAY_SIZE(jz4770_cs2_groups), },
873 { "nemc-cs3", jz4770_cs3_groups, ARRAY_SIZE(jz4770_cs3_groups), },
874 { "nemc-cs4", jz4770_cs4_groups, ARRAY_SIZE(jz4770_cs4_groups), },
875 { "nemc-cs5", jz4770_cs5_groups, ARRAY_SIZE(jz4770_cs5_groups), },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200876 { "nemc-cs6", jz4770_cs6_groups, ARRAY_SIZE(jz4770_cs6_groups), },
877 { "i2c0", jz4770_i2c0_groups, ARRAY_SIZE(jz4770_i2c0_groups), },
878 { "i2c1", jz4770_i2c1_groups, ARRAY_SIZE(jz4770_i2c1_groups), },
879 { "i2c2", jz4770_i2c2_groups, ARRAY_SIZE(jz4770_i2c2_groups), },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200880 { "cim", jz4770_cim_groups, ARRAY_SIZE(jz4770_cim_groups), },
881 { "lcd", jz4770_lcd_groups, ARRAY_SIZE(jz4770_lcd_groups), },
882 { "pwm0", jz4770_pwm0_groups, ARRAY_SIZE(jz4770_pwm0_groups), },
883 { "pwm1", jz4770_pwm1_groups, ARRAY_SIZE(jz4770_pwm1_groups), },
884 { "pwm2", jz4770_pwm2_groups, ARRAY_SIZE(jz4770_pwm2_groups), },
885 { "pwm3", jz4770_pwm3_groups, ARRAY_SIZE(jz4770_pwm3_groups), },
886 { "pwm4", jz4770_pwm4_groups, ARRAY_SIZE(jz4770_pwm4_groups), },
887 { "pwm5", jz4770_pwm5_groups, ARRAY_SIZE(jz4770_pwm5_groups), },
888 { "pwm6", jz4770_pwm6_groups, ARRAY_SIZE(jz4770_pwm6_groups), },
889 { "pwm7", jz4770_pwm7_groups, ARRAY_SIZE(jz4770_pwm7_groups), },
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800890 { "mac", jz4770_mac_groups, ARRAY_SIZE(jz4770_mac_groups), },
Paul Cercueilae75b532019-11-19 16:52:11 +0100891 { "otg", jz4770_otg_groups, ARRAY_SIZE(jz4770_otg_groups), },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200892};
893
894static const struct ingenic_chip_info jz4770_chip_info = {
895 .num_chips = 6,
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +0800896 .reg_offset = 0x100,
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200897 .groups = jz4770_groups,
898 .num_groups = ARRAY_SIZE(jz4770_groups),
899 .functions = jz4770_functions,
900 .num_functions = ARRAY_SIZE(jz4770_functions),
901 .pull_ups = jz4770_pull_ups,
902 .pull_downs = jz4770_pull_downs,
903};
904
Zhou Yanjieff656e42019-01-28 23:19:57 +0800905static int jz4780_uart2_data_pins[] = { 0x66, 0x67, };
906static int jz4780_uart2_hwflow_pins[] = { 0x65, 0x64, };
907static int jz4780_uart4_data_pins[] = { 0x54, 0x4a, };
908static int jz4780_mmc0_8bit_a_pins[] = { 0x04, 0x05, 0x06, 0x07, 0x18, };
909static int jz4780_i2c3_pins[] = { 0x6a, 0x6b, };
910static int jz4780_i2c4_e_pins[] = { 0x8c, 0x8d, };
911static int jz4780_i2c4_f_pins[] = { 0xb9, 0xb8, };
912
913static int jz4780_uart2_data_funcs[] = { 1, 1, };
914static int jz4780_uart2_hwflow_funcs[] = { 1, 1, };
915static int jz4780_uart4_data_funcs[] = { 2, 2, };
916static int jz4780_mmc0_8bit_a_funcs[] = { 1, 1, 1, 1, 1, };
917static int jz4780_i2c3_funcs[] = { 1, 1, };
918static int jz4780_i2c4_e_funcs[] = { 1, 1, };
919static int jz4780_i2c4_f_funcs[] = { 1, 1, };
920
921static const struct group_desc jz4780_groups[] = {
922 INGENIC_PIN_GROUP("uart0-data", jz4770_uart0_data),
923 INGENIC_PIN_GROUP("uart0-hwflow", jz4770_uart0_hwflow),
924 INGENIC_PIN_GROUP("uart1-data", jz4770_uart1_data),
925 INGENIC_PIN_GROUP("uart1-hwflow", jz4770_uart1_hwflow),
926 INGENIC_PIN_GROUP("uart2-data", jz4780_uart2_data),
927 INGENIC_PIN_GROUP("uart2-hwflow", jz4780_uart2_hwflow),
928 INGENIC_PIN_GROUP("uart3-data", jz4770_uart3_data),
929 INGENIC_PIN_GROUP("uart3-hwflow", jz4770_uart3_hwflow),
930 INGENIC_PIN_GROUP("uart4-data", jz4780_uart4_data),
931 INGENIC_PIN_GROUP("mmc0-1bit-a", jz4770_mmc0_1bit_a),
932 INGENIC_PIN_GROUP("mmc0-4bit-a", jz4770_mmc0_4bit_a),
933 INGENIC_PIN_GROUP("mmc0-8bit-a", jz4780_mmc0_8bit_a),
934 INGENIC_PIN_GROUP("mmc0-1bit-e", jz4770_mmc0_1bit_e),
935 INGENIC_PIN_GROUP("mmc0-4bit-e", jz4770_mmc0_4bit_e),
936 INGENIC_PIN_GROUP("mmc1-1bit-d", jz4770_mmc1_1bit_d),
937 INGENIC_PIN_GROUP("mmc1-4bit-d", jz4770_mmc1_4bit_d),
938 INGENIC_PIN_GROUP("mmc1-1bit-e", jz4770_mmc1_1bit_e),
939 INGENIC_PIN_GROUP("mmc1-4bit-e", jz4770_mmc1_4bit_e),
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800940 INGENIC_PIN_GROUP("mmc2-1bit-b", jz4770_mmc2_1bit_b),
941 INGENIC_PIN_GROUP("mmc2-4bit-b", jz4770_mmc2_4bit_b),
942 INGENIC_PIN_GROUP("mmc2-1bit-e", jz4770_mmc2_1bit_e),
943 INGENIC_PIN_GROUP("mmc2-4bit-e", jz4770_mmc2_4bit_e),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800944 INGENIC_PIN_GROUP("nemc-data", jz4770_nemc_8bit_data),
945 INGENIC_PIN_GROUP("nemc-cle-ale", jz4770_nemc_cle_ale),
946 INGENIC_PIN_GROUP("nemc-addr", jz4770_nemc_addr),
947 INGENIC_PIN_GROUP("nemc-rd-we", jz4770_nemc_rd_we),
948 INGENIC_PIN_GROUP("nemc-frd-fwe", jz4770_nemc_frd_fwe),
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800949 INGENIC_PIN_GROUP("nemc-wait", jz4770_nemc_wait),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800950 INGENIC_PIN_GROUP("nemc-cs1", jz4770_nemc_cs1),
951 INGENIC_PIN_GROUP("nemc-cs2", jz4770_nemc_cs2),
952 INGENIC_PIN_GROUP("nemc-cs3", jz4770_nemc_cs3),
953 INGENIC_PIN_GROUP("nemc-cs4", jz4770_nemc_cs4),
954 INGENIC_PIN_GROUP("nemc-cs5", jz4770_nemc_cs5),
955 INGENIC_PIN_GROUP("nemc-cs6", jz4770_nemc_cs6),
956 INGENIC_PIN_GROUP("i2c0-data", jz4770_i2c0),
957 INGENIC_PIN_GROUP("i2c1-data", jz4770_i2c1),
958 INGENIC_PIN_GROUP("i2c2-data", jz4770_i2c2),
959 INGENIC_PIN_GROUP("i2c3-data", jz4780_i2c3),
960 INGENIC_PIN_GROUP("i2c4-data-e", jz4780_i2c4_e),
961 INGENIC_PIN_GROUP("i2c4-data-f", jz4780_i2c4_f),
962 INGENIC_PIN_GROUP("cim-data", jz4770_cim_8bit),
963 INGENIC_PIN_GROUP("lcd-24bit", jz4770_lcd_24bit),
964 { "lcd-no-pins", },
965 INGENIC_PIN_GROUP("pwm0", jz4770_pwm_pwm0),
966 INGENIC_PIN_GROUP("pwm1", jz4770_pwm_pwm1),
967 INGENIC_PIN_GROUP("pwm2", jz4770_pwm_pwm2),
968 INGENIC_PIN_GROUP("pwm3", jz4770_pwm_pwm3),
969 INGENIC_PIN_GROUP("pwm4", jz4770_pwm_pwm4),
970 INGENIC_PIN_GROUP("pwm5", jz4770_pwm_pwm5),
971 INGENIC_PIN_GROUP("pwm6", jz4770_pwm_pwm6),
972 INGENIC_PIN_GROUP("pwm7", jz4770_pwm_pwm7),
973};
974
975static const char *jz4780_uart2_groups[] = { "uart2-data", "uart2-hwflow", };
976static const char *jz4780_uart4_groups[] = { "uart4-data", };
977static const char *jz4780_mmc0_groups[] = {
978 "mmc0-1bit-a", "mmc0-4bit-a", "mmc0-8bit-a",
979 "mmc0-1bit-e", "mmc0-4bit-e",
980};
981static const char *jz4780_mmc1_groups[] = {
982 "mmc1-1bit-d", "mmc1-4bit-d", "mmc1-1bit-e", "mmc1-4bit-e",
983};
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800984static const char *jz4780_mmc2_groups[] = {
985 "mmc2-1bit-b", "mmc2-4bit-b", "mmc2-1bit-e", "mmc2-4bit-e",
986};
Zhou Yanjieff656e42019-01-28 23:19:57 +0800987static const char *jz4780_nemc_groups[] = {
988 "nemc-data", "nemc-cle-ale", "nemc-addr",
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800989 "nemc-rd-we", "nemc-frd-fwe", "nemc-wait",
Zhou Yanjieff656e42019-01-28 23:19:57 +0800990};
991static const char *jz4780_i2c3_groups[] = { "i2c3-data", };
992static const char *jz4780_i2c4_groups[] = { "i2c4-data-e", "i2c4-data-f", };
993static const char *jz4780_cim_groups[] = { "cim-data", };
994
995static const struct function_desc jz4780_functions[] = {
996 { "uart0", jz4770_uart0_groups, ARRAY_SIZE(jz4770_uart0_groups), },
997 { "uart1", jz4770_uart1_groups, ARRAY_SIZE(jz4770_uart1_groups), },
998 { "uart2", jz4780_uart2_groups, ARRAY_SIZE(jz4780_uart2_groups), },
999 { "uart3", jz4770_uart3_groups, ARRAY_SIZE(jz4770_uart3_groups), },
1000 { "uart4", jz4780_uart4_groups, ARRAY_SIZE(jz4780_uart4_groups), },
1001 { "mmc0", jz4780_mmc0_groups, ARRAY_SIZE(jz4780_mmc0_groups), },
1002 { "mmc1", jz4780_mmc1_groups, ARRAY_SIZE(jz4780_mmc1_groups), },
Zhou Yanjie5de1a732019-01-28 23:19:58 +08001003 { "mmc2", jz4780_mmc2_groups, ARRAY_SIZE(jz4780_mmc2_groups), },
Zhou Yanjieff656e42019-01-28 23:19:57 +08001004 { "nemc", jz4780_nemc_groups, ARRAY_SIZE(jz4780_nemc_groups), },
1005 { "nemc-cs1", jz4770_cs1_groups, ARRAY_SIZE(jz4770_cs1_groups), },
1006 { "nemc-cs2", jz4770_cs2_groups, ARRAY_SIZE(jz4770_cs2_groups), },
1007 { "nemc-cs3", jz4770_cs3_groups, ARRAY_SIZE(jz4770_cs3_groups), },
1008 { "nemc-cs4", jz4770_cs4_groups, ARRAY_SIZE(jz4770_cs4_groups), },
1009 { "nemc-cs5", jz4770_cs5_groups, ARRAY_SIZE(jz4770_cs5_groups), },
1010 { "nemc-cs6", jz4770_cs6_groups, ARRAY_SIZE(jz4770_cs6_groups), },
1011 { "i2c0", jz4770_i2c0_groups, ARRAY_SIZE(jz4770_i2c0_groups), },
1012 { "i2c1", jz4770_i2c1_groups, ARRAY_SIZE(jz4770_i2c1_groups), },
1013 { "i2c2", jz4770_i2c2_groups, ARRAY_SIZE(jz4770_i2c2_groups), },
1014 { "i2c3", jz4780_i2c3_groups, ARRAY_SIZE(jz4780_i2c3_groups), },
1015 { "i2c4", jz4780_i2c4_groups, ARRAY_SIZE(jz4780_i2c4_groups), },
1016 { "cim", jz4780_cim_groups, ARRAY_SIZE(jz4780_cim_groups), },
1017 { "lcd", jz4770_lcd_groups, ARRAY_SIZE(jz4770_lcd_groups), },
1018 { "pwm0", jz4770_pwm0_groups, ARRAY_SIZE(jz4770_pwm0_groups), },
1019 { "pwm1", jz4770_pwm1_groups, ARRAY_SIZE(jz4770_pwm1_groups), },
1020 { "pwm2", jz4770_pwm2_groups, ARRAY_SIZE(jz4770_pwm2_groups), },
1021 { "pwm3", jz4770_pwm3_groups, ARRAY_SIZE(jz4770_pwm3_groups), },
1022 { "pwm4", jz4770_pwm4_groups, ARRAY_SIZE(jz4770_pwm4_groups), },
1023 { "pwm5", jz4770_pwm5_groups, ARRAY_SIZE(jz4770_pwm5_groups), },
1024 { "pwm6", jz4770_pwm6_groups, ARRAY_SIZE(jz4770_pwm6_groups), },
1025 { "pwm7", jz4770_pwm7_groups, ARRAY_SIZE(jz4770_pwm7_groups), },
1026};
1027
1028static const struct ingenic_chip_info jz4780_chip_info = {
1029 .num_chips = 6,
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +08001030 .reg_offset = 0x100,
Zhou Yanjieff656e42019-01-28 23:19:57 +08001031 .groups = jz4780_groups,
1032 .num_groups = ARRAY_SIZE(jz4780_groups),
1033 .functions = jz4780_functions,
1034 .num_functions = ARRAY_SIZE(jz4780_functions),
1035 .pull_ups = jz4770_pull_ups,
1036 .pull_downs = jz4770_pull_downs,
1037};
1038
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001039static const u32 x1000_pull_ups[4] = {
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001040 0xffffffff, 0xfdffffff, 0x0dffffff, 0x0000003f,
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001041};
1042
1043static const u32 x1000_pull_downs[4] = {
1044 0x00000000, 0x02000000, 0x02000000, 0x00000000,
1045};
1046
1047static int x1000_uart0_data_pins[] = { 0x4a, 0x4b, };
1048static int x1000_uart0_hwflow_pins[] = { 0x4c, 0x4d, };
1049static int x1000_uart1_data_a_pins[] = { 0x04, 0x05, };
1050static int x1000_uart1_data_d_pins[] = { 0x62, 0x63, };
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001051static int x1000_uart1_hwflow_pins[] = { 0x64, 0x65, };
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001052static int x1000_uart2_data_a_pins[] = { 0x02, 0x03, };
1053static int x1000_uart2_data_d_pins[] = { 0x65, 0x64, };
周琰杰 (Zhou Yanjie)3b31e9b2019-12-16 00:21:01 +08001054static int x1000_sfc_pins[] = { 0x1d, 0x1c, 0x1e, 0x1f, 0x1a, 0x1b, };
1055static int x1000_ssi_dt_a_22_pins[] = { 0x16, };
1056static int x1000_ssi_dt_a_29_pins[] = { 0x1d, };
1057static int x1000_ssi_dt_d_pins[] = { 0x62, };
1058static int x1000_ssi_dr_a_23_pins[] = { 0x17, };
1059static int x1000_ssi_dr_a_28_pins[] = { 0x1c, };
1060static int x1000_ssi_dr_d_pins[] = { 0x63, };
1061static int x1000_ssi_clk_a_24_pins[] = { 0x18, };
1062static int x1000_ssi_clk_a_26_pins[] = { 0x1a, };
1063static int x1000_ssi_clk_d_pins[] = { 0x60, };
1064static int x1000_ssi_gpc_a_20_pins[] = { 0x14, };
1065static int x1000_ssi_gpc_a_31_pins[] = { 0x1f, };
1066static int x1000_ssi_ce0_a_25_pins[] = { 0x19, };
1067static int x1000_ssi_ce0_a_27_pins[] = { 0x1b, };
1068static int x1000_ssi_ce0_d_pins[] = { 0x61, };
1069static int x1000_ssi_ce1_a_21_pins[] = { 0x15, };
1070static int x1000_ssi_ce1_a_30_pins[] = { 0x1e, };
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001071static int x1000_mmc0_1bit_pins[] = { 0x18, 0x19, 0x17, };
1072static int x1000_mmc0_4bit_pins[] = { 0x16, 0x15, 0x14, };
1073static int x1000_mmc0_8bit_pins[] = { 0x13, 0x12, 0x11, 0x10, };
1074static int x1000_mmc1_1bit_pins[] = { 0x40, 0x41, 0x42, };
1075static int x1000_mmc1_4bit_pins[] = { 0x43, 0x44, 0x45, };
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001076static int x1000_emc_8bit_data_pins[] = {
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001077 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1078};
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001079static int x1000_emc_16bit_data_pins[] = {
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001080 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1081};
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001082static int x1000_emc_addr_pins[] = {
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001083 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
1084 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
1085};
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001086static int x1000_emc_rd_we_pins[] = { 0x30, 0x31, };
1087static int x1000_emc_wait_pins[] = { 0x34, };
1088static int x1000_emc_cs1_pins[] = { 0x32, };
1089static int x1000_emc_cs2_pins[] = { 0x33, };
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001090static int x1000_i2c0_pins[] = { 0x38, 0x37, };
1091static int x1000_i2c1_a_pins[] = { 0x01, 0x00, };
1092static int x1000_i2c1_c_pins[] = { 0x5b, 0x5a, };
1093static int x1000_i2c2_pins[] = { 0x61, 0x60, };
1094static int x1000_cim_pins[] = {
1095 0x08, 0x09, 0x0a, 0x0b,
1096 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0c,
1097};
1098static int x1000_lcd_8bit_pins[] = {
1099 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1100 0x30, 0x31, 0x32, 0x33, 0x34,
1101};
1102static int x1000_lcd_16bit_pins[] = {
1103 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1104};
1105static int x1000_pwm_pwm0_pins[] = { 0x59, };
1106static int x1000_pwm_pwm1_pins[] = { 0x5a, };
1107static int x1000_pwm_pwm2_pins[] = { 0x5b, };
1108static int x1000_pwm_pwm3_pins[] = { 0x26, };
1109static int x1000_pwm_pwm4_pins[] = { 0x58, };
1110static int x1000_mac_pins[] = {
1111 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x26,
1112};
1113
1114static int x1000_uart0_data_funcs[] = { 0, 0, };
1115static int x1000_uart0_hwflow_funcs[] = { 0, 0, };
1116static int x1000_uart1_data_a_funcs[] = { 2, 2, };
1117static int x1000_uart1_data_d_funcs[] = { 1, 1, };
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001118static int x1000_uart1_hwflow_funcs[] = { 1, 1, };
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001119static int x1000_uart2_data_a_funcs[] = { 2, 2, };
1120static int x1000_uart2_data_d_funcs[] = { 0, 0, };
周琰杰 (Zhou Yanjie)3b31e9b2019-12-16 00:21:01 +08001121static int x1000_sfc_funcs[] = { 1, 1, 1, 1, 1, 1, };
1122static int x1000_ssi_dt_a_22_funcs[] = { 2, };
1123static int x1000_ssi_dt_a_29_funcs[] = { 2, };
1124static int x1000_ssi_dt_d_funcs[] = { 0, };
1125static int x1000_ssi_dr_a_23_funcs[] = { 2, };
1126static int x1000_ssi_dr_a_28_funcs[] = { 2, };
1127static int x1000_ssi_dr_d_funcs[] = { 0, };
1128static int x1000_ssi_clk_a_24_funcs[] = { 2, };
1129static int x1000_ssi_clk_a_26_funcs[] = { 2, };
1130static int x1000_ssi_clk_d_funcs[] = { 0, };
1131static int x1000_ssi_gpc_a_20_funcs[] = { 2, };
1132static int x1000_ssi_gpc_a_31_funcs[] = { 2, };
1133static int x1000_ssi_ce0_a_25_funcs[] = { 2, };
1134static int x1000_ssi_ce0_a_27_funcs[] = { 2, };
1135static int x1000_ssi_ce0_d_funcs[] = { 0, };
1136static int x1000_ssi_ce1_a_21_funcs[] = { 2, };
1137static int x1000_ssi_ce1_a_30_funcs[] = { 2, };
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001138static int x1000_mmc0_1bit_funcs[] = { 1, 1, 1, };
1139static int x1000_mmc0_4bit_funcs[] = { 1, 1, 1, };
1140static int x1000_mmc0_8bit_funcs[] = { 1, 1, 1, 1, 1, };
1141static int x1000_mmc1_1bit_funcs[] = { 0, 0, 0, };
1142static int x1000_mmc1_4bit_funcs[] = { 0, 0, 0, };
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001143static int x1000_emc_8bit_data_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, };
1144static int x1000_emc_16bit_data_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, };
1145static int x1000_emc_addr_funcs[] = {
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001146 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1147};
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001148static int x1000_emc_rd_we_funcs[] = { 0, 0, };
1149static int x1000_emc_wait_funcs[] = { 0, };
1150static int x1000_emc_cs1_funcs[] = { 0, };
1151static int x1000_emc_cs2_funcs[] = { 0, };
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001152static int x1000_i2c0_funcs[] = { 0, 0, };
1153static int x1000_i2c1_a_funcs[] = { 2, 2, };
1154static int x1000_i2c1_c_funcs[] = { 0, 0, };
1155static int x1000_i2c2_funcs[] = { 1, 1, };
1156static int x1000_cim_funcs[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, };
1157static int x1000_lcd_8bit_funcs[] = {
1158 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1159};
1160static int x1000_lcd_16bit_funcs[] = { 1, 1, 1, 1, 1, 1, 1, 1, };
1161static int x1000_pwm_pwm0_funcs[] = { 0, };
1162static int x1000_pwm_pwm1_funcs[] = { 1, };
1163static int x1000_pwm_pwm2_funcs[] = { 1, };
1164static int x1000_pwm_pwm3_funcs[] = { 2, };
1165static int x1000_pwm_pwm4_funcs[] = { 0, };
1166static int x1000_mac_funcs[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, };
1167
1168static const struct group_desc x1000_groups[] = {
1169 INGENIC_PIN_GROUP("uart0-data", x1000_uart0_data),
1170 INGENIC_PIN_GROUP("uart0-hwflow", x1000_uart0_hwflow),
1171 INGENIC_PIN_GROUP("uart1-data-a", x1000_uart1_data_a),
1172 INGENIC_PIN_GROUP("uart1-data-d", x1000_uart1_data_d),
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001173 INGENIC_PIN_GROUP("uart1-hwflow", x1000_uart1_hwflow),
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001174 INGENIC_PIN_GROUP("uart2-data-a", x1000_uart2_data_a),
1175 INGENIC_PIN_GROUP("uart2-data-d", x1000_uart2_data_d),
周琰杰 (Zhou Yanjie)3b31e9b2019-12-16 00:21:01 +08001176 INGENIC_PIN_GROUP("sfc", x1000_sfc),
1177 INGENIC_PIN_GROUP("ssi-dt-a-22", x1000_ssi_dt_a_22),
1178 INGENIC_PIN_GROUP("ssi-dt-a-29", x1000_ssi_dt_a_29),
1179 INGENIC_PIN_GROUP("ssi-dt-d", x1000_ssi_dt_d),
1180 INGENIC_PIN_GROUP("ssi-dr-a-23", x1000_ssi_dr_a_23),
1181 INGENIC_PIN_GROUP("ssi-dr-a-28", x1000_ssi_dr_a_28),
1182 INGENIC_PIN_GROUP("ssi-dr-d", x1000_ssi_dr_d),
1183 INGENIC_PIN_GROUP("ssi-clk-a-24", x1000_ssi_clk_a_24),
1184 INGENIC_PIN_GROUP("ssi-clk-a-26", x1000_ssi_clk_a_26),
1185 INGENIC_PIN_GROUP("ssi-clk-d", x1000_ssi_clk_d),
1186 INGENIC_PIN_GROUP("ssi-gpc-a-20", x1000_ssi_gpc_a_20),
1187 INGENIC_PIN_GROUP("ssi-gpc-a-31", x1000_ssi_gpc_a_31),
1188 INGENIC_PIN_GROUP("ssi-ce0-a-25", x1000_ssi_ce0_a_25),
1189 INGENIC_PIN_GROUP("ssi-ce0-a-27", x1000_ssi_ce0_a_27),
1190 INGENIC_PIN_GROUP("ssi-ce0-d", x1000_ssi_ce0_d),
1191 INGENIC_PIN_GROUP("ssi-ce1-a-21", x1000_ssi_ce1_a_21),
1192 INGENIC_PIN_GROUP("ssi-ce1-a-30", x1000_ssi_ce1_a_30),
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001193 INGENIC_PIN_GROUP("mmc0-1bit", x1000_mmc0_1bit),
1194 INGENIC_PIN_GROUP("mmc0-4bit", x1000_mmc0_4bit),
1195 INGENIC_PIN_GROUP("mmc0-8bit", x1000_mmc0_8bit),
1196 INGENIC_PIN_GROUP("mmc1-1bit", x1000_mmc1_1bit),
1197 INGENIC_PIN_GROUP("mmc1-4bit", x1000_mmc1_4bit),
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001198 INGENIC_PIN_GROUP("emc-8bit-data", x1000_emc_8bit_data),
1199 INGENIC_PIN_GROUP("emc-16bit-data", x1000_emc_16bit_data),
1200 INGENIC_PIN_GROUP("emc-addr", x1000_emc_addr),
1201 INGENIC_PIN_GROUP("emc-rd-we", x1000_emc_rd_we),
1202 INGENIC_PIN_GROUP("emc-wait", x1000_emc_wait),
1203 INGENIC_PIN_GROUP("emc-cs1", x1000_emc_cs1),
1204 INGENIC_PIN_GROUP("emc-cs2", x1000_emc_cs2),
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001205 INGENIC_PIN_GROUP("i2c0-data", x1000_i2c0),
1206 INGENIC_PIN_GROUP("i2c1-data-a", x1000_i2c1_a),
1207 INGENIC_PIN_GROUP("i2c1-data-c", x1000_i2c1_c),
1208 INGENIC_PIN_GROUP("i2c2-data", x1000_i2c2),
1209 INGENIC_PIN_GROUP("cim-data", x1000_cim),
1210 INGENIC_PIN_GROUP("lcd-8bit", x1000_lcd_8bit),
1211 INGENIC_PIN_GROUP("lcd-16bit", x1000_lcd_16bit),
1212 { "lcd-no-pins", },
1213 INGENIC_PIN_GROUP("pwm0", x1000_pwm_pwm0),
1214 INGENIC_PIN_GROUP("pwm1", x1000_pwm_pwm1),
1215 INGENIC_PIN_GROUP("pwm2", x1000_pwm_pwm2),
1216 INGENIC_PIN_GROUP("pwm3", x1000_pwm_pwm3),
1217 INGENIC_PIN_GROUP("pwm4", x1000_pwm_pwm4),
1218 INGENIC_PIN_GROUP("mac", x1000_mac),
1219};
1220
1221static const char *x1000_uart0_groups[] = { "uart0-data", "uart0-hwflow", };
1222static const char *x1000_uart1_groups[] = {
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001223 "uart1-data-a", "uart1-data-d", "uart1-hwflow",
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001224};
1225static const char *x1000_uart2_groups[] = { "uart2-data-a", "uart2-data-d", };
周琰杰 (Zhou Yanjie)3b31e9b2019-12-16 00:21:01 +08001226static const char *x1000_sfc_groups[] = { "sfc", };
1227static const char *x1000_ssi_groups[] = {
1228 "ssi-dt-a-22", "ssi-dt-a-29", "ssi-dt-d",
1229 "ssi-dr-a-23", "ssi-dr-a-28", "ssi-dr-d",
1230 "ssi-clk-a-24", "ssi-clk-a-26", "ssi-clk-d",
1231 "ssi-gpc-a-20", "ssi-gpc-a-31",
1232 "ssi-ce0-a-25", "ssi-ce0-a-27", "ssi-ce0-d",
1233 "ssi-ce1-a-21", "ssi-ce1-a-30",
1234};
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001235static const char *x1000_mmc0_groups[] = {
1236 "mmc0-1bit", "mmc0-4bit", "mmc0-8bit",
1237};
1238static const char *x1000_mmc1_groups[] = {
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001239 "mmc1-1bit", "mmc1-4bit",
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001240};
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001241static const char *x1000_emc_groups[] = {
1242 "emc-8bit-data", "emc-16bit-data",
1243 "emc-addr", "emc-rd-we", "emc-wait",
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001244};
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001245static const char *x1000_cs1_groups[] = { "emc-cs1", };
1246static const char *x1000_cs2_groups[] = { "emc-cs2", };
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001247static const char *x1000_i2c0_groups[] = { "i2c0-data", };
1248static const char *x1000_i2c1_groups[] = { "i2c1-data-a", "i2c1-data-c", };
1249static const char *x1000_i2c2_groups[] = { "i2c2-data", };
1250static const char *x1000_cim_groups[] = { "cim-data", };
1251static const char *x1000_lcd_groups[] = {
1252 "lcd-8bit", "lcd-16bit", "lcd-no-pins",
1253};
1254static const char *x1000_pwm0_groups[] = { "pwm0", };
1255static const char *x1000_pwm1_groups[] = { "pwm1", };
1256static const char *x1000_pwm2_groups[] = { "pwm2", };
1257static const char *x1000_pwm3_groups[] = { "pwm3", };
1258static const char *x1000_pwm4_groups[] = { "pwm4", };
1259static const char *x1000_mac_groups[] = { "mac", };
1260
1261static const struct function_desc x1000_functions[] = {
1262 { "uart0", x1000_uart0_groups, ARRAY_SIZE(x1000_uart0_groups), },
1263 { "uart1", x1000_uart1_groups, ARRAY_SIZE(x1000_uart1_groups), },
1264 { "uart2", x1000_uart2_groups, ARRAY_SIZE(x1000_uart2_groups), },
周琰杰 (Zhou Yanjie)3b31e9b2019-12-16 00:21:01 +08001265 { "sfc", x1000_sfc_groups, ARRAY_SIZE(x1000_sfc_groups), },
1266 { "ssi", x1000_ssi_groups, ARRAY_SIZE(x1000_ssi_groups), },
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001267 { "mmc0", x1000_mmc0_groups, ARRAY_SIZE(x1000_mmc0_groups), },
1268 { "mmc1", x1000_mmc1_groups, ARRAY_SIZE(x1000_mmc1_groups), },
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001269 { "emc", x1000_emc_groups, ARRAY_SIZE(x1000_emc_groups), },
1270 { "emc-cs1", x1000_cs1_groups, ARRAY_SIZE(x1000_cs1_groups), },
1271 { "emc-cs2", x1000_cs2_groups, ARRAY_SIZE(x1000_cs2_groups), },
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001272 { "i2c0", x1000_i2c0_groups, ARRAY_SIZE(x1000_i2c0_groups), },
1273 { "i2c1", x1000_i2c1_groups, ARRAY_SIZE(x1000_i2c1_groups), },
1274 { "i2c2", x1000_i2c2_groups, ARRAY_SIZE(x1000_i2c2_groups), },
1275 { "cim", x1000_cim_groups, ARRAY_SIZE(x1000_cim_groups), },
1276 { "lcd", x1000_lcd_groups, ARRAY_SIZE(x1000_lcd_groups), },
1277 { "pwm0", x1000_pwm0_groups, ARRAY_SIZE(x1000_pwm0_groups), },
1278 { "pwm1", x1000_pwm1_groups, ARRAY_SIZE(x1000_pwm1_groups), },
1279 { "pwm2", x1000_pwm2_groups, ARRAY_SIZE(x1000_pwm2_groups), },
1280 { "pwm3", x1000_pwm3_groups, ARRAY_SIZE(x1000_pwm3_groups), },
1281 { "pwm4", x1000_pwm4_groups, ARRAY_SIZE(x1000_pwm4_groups), },
1282 { "mac", x1000_mac_groups, ARRAY_SIZE(x1000_mac_groups), },
1283};
1284
1285static const struct ingenic_chip_info x1000_chip_info = {
1286 .num_chips = 4,
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +08001287 .reg_offset = 0x100,
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001288 .groups = x1000_groups,
1289 .num_groups = ARRAY_SIZE(x1000_groups),
1290 .functions = x1000_functions,
1291 .num_functions = ARRAY_SIZE(x1000_functions),
1292 .pull_ups = x1000_pull_ups,
1293 .pull_downs = x1000_pull_downs,
1294};
1295
1296static const struct ingenic_chip_info x1000e_chip_info = {
1297 .num_chips = 4,
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +08001298 .reg_offset = 0x100,
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001299 .groups = x1000_groups,
1300 .num_groups = ARRAY_SIZE(x1000_groups),
1301 .functions = x1000_functions,
1302 .num_functions = ARRAY_SIZE(x1000_functions),
1303 .pull_ups = x1000_pull_ups,
1304 .pull_downs = x1000_pull_downs,
1305};
1306
Zhou Yanjie5d215952019-07-14 11:53:56 +08001307static int x1500_uart0_data_pins[] = { 0x4a, 0x4b, };
1308static int x1500_uart0_hwflow_pins[] = { 0x4c, 0x4d, };
1309static int x1500_uart1_data_a_pins[] = { 0x04, 0x05, };
1310static int x1500_uart1_data_d_pins[] = { 0x62, 0x63, };
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001311static int x1500_uart1_hwflow_pins[] = { 0x64, 0x65, };
Zhou Yanjie5d215952019-07-14 11:53:56 +08001312static int x1500_uart2_data_a_pins[] = { 0x02, 0x03, };
1313static int x1500_uart2_data_d_pins[] = { 0x65, 0x64, };
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001314static int x1500_mmc_1bit_pins[] = { 0x18, 0x19, 0x17, };
1315static int x1500_mmc_4bit_pins[] = { 0x16, 0x15, 0x14, };
Zhou Yanjie5d215952019-07-14 11:53:56 +08001316static int x1500_i2c0_pins[] = { 0x38, 0x37, };
1317static int x1500_i2c1_a_pins[] = { 0x01, 0x00, };
1318static int x1500_i2c1_c_pins[] = { 0x5b, 0x5a, };
1319static int x1500_i2c2_pins[] = { 0x61, 0x60, };
1320static int x1500_cim_pins[] = {
1321 0x08, 0x09, 0x0a, 0x0b,
1322 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0c,
1323};
1324static int x1500_pwm_pwm0_pins[] = { 0x59, };
1325static int x1500_pwm_pwm1_pins[] = { 0x5a, };
1326static int x1500_pwm_pwm2_pins[] = { 0x5b, };
1327static int x1500_pwm_pwm3_pins[] = { 0x26, };
1328static int x1500_pwm_pwm4_pins[] = { 0x58, };
1329
1330static int x1500_uart0_data_funcs[] = { 0, 0, };
1331static int x1500_uart0_hwflow_funcs[] = { 0, 0, };
1332static int x1500_uart1_data_a_funcs[] = { 2, 2, };
1333static int x1500_uart1_data_d_funcs[] = { 1, 1, };
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001334static int x1500_uart1_hwflow_funcs[] = { 1, 1, };
Zhou Yanjie5d215952019-07-14 11:53:56 +08001335static int x1500_uart2_data_a_funcs[] = { 2, 2, };
1336static int x1500_uart2_data_d_funcs[] = { 0, 0, };
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001337static int x1500_mmc_1bit_funcs[] = { 1, 1, 1, };
1338static int x1500_mmc_4bit_funcs[] = { 1, 1, 1, };
Zhou Yanjie5d215952019-07-14 11:53:56 +08001339static int x1500_i2c0_funcs[] = { 0, 0, };
1340static int x1500_i2c1_a_funcs[] = { 2, 2, };
1341static int x1500_i2c1_c_funcs[] = { 0, 0, };
1342static int x1500_i2c2_funcs[] = { 1, 1, };
1343static int x1500_cim_funcs[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, };
1344static int x1500_pwm_pwm0_funcs[] = { 0, };
1345static int x1500_pwm_pwm1_funcs[] = { 1, };
1346static int x1500_pwm_pwm2_funcs[] = { 1, };
1347static int x1500_pwm_pwm3_funcs[] = { 2, };
1348static int x1500_pwm_pwm4_funcs[] = { 0, };
1349
1350static const struct group_desc x1500_groups[] = {
1351 INGENIC_PIN_GROUP("uart0-data", x1500_uart0_data),
1352 INGENIC_PIN_GROUP("uart0-hwflow", x1500_uart0_hwflow),
1353 INGENIC_PIN_GROUP("uart1-data-a", x1500_uart1_data_a),
1354 INGENIC_PIN_GROUP("uart1-data-d", x1500_uart1_data_d),
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001355 INGENIC_PIN_GROUP("uart1-hwflow", x1500_uart1_hwflow),
Zhou Yanjie5d215952019-07-14 11:53:56 +08001356 INGENIC_PIN_GROUP("uart2-data-a", x1500_uart2_data_a),
1357 INGENIC_PIN_GROUP("uart2-data-d", x1500_uart2_data_d),
周琰杰 (Zhou Yanjie)3b31e9b2019-12-16 00:21:01 +08001358 INGENIC_PIN_GROUP("sfc", x1000_sfc),
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001359 INGENIC_PIN_GROUP("mmc-1bit", x1500_mmc_1bit),
1360 INGENIC_PIN_GROUP("mmc-4bit", x1500_mmc_4bit),
Zhou Yanjie5d215952019-07-14 11:53:56 +08001361 INGENIC_PIN_GROUP("i2c0-data", x1500_i2c0),
1362 INGENIC_PIN_GROUP("i2c1-data-a", x1500_i2c1_a),
1363 INGENIC_PIN_GROUP("i2c1-data-c", x1500_i2c1_c),
1364 INGENIC_PIN_GROUP("i2c2-data", x1500_i2c2),
1365 INGENIC_PIN_GROUP("cim-data", x1500_cim),
1366 { "lcd-no-pins", },
1367 INGENIC_PIN_GROUP("pwm0", x1500_pwm_pwm0),
1368 INGENIC_PIN_GROUP("pwm1", x1500_pwm_pwm1),
1369 INGENIC_PIN_GROUP("pwm2", x1500_pwm_pwm2),
1370 INGENIC_PIN_GROUP("pwm3", x1500_pwm_pwm3),
1371 INGENIC_PIN_GROUP("pwm4", x1500_pwm_pwm4),
1372};
1373
1374static const char *x1500_uart0_groups[] = { "uart0-data", "uart0-hwflow", };
1375static const char *x1500_uart1_groups[] = {
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001376 "uart1-data-a", "uart1-data-d", "uart1-hwflow",
Zhou Yanjie5d215952019-07-14 11:53:56 +08001377};
1378static const char *x1500_uart2_groups[] = { "uart2-data-a", "uart2-data-d", };
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001379static const char *x1500_mmc_groups[] = { "mmc-1bit", "mmc-4bit", };
Zhou Yanjie5d215952019-07-14 11:53:56 +08001380static const char *x1500_i2c0_groups[] = { "i2c0-data", };
1381static const char *x1500_i2c1_groups[] = { "i2c1-data-a", "i2c1-data-c", };
1382static const char *x1500_i2c2_groups[] = { "i2c2-data", };
1383static const char *x1500_cim_groups[] = { "cim-data", };
1384static const char *x1500_lcd_groups[] = { "lcd-no-pins", };
1385static const char *x1500_pwm0_groups[] = { "pwm0", };
1386static const char *x1500_pwm1_groups[] = { "pwm1", };
1387static const char *x1500_pwm2_groups[] = { "pwm2", };
1388static const char *x1500_pwm3_groups[] = { "pwm3", };
1389static const char *x1500_pwm4_groups[] = { "pwm4", };
1390
1391static const struct function_desc x1500_functions[] = {
1392 { "uart0", x1500_uart0_groups, ARRAY_SIZE(x1500_uart0_groups), },
1393 { "uart1", x1500_uart1_groups, ARRAY_SIZE(x1500_uart1_groups), },
1394 { "uart2", x1500_uart2_groups, ARRAY_SIZE(x1500_uart2_groups), },
周琰杰 (Zhou Yanjie)3b31e9b2019-12-16 00:21:01 +08001395 { "sfc", x1000_sfc_groups, ARRAY_SIZE(x1000_sfc_groups), },
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001396 { "mmc", x1500_mmc_groups, ARRAY_SIZE(x1500_mmc_groups), },
Zhou Yanjie5d215952019-07-14 11:53:56 +08001397 { "i2c0", x1500_i2c0_groups, ARRAY_SIZE(x1500_i2c0_groups), },
1398 { "i2c1", x1500_i2c1_groups, ARRAY_SIZE(x1500_i2c1_groups), },
1399 { "i2c2", x1500_i2c2_groups, ARRAY_SIZE(x1500_i2c2_groups), },
1400 { "cim", x1500_cim_groups, ARRAY_SIZE(x1500_cim_groups), },
1401 { "lcd", x1500_lcd_groups, ARRAY_SIZE(x1500_lcd_groups), },
1402 { "pwm0", x1500_pwm0_groups, ARRAY_SIZE(x1500_pwm0_groups), },
1403 { "pwm1", x1500_pwm1_groups, ARRAY_SIZE(x1500_pwm1_groups), },
1404 { "pwm2", x1500_pwm2_groups, ARRAY_SIZE(x1500_pwm2_groups), },
1405 { "pwm3", x1500_pwm3_groups, ARRAY_SIZE(x1500_pwm3_groups), },
1406 { "pwm4", x1500_pwm4_groups, ARRAY_SIZE(x1500_pwm4_groups), },
1407};
1408
1409static const struct ingenic_chip_info x1500_chip_info = {
1410 .num_chips = 4,
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +08001411 .reg_offset = 0x100,
Zhou Yanjie5d215952019-07-14 11:53:56 +08001412 .groups = x1500_groups,
1413 .num_groups = ARRAY_SIZE(x1500_groups),
1414 .functions = x1500_functions,
1415 .num_functions = ARRAY_SIZE(x1500_functions),
1416 .pull_ups = x1000_pull_ups,
1417 .pull_downs = x1000_pull_downs,
1418};
1419
周琰杰 (Zhou Yanjie)d7da2a12019-12-16 00:21:04 +08001420static const u32 x1830_pull_ups[4] = {
1421 0x5fdfffc0, 0xffffefff, 0x1ffffbff, 0x0fcff3fc,
1422};
1423
1424static const u32 x1830_pull_downs[4] = {
1425 0x5fdfffc0, 0xffffefff, 0x1ffffbff, 0x0fcff3fc,
1426};
1427
1428static int x1830_uart0_data_pins[] = { 0x33, 0x36, };
1429static int x1830_uart0_hwflow_pins[] = { 0x34, 0x35, };
1430static int x1830_uart1_data_pins[] = { 0x38, 0x37, };
1431static int x1830_sfc_pins[] = { 0x17, 0x18, 0x1a, 0x19, 0x1b, 0x1c, };
1432static int x1830_ssi0_dt_pins[] = { 0x4c, };
1433static int x1830_ssi0_dr_pins[] = { 0x4b, };
1434static int x1830_ssi0_clk_pins[] = { 0x4f, };
1435static int x1830_ssi0_gpc_pins[] = { 0x4d, };
1436static int x1830_ssi0_ce0_pins[] = { 0x50, };
1437static int x1830_ssi0_ce1_pins[] = { 0x4e, };
1438static int x1830_ssi1_dt_c_pins[] = { 0x53, };
1439static int x1830_ssi1_dr_c_pins[] = { 0x54, };
1440static int x1830_ssi1_clk_c_pins[] = { 0x57, };
1441static int x1830_ssi1_gpc_c_pins[] = { 0x55, };
1442static int x1830_ssi1_ce0_c_pins[] = { 0x58, };
1443static int x1830_ssi1_ce1_c_pins[] = { 0x56, };
1444static int x1830_ssi1_dt_d_pins[] = { 0x62, };
1445static int x1830_ssi1_dr_d_pins[] = { 0x63, };
1446static int x1830_ssi1_clk_d_pins[] = { 0x66, };
1447static int x1830_ssi1_gpc_d_pins[] = { 0x64, };
1448static int x1830_ssi1_ce0_d_pins[] = { 0x67, };
1449static int x1830_ssi1_ce1_d_pins[] = { 0x65, };
1450static int x1830_mmc0_1bit_pins[] = { 0x24, 0x25, 0x20, };
1451static int x1830_mmc0_4bit_pins[] = { 0x21, 0x22, 0x23, };
1452static int x1830_mmc1_1bit_pins[] = { 0x42, 0x43, 0x44, };
1453static int x1830_mmc1_4bit_pins[] = { 0x45, 0x46, 0x47, };
1454static int x1830_i2c0_pins[] = { 0x0c, 0x0d, };
1455static int x1830_i2c1_pins[] = { 0x39, 0x3a, };
1456static int x1830_i2c2_pins[] = { 0x5b, 0x5c, };
1457static int x1830_pwm_pwm0_b_pins[] = { 0x31, };
1458static int x1830_pwm_pwm0_c_pins[] = { 0x4b, };
1459static int x1830_pwm_pwm1_b_pins[] = { 0x32, };
1460static int x1830_pwm_pwm1_c_pins[] = { 0x4c, };
1461static int x1830_pwm_pwm2_c_8_pins[] = { 0x48, };
1462static int x1830_pwm_pwm2_c_13_pins[] = { 0x4d, };
1463static int x1830_pwm_pwm3_c_9_pins[] = { 0x49, };
1464static int x1830_pwm_pwm3_c_14_pins[] = { 0x4e, };
1465static int x1830_pwm_pwm4_c_15_pins[] = { 0x4f, };
1466static int x1830_pwm_pwm4_c_25_pins[] = { 0x59, };
1467static int x1830_pwm_pwm5_c_16_pins[] = { 0x50, };
1468static int x1830_pwm_pwm5_c_26_pins[] = { 0x5a, };
1469static int x1830_pwm_pwm6_c_17_pins[] = { 0x51, };
1470static int x1830_pwm_pwm6_c_27_pins[] = { 0x5b, };
1471static int x1830_pwm_pwm7_c_18_pins[] = { 0x52, };
1472static int x1830_pwm_pwm7_c_28_pins[] = { 0x5c, };
1473static int x1830_mac_pins[] = {
1474 0x29, 0x30, 0x2f, 0x28, 0x2e, 0x2d, 0x2a, 0x2b, 0x26, 0x27,
1475};
1476
1477static int x1830_uart0_data_funcs[] = { 0, 0, };
1478static int x1830_uart0_hwflow_funcs[] = { 0, 0, };
1479static int x1830_uart1_data_funcs[] = { 0, 0, };
1480static int x1830_sfc_funcs[] = { 1, 1, 1, 1, 1, 1, };
1481static int x1830_ssi0_dt_funcs[] = { 0, };
1482static int x1830_ssi0_dr_funcs[] = { 0, };
1483static int x1830_ssi0_clk_funcs[] = { 0, };
1484static int x1830_ssi0_gpc_funcs[] = { 0, };
1485static int x1830_ssi0_ce0_funcs[] = { 0, };
1486static int x1830_ssi0_ce1_funcs[] = { 0, };
1487static int x1830_ssi1_dt_c_funcs[] = { 1, };
1488static int x1830_ssi1_dr_c_funcs[] = { 1, };
1489static int x1830_ssi1_clk_c_funcs[] = { 1, };
1490static int x1830_ssi1_gpc_c_funcs[] = { 1, };
1491static int x1830_ssi1_ce0_c_funcs[] = { 1, };
1492static int x1830_ssi1_ce1_c_funcs[] = { 1, };
1493static int x1830_ssi1_dt_d_funcs[] = { 2, };
1494static int x1830_ssi1_dr_d_funcs[] = { 2, };
1495static int x1830_ssi1_clk_d_funcs[] = { 2, };
1496static int x1830_ssi1_gpc_d_funcs[] = { 2, };
1497static int x1830_ssi1_ce0_d_funcs[] = { 2, };
1498static int x1830_ssi1_ce1_d_funcs[] = { 2, };
1499static int x1830_mmc0_1bit_funcs[] = { 0, 0, 0, };
1500static int x1830_mmc0_4bit_funcs[] = { 0, 0, 0, };
1501static int x1830_mmc1_1bit_funcs[] = { 0, 0, 0, };
1502static int x1830_mmc1_4bit_funcs[] = { 0, 0, 0, };
1503static int x1830_i2c0_funcs[] = { 1, 1, };
1504static int x1830_i2c1_funcs[] = { 0, 0, };
1505static int x1830_i2c2_funcs[] = { 1, 1, };
1506static int x1830_pwm_pwm0_b_funcs[] = { 0, };
1507static int x1830_pwm_pwm0_c_funcs[] = { 1, };
1508static int x1830_pwm_pwm1_b_funcs[] = { 0, };
1509static int x1830_pwm_pwm1_c_funcs[] = { 1, };
1510static int x1830_pwm_pwm2_c_8_funcs[] = { 0, };
1511static int x1830_pwm_pwm2_c_13_funcs[] = { 1, };
1512static int x1830_pwm_pwm3_c_9_funcs[] = { 0, };
1513static int x1830_pwm_pwm3_c_14_funcs[] = { 1, };
1514static int x1830_pwm_pwm4_c_15_funcs[] = { 1, };
1515static int x1830_pwm_pwm4_c_25_funcs[] = { 0, };
1516static int x1830_pwm_pwm5_c_16_funcs[] = { 1, };
1517static int x1830_pwm_pwm5_c_26_funcs[] = { 0, };
1518static int x1830_pwm_pwm6_c_17_funcs[] = { 1, };
1519static int x1830_pwm_pwm6_c_27_funcs[] = { 0, };
1520static int x1830_pwm_pwm7_c_18_funcs[] = { 1, };
1521static int x1830_pwm_pwm7_c_28_funcs[] = { 0, };
1522static int x1830_mac_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
1523
1524static const struct group_desc x1830_groups[] = {
1525 INGENIC_PIN_GROUP("uart0-data", x1830_uart0_data),
1526 INGENIC_PIN_GROUP("uart0-hwflow", x1830_uart0_hwflow),
1527 INGENIC_PIN_GROUP("uart1-data", x1830_uart1_data),
1528 INGENIC_PIN_GROUP("sfc", x1830_sfc),
1529 INGENIC_PIN_GROUP("ssi0-dt", x1830_ssi0_dt),
1530 INGENIC_PIN_GROUP("ssi0-dr", x1830_ssi0_dr),
1531 INGENIC_PIN_GROUP("ssi0-clk", x1830_ssi0_clk),
1532 INGENIC_PIN_GROUP("ssi0-gpc", x1830_ssi0_gpc),
1533 INGENIC_PIN_GROUP("ssi0-ce0", x1830_ssi0_ce0),
1534 INGENIC_PIN_GROUP("ssi0-ce1", x1830_ssi0_ce1),
1535 INGENIC_PIN_GROUP("ssi1-dt-c", x1830_ssi1_dt_c),
1536 INGENIC_PIN_GROUP("ssi1-dr-c", x1830_ssi1_dr_c),
1537 INGENIC_PIN_GROUP("ssi1-clk-c", x1830_ssi1_clk_c),
1538 INGENIC_PIN_GROUP("ssi1-gpc-c", x1830_ssi1_gpc_c),
1539 INGENIC_PIN_GROUP("ssi1-ce0-c", x1830_ssi1_ce0_c),
1540 INGENIC_PIN_GROUP("ssi1-ce1-c", x1830_ssi1_ce1_c),
1541 INGENIC_PIN_GROUP("ssi1-dt-d", x1830_ssi1_dt_d),
1542 INGENIC_PIN_GROUP("ssi1-dr-d", x1830_ssi1_dr_d),
1543 INGENIC_PIN_GROUP("ssi1-clk-d", x1830_ssi1_clk_d),
1544 INGENIC_PIN_GROUP("ssi1-gpc-d", x1830_ssi1_gpc_d),
1545 INGENIC_PIN_GROUP("ssi1-ce0-d", x1830_ssi1_ce0_d),
1546 INGENIC_PIN_GROUP("ssi1-ce1-d", x1830_ssi1_ce1_d),
1547 INGENIC_PIN_GROUP("mmc0-1bit", x1830_mmc0_1bit),
1548 INGENIC_PIN_GROUP("mmc0-4bit", x1830_mmc0_4bit),
1549 INGENIC_PIN_GROUP("mmc1-1bit", x1830_mmc1_1bit),
1550 INGENIC_PIN_GROUP("mmc1-4bit", x1830_mmc1_4bit),
1551 INGENIC_PIN_GROUP("i2c0-data", x1830_i2c0),
1552 INGENIC_PIN_GROUP("i2c1-data", x1830_i2c1),
1553 INGENIC_PIN_GROUP("i2c2-data", x1830_i2c2),
1554 INGENIC_PIN_GROUP("pwm0-b", x1830_pwm_pwm0_b),
1555 INGENIC_PIN_GROUP("pwm0-c", x1830_pwm_pwm0_c),
1556 INGENIC_PIN_GROUP("pwm1-b", x1830_pwm_pwm1_b),
1557 INGENIC_PIN_GROUP("pwm1-c", x1830_pwm_pwm1_c),
1558 INGENIC_PIN_GROUP("pwm2-c-8", x1830_pwm_pwm2_c_8),
1559 INGENIC_PIN_GROUP("pwm2-c-13", x1830_pwm_pwm2_c_13),
1560 INGENIC_PIN_GROUP("pwm3-c-9", x1830_pwm_pwm3_c_9),
1561 INGENIC_PIN_GROUP("pwm3-c-14", x1830_pwm_pwm3_c_14),
1562 INGENIC_PIN_GROUP("pwm4-c-15", x1830_pwm_pwm4_c_15),
1563 INGENIC_PIN_GROUP("pwm4-c-25", x1830_pwm_pwm4_c_25),
1564 INGENIC_PIN_GROUP("pwm5-c-16", x1830_pwm_pwm5_c_16),
1565 INGENIC_PIN_GROUP("pwm5-c-26", x1830_pwm_pwm5_c_26),
1566 INGENIC_PIN_GROUP("pwm6-c-17", x1830_pwm_pwm6_c_17),
1567 INGENIC_PIN_GROUP("pwm6-c-27", x1830_pwm_pwm6_c_27),
1568 INGENIC_PIN_GROUP("pwm7-c-18", x1830_pwm_pwm7_c_18),
1569 INGENIC_PIN_GROUP("pwm7-c-28", x1830_pwm_pwm7_c_28),
1570 INGENIC_PIN_GROUP("mac", x1830_mac),
1571};
1572
1573static const char *x1830_uart0_groups[] = { "uart0-data", "uart0-hwflow", };
1574static const char *x1830_uart1_groups[] = { "uart1-data", };
1575static const char *x1830_sfc_groups[] = { "sfc", };
1576static const char *x1830_ssi0_groups[] = {
1577 "ssi0-dt", "ssi0-dr", "ssi0-clk", "ssi0-gpc", "ssi0-ce0", "ssi0-ce1",
1578};
1579static const char *x1830_ssi1_groups[] = {
1580 "ssi1-dt-c", "ssi1-dt-d",
1581 "ssi1-dr-c", "ssi1-dr-d",
1582 "ssi1-clk-c", "ssi1-clk-d",
1583 "ssi1-gpc-c", "ssi1-gpc-d",
1584 "ssi1-ce0-c", "ssi1-ce0-d",
1585 "ssi1-ce1-c", "ssi1-ce1-d",
1586};
1587static const char *x1830_mmc0_groups[] = { "mmc0-1bit", "mmc0-4bit", };
1588static const char *x1830_mmc1_groups[] = { "mmc1-1bit", "mmc1-4bit", };
1589static const char *x1830_i2c0_groups[] = { "i2c0-data", };
1590static const char *x1830_i2c1_groups[] = { "i2c1-data", };
1591static const char *x1830_i2c2_groups[] = { "i2c2-data", };
1592static const char *x1830_pwm0_groups[] = { "pwm0-b", "pwm0-c", };
1593static const char *x1830_pwm1_groups[] = { "pwm1-b", "pwm1-c", };
1594static const char *x1830_pwm2_groups[] = { "pwm2-c-8", "pwm2-c-13", };
1595static const char *x1830_pwm3_groups[] = { "pwm3-c-9", "pwm3-c-14", };
1596static const char *x1830_pwm4_groups[] = { "pwm4-c-15", "pwm4-c-25", };
1597static const char *x1830_pwm5_groups[] = { "pwm5-c-16", "pwm5-c-26", };
1598static const char *x1830_pwm6_groups[] = { "pwm6-c-17", "pwm6-c-27", };
1599static const char *x1830_pwm7_groups[] = { "pwm7-c-18", "pwm7-c-28", };
1600static const char *x1830_mac_groups[] = { "mac", };
1601
1602static const struct function_desc x1830_functions[] = {
1603 { "uart0", x1830_uart0_groups, ARRAY_SIZE(x1830_uart0_groups), },
1604 { "uart1", x1830_uart1_groups, ARRAY_SIZE(x1830_uart1_groups), },
1605 { "sfc", x1830_sfc_groups, ARRAY_SIZE(x1830_sfc_groups), },
1606 { "ssi0", x1830_ssi0_groups, ARRAY_SIZE(x1830_ssi0_groups), },
1607 { "ssi1", x1830_ssi1_groups, ARRAY_SIZE(x1830_ssi1_groups), },
1608 { "mmc0", x1830_mmc0_groups, ARRAY_SIZE(x1830_mmc0_groups), },
1609 { "mmc1", x1830_mmc1_groups, ARRAY_SIZE(x1830_mmc1_groups), },
1610 { "i2c0", x1830_i2c0_groups, ARRAY_SIZE(x1830_i2c0_groups), },
1611 { "i2c1", x1830_i2c1_groups, ARRAY_SIZE(x1830_i2c1_groups), },
1612 { "i2c2", x1830_i2c2_groups, ARRAY_SIZE(x1830_i2c2_groups), },
1613 { "pwm0", x1830_pwm0_groups, ARRAY_SIZE(x1830_pwm0_groups), },
1614 { "pwm1", x1830_pwm1_groups, ARRAY_SIZE(x1830_pwm1_groups), },
1615 { "pwm2", x1830_pwm2_groups, ARRAY_SIZE(x1830_pwm2_groups), },
1616 { "pwm3", x1830_pwm3_groups, ARRAY_SIZE(x1830_pwm3_groups), },
1617 { "pwm4", x1830_pwm4_groups, ARRAY_SIZE(x1830_pwm4_groups), },
1618 { "pwm5", x1830_pwm5_groups, ARRAY_SIZE(x1830_pwm4_groups), },
1619 { "pwm6", x1830_pwm6_groups, ARRAY_SIZE(x1830_pwm4_groups), },
1620 { "pwm7", x1830_pwm7_groups, ARRAY_SIZE(x1830_pwm4_groups), },
1621 { "mac", x1830_mac_groups, ARRAY_SIZE(x1830_mac_groups), },
1622};
1623
1624static const struct ingenic_chip_info x1830_chip_info = {
1625 .num_chips = 4,
1626 .reg_offset = 0x1000,
1627 .groups = x1830_groups,
1628 .num_groups = ARRAY_SIZE(x1830_groups),
1629 .functions = x1830_functions,
1630 .num_functions = ARRAY_SIZE(x1830_functions),
1631 .pull_ups = x1830_pull_ups,
1632 .pull_downs = x1830_pull_downs,
1633};
1634
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001635static u32 ingenic_gpio_read_reg(struct ingenic_gpio_chip *jzgc, u8 reg)
Paul Cercueile72394e2018-08-21 18:42:32 +02001636{
1637 unsigned int val;
1638
1639 regmap_read(jzgc->jzpc->map, jzgc->reg_base + reg, &val);
1640
1641 return (u32) val;
1642}
1643
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001644static void ingenic_gpio_set_bit(struct ingenic_gpio_chip *jzgc,
Paul Cercueile72394e2018-08-21 18:42:32 +02001645 u8 reg, u8 offset, bool set)
1646{
1647 if (set)
1648 reg = REG_SET(reg);
1649 else
1650 reg = REG_CLEAR(reg);
1651
1652 regmap_write(jzgc->jzpc->map, jzgc->reg_base + reg, BIT(offset));
1653}
1654
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001655static void ingenic_gpio_shadow_set_bit(struct ingenic_gpio_chip *jzgc,
1656 u8 reg, u8 offset, bool set)
1657{
1658 if (set)
1659 reg = REG_SET(reg);
1660 else
1661 reg = REG_CLEAR(reg);
1662
周琰杰 (Zhou Yanjie)d7da2a12019-12-16 00:21:04 +08001663 regmap_write(jzgc->jzpc->map, REG_PZ_BASE(
1664 jzgc->jzpc->info->reg_offset) + reg, BIT(offset));
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001665}
1666
1667static void ingenic_gpio_shadow_set_bit_load(struct ingenic_gpio_chip *jzgc)
1668{
周琰杰 (Zhou Yanjie)d7da2a12019-12-16 00:21:04 +08001669 regmap_write(jzgc->jzpc->map, REG_PZ_GID2LD(
1670 jzgc->jzpc->info->reg_offset),
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001671 jzgc->gc.base / PINS_PER_GPIO_CHIP);
1672}
1673
Paul Cercueile72394e2018-08-21 18:42:32 +02001674static inline bool ingenic_gpio_get_value(struct ingenic_gpio_chip *jzgc,
1675 u8 offset)
1676{
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001677 unsigned int val = ingenic_gpio_read_reg(jzgc, GPIO_PIN);
Paul Cercueile72394e2018-08-21 18:42:32 +02001678
1679 return !!(val & BIT(offset));
1680}
1681
1682static void ingenic_gpio_set_value(struct ingenic_gpio_chip *jzgc,
1683 u8 offset, int value)
1684{
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001685 if (jzgc->jzpc->version >= ID_JZ4760)
1686 ingenic_gpio_set_bit(jzgc, JZ4760_GPIO_PAT0, offset, !!value);
Paul Cercueile72394e2018-08-21 18:42:32 +02001687 else
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001688 ingenic_gpio_set_bit(jzgc, JZ4740_GPIO_DATA, offset, !!value);
Paul Cercueile72394e2018-08-21 18:42:32 +02001689}
1690
1691static void irq_set_type(struct ingenic_gpio_chip *jzgc,
1692 u8 offset, unsigned int type)
1693{
1694 u8 reg1, reg2;
1695
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001696 if (jzgc->jzpc->version >= ID_JZ4760) {
1697 reg1 = JZ4760_GPIO_PAT1;
1698 reg2 = JZ4760_GPIO_PAT0;
Paul Cercueile72394e2018-08-21 18:42:32 +02001699 } else {
1700 reg1 = JZ4740_GPIO_TRIG;
1701 reg2 = JZ4740_GPIO_DIR;
1702 }
1703
1704 switch (type) {
1705 case IRQ_TYPE_EDGE_RISING:
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001706 if (jzgc->jzpc->version >= ID_X1000) {
1707 ingenic_gpio_shadow_set_bit(jzgc, reg2, offset, true);
1708 ingenic_gpio_shadow_set_bit(jzgc, reg1, offset, true);
1709 ingenic_gpio_shadow_set_bit_load(jzgc);
1710 } else {
1711 ingenic_gpio_set_bit(jzgc, reg2, offset, true);
1712 ingenic_gpio_set_bit(jzgc, reg1, offset, true);
1713 }
Paul Cercueile72394e2018-08-21 18:42:32 +02001714 break;
1715 case IRQ_TYPE_EDGE_FALLING:
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001716 if (jzgc->jzpc->version >= ID_X1000) {
1717 ingenic_gpio_shadow_set_bit(jzgc, reg2, offset, false);
1718 ingenic_gpio_shadow_set_bit(jzgc, reg1, offset, true);
1719 ingenic_gpio_shadow_set_bit_load(jzgc);
1720 } else {
1721 ingenic_gpio_set_bit(jzgc, reg2, offset, false);
1722 ingenic_gpio_set_bit(jzgc, reg1, offset, true);
1723 }
Paul Cercueile72394e2018-08-21 18:42:32 +02001724 break;
1725 case IRQ_TYPE_LEVEL_HIGH:
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001726 if (jzgc->jzpc->version >= ID_X1000) {
1727 ingenic_gpio_shadow_set_bit(jzgc, reg2, offset, true);
1728 ingenic_gpio_shadow_set_bit(jzgc, reg1, offset, false);
1729 ingenic_gpio_shadow_set_bit_load(jzgc);
1730 } else {
1731 ingenic_gpio_set_bit(jzgc, reg2, offset, true);
1732 ingenic_gpio_set_bit(jzgc, reg1, offset, false);
1733 }
Paul Cercueile72394e2018-08-21 18:42:32 +02001734 break;
1735 case IRQ_TYPE_LEVEL_LOW:
1736 default:
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001737 if (jzgc->jzpc->version >= ID_X1000) {
1738 ingenic_gpio_shadow_set_bit(jzgc, reg2, offset, false);
1739 ingenic_gpio_shadow_set_bit(jzgc, reg1, offset, false);
1740 ingenic_gpio_shadow_set_bit_load(jzgc);
1741 } else {
1742 ingenic_gpio_set_bit(jzgc, reg2, offset, false);
1743 ingenic_gpio_set_bit(jzgc, reg1, offset, false);
1744 }
Paul Cercueile72394e2018-08-21 18:42:32 +02001745 break;
1746 }
1747}
1748
1749static void ingenic_gpio_irq_mask(struct irq_data *irqd)
1750{
1751 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
1752 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1753
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001754 ingenic_gpio_set_bit(jzgc, GPIO_MSK, irqd->hwirq, true);
Paul Cercueile72394e2018-08-21 18:42:32 +02001755}
1756
1757static void ingenic_gpio_irq_unmask(struct irq_data *irqd)
1758{
1759 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
1760 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1761
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001762 ingenic_gpio_set_bit(jzgc, GPIO_MSK, irqd->hwirq, false);
Paul Cercueile72394e2018-08-21 18:42:32 +02001763}
1764
1765static void ingenic_gpio_irq_enable(struct irq_data *irqd)
1766{
1767 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
1768 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1769 int irq = irqd->hwirq;
1770
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001771 if (jzgc->jzpc->version >= ID_JZ4760)
1772 ingenic_gpio_set_bit(jzgc, JZ4760_GPIO_INT, irq, true);
Paul Cercueile72394e2018-08-21 18:42:32 +02001773 else
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001774 ingenic_gpio_set_bit(jzgc, JZ4740_GPIO_SELECT, irq, true);
Paul Cercueile72394e2018-08-21 18:42:32 +02001775
1776 ingenic_gpio_irq_unmask(irqd);
1777}
1778
1779static void ingenic_gpio_irq_disable(struct irq_data *irqd)
1780{
1781 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
1782 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1783 int irq = irqd->hwirq;
1784
1785 ingenic_gpio_irq_mask(irqd);
1786
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001787 if (jzgc->jzpc->version >= ID_JZ4760)
1788 ingenic_gpio_set_bit(jzgc, JZ4760_GPIO_INT, irq, false);
Paul Cercueile72394e2018-08-21 18:42:32 +02001789 else
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001790 ingenic_gpio_set_bit(jzgc, JZ4740_GPIO_SELECT, irq, false);
Paul Cercueile72394e2018-08-21 18:42:32 +02001791}
1792
1793static void ingenic_gpio_irq_ack(struct irq_data *irqd)
1794{
1795 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
1796 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1797 int irq = irqd->hwirq;
1798 bool high;
1799
1800 if (irqd_get_trigger_type(irqd) == IRQ_TYPE_EDGE_BOTH) {
1801 /*
1802 * Switch to an interrupt for the opposite edge to the one that
1803 * triggered the interrupt being ACKed.
1804 */
1805 high = ingenic_gpio_get_value(jzgc, irq);
1806 if (high)
1807 irq_set_type(jzgc, irq, IRQ_TYPE_EDGE_FALLING);
1808 else
1809 irq_set_type(jzgc, irq, IRQ_TYPE_EDGE_RISING);
1810 }
1811
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001812 if (jzgc->jzpc->version >= ID_JZ4760)
1813 ingenic_gpio_set_bit(jzgc, JZ4760_GPIO_FLAG, irq, false);
Paul Cercueile72394e2018-08-21 18:42:32 +02001814 else
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001815 ingenic_gpio_set_bit(jzgc, JZ4740_GPIO_DATA, irq, true);
Paul Cercueile72394e2018-08-21 18:42:32 +02001816}
1817
1818static int ingenic_gpio_irq_set_type(struct irq_data *irqd, unsigned int type)
1819{
1820 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
1821 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1822
1823 switch (type) {
1824 case IRQ_TYPE_EDGE_BOTH:
1825 case IRQ_TYPE_EDGE_RISING:
1826 case IRQ_TYPE_EDGE_FALLING:
1827 irq_set_handler_locked(irqd, handle_edge_irq);
1828 break;
1829 case IRQ_TYPE_LEVEL_HIGH:
1830 case IRQ_TYPE_LEVEL_LOW:
1831 irq_set_handler_locked(irqd, handle_level_irq);
1832 break;
1833 default:
1834 irq_set_handler_locked(irqd, handle_bad_irq);
1835 }
1836
1837 if (type == IRQ_TYPE_EDGE_BOTH) {
1838 /*
1839 * The hardware does not support interrupts on both edges. The
1840 * best we can do is to set up a single-edge interrupt and then
1841 * switch to the opposing edge when ACKing the interrupt.
1842 */
1843 bool high = ingenic_gpio_get_value(jzgc, irqd->hwirq);
1844
1845 type = high ? IRQ_TYPE_EDGE_FALLING : IRQ_TYPE_EDGE_RISING;
1846 }
1847
1848 irq_set_type(jzgc, irqd->hwirq, type);
1849 return 0;
1850}
1851
1852static int ingenic_gpio_irq_set_wake(struct irq_data *irqd, unsigned int on)
1853{
1854 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
1855 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1856
1857 return irq_set_irq_wake(jzgc->irq, on);
1858}
1859
1860static void ingenic_gpio_irq_handler(struct irq_desc *desc)
1861{
1862 struct gpio_chip *gc = irq_desc_get_handler_data(desc);
1863 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1864 struct irq_chip *irq_chip = irq_data_get_irq_chip(&desc->irq_data);
1865 unsigned long flag, i;
1866
1867 chained_irq_enter(irq_chip, desc);
1868
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001869 if (jzgc->jzpc->version >= ID_JZ4760)
1870 flag = ingenic_gpio_read_reg(jzgc, JZ4760_GPIO_FLAG);
Paul Cercueile72394e2018-08-21 18:42:32 +02001871 else
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001872 flag = ingenic_gpio_read_reg(jzgc, JZ4740_GPIO_FLAG);
Paul Cercueile72394e2018-08-21 18:42:32 +02001873
1874 for_each_set_bit(i, &flag, 32)
1875 generic_handle_irq(irq_linear_revmap(gc->irq.domain, i));
1876 chained_irq_exit(irq_chip, desc);
1877}
1878
1879static void ingenic_gpio_set(struct gpio_chip *gc,
1880 unsigned int offset, int value)
1881{
1882 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1883
1884 ingenic_gpio_set_value(jzgc, offset, value);
1885}
1886
1887static int ingenic_gpio_get(struct gpio_chip *gc, unsigned int offset)
1888{
1889 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1890
1891 return (int) ingenic_gpio_get_value(jzgc, offset);
1892}
1893
1894static int ingenic_gpio_direction_input(struct gpio_chip *gc,
1895 unsigned int offset)
1896{
1897 return pinctrl_gpio_direction_input(gc->base + offset);
1898}
1899
1900static int ingenic_gpio_direction_output(struct gpio_chip *gc,
1901 unsigned int offset, int value)
1902{
1903 ingenic_gpio_set(gc, offset, value);
1904 return pinctrl_gpio_direction_output(gc->base + offset);
1905}
1906
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001907static inline void ingenic_config_pin(struct ingenic_pinctrl *jzpc,
1908 unsigned int pin, u8 reg, bool set)
1909{
1910 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
1911 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
1912
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +08001913 regmap_write(jzpc->map, offt * jzpc->info->reg_offset +
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001914 (set ? REG_SET(reg) : REG_CLEAR(reg)), BIT(idx));
1915}
1916
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001917static inline void ingenic_shadow_config_pin(struct ingenic_pinctrl *jzpc,
1918 unsigned int pin, u8 reg, bool set)
1919{
1920 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
1921
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +08001922 regmap_write(jzpc->map, REG_PZ_BASE(jzpc->info->reg_offset) +
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001923 (set ? REG_SET(reg) : REG_CLEAR(reg)), BIT(idx));
1924}
1925
1926static inline void ingenic_shadow_config_pin_load(struct ingenic_pinctrl *jzpc,
1927 unsigned int pin)
1928{
周琰杰 (Zhou Yanjie)d7da2a12019-12-16 00:21:04 +08001929 regmap_write(jzpc->map, REG_PZ_GID2LD(jzpc->info->reg_offset),
1930 pin / PINS_PER_GPIO_CHIP);
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001931}
1932
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001933static inline bool ingenic_get_pin_config(struct ingenic_pinctrl *jzpc,
1934 unsigned int pin, u8 reg)
1935{
1936 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
1937 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
1938 unsigned int val;
1939
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +08001940 regmap_read(jzpc->map, offt * jzpc->info->reg_offset + reg, &val);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001941
1942 return val & BIT(idx);
1943}
1944
Paul Cercueilebd66512018-08-21 18:42:33 +02001945static int ingenic_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
1946{
1947 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1948 struct ingenic_pinctrl *jzpc = jzgc->jzpc;
1949 unsigned int pin = gc->base + offset;
1950
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001951 if (jzpc->version >= ID_JZ4760)
1952 return ingenic_get_pin_config(jzpc, pin, JZ4760_GPIO_PAT1);
Paul Cercueilebd66512018-08-21 18:42:33 +02001953
1954 if (ingenic_get_pin_config(jzpc, pin, JZ4740_GPIO_SELECT))
1955 return true;
1956
1957 return !ingenic_get_pin_config(jzpc, pin, JZ4740_GPIO_DIR);
1958}
1959
Julia Lawall5bf7b842017-08-10 12:06:23 +02001960static const struct pinctrl_ops ingenic_pctlops = {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001961 .get_groups_count = pinctrl_generic_get_group_count,
1962 .get_group_name = pinctrl_generic_get_group_name,
1963 .get_group_pins = pinctrl_generic_get_group_pins,
1964 .dt_node_to_map = pinconf_generic_dt_node_to_map_all,
1965 .dt_free_map = pinconf_generic_dt_free_map,
1966};
1967
1968static int ingenic_pinmux_set_pin_fn(struct ingenic_pinctrl *jzpc,
1969 int pin, int func)
1970{
1971 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
1972 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
1973
1974 dev_dbg(jzpc->dev, "set pin P%c%u to function %u\n",
1975 'A' + offt, idx, func);
1976
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001977 if (jzpc->version >= ID_X1000) {
1978 ingenic_shadow_config_pin(jzpc, pin, JZ4760_GPIO_INT, false);
1979 ingenic_shadow_config_pin(jzpc, pin, GPIO_MSK, false);
1980 ingenic_shadow_config_pin(jzpc, pin, JZ4760_GPIO_PAT1, func & 0x2);
1981 ingenic_shadow_config_pin(jzpc, pin, JZ4760_GPIO_PAT0, func & 0x1);
1982 ingenic_shadow_config_pin_load(jzpc, pin);
1983 } else if (jzpc->version >= ID_JZ4760) {
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001984 ingenic_config_pin(jzpc, pin, JZ4760_GPIO_INT, false);
Paul Cercueile72394e2018-08-21 18:42:32 +02001985 ingenic_config_pin(jzpc, pin, GPIO_MSK, false);
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001986 ingenic_config_pin(jzpc, pin, JZ4760_GPIO_PAT1, func & 0x2);
1987 ingenic_config_pin(jzpc, pin, JZ4760_GPIO_PAT0, func & 0x1);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001988 } else {
1989 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_FUNC, true);
1990 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_TRIG, func & 0x2);
1991 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_SELECT, func > 0);
1992 }
1993
1994 return 0;
1995}
1996
1997static int ingenic_pinmux_set_mux(struct pinctrl_dev *pctldev,
1998 unsigned int selector, unsigned int group)
1999{
2000 struct ingenic_pinctrl *jzpc = pinctrl_dev_get_drvdata(pctldev);
2001 struct function_desc *func;
2002 struct group_desc *grp;
2003 unsigned int i;
2004
2005 func = pinmux_generic_get_function(pctldev, selector);
2006 if (!func)
2007 return -EINVAL;
2008
2009 grp = pinctrl_generic_get_group(pctldev, group);
2010 if (!grp)
2011 return -EINVAL;
2012
2013 dev_dbg(pctldev->dev, "enable function %s group %s\n",
2014 func->name, grp->name);
2015
2016 for (i = 0; i < grp->num_pins; i++) {
2017 int *pin_modes = grp->data;
2018
2019 ingenic_pinmux_set_pin_fn(jzpc, grp->pins[i], pin_modes[i]);
2020 }
2021
2022 return 0;
2023}
2024
2025static int ingenic_pinmux_gpio_set_direction(struct pinctrl_dev *pctldev,
2026 struct pinctrl_gpio_range *range,
2027 unsigned int pin, bool input)
2028{
2029 struct ingenic_pinctrl *jzpc = pinctrl_dev_get_drvdata(pctldev);
2030 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
2031 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
2032
2033 dev_dbg(pctldev->dev, "set pin P%c%u to %sput\n",
2034 'A' + offt, idx, input ? "in" : "out");
2035
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08002036 if (jzpc->version >= ID_X1000) {
2037 ingenic_shadow_config_pin(jzpc, pin, JZ4760_GPIO_INT, false);
2038 ingenic_shadow_config_pin(jzpc, pin, GPIO_MSK, true);
2039 ingenic_shadow_config_pin(jzpc, pin, JZ4760_GPIO_PAT1, input);
2040 ingenic_shadow_config_pin_load(jzpc, pin);
2041 } else if (jzpc->version >= ID_JZ4760) {
Zhou Yanjie0257595a2019-07-14 11:53:52 +08002042 ingenic_config_pin(jzpc, pin, JZ4760_GPIO_INT, false);
Paul Cercueile72394e2018-08-21 18:42:32 +02002043 ingenic_config_pin(jzpc, pin, GPIO_MSK, true);
Zhou Yanjie0257595a2019-07-14 11:53:52 +08002044 ingenic_config_pin(jzpc, pin, JZ4760_GPIO_PAT1, input);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002045 } else {
2046 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_SELECT, false);
Paul Cercueil0084a782018-06-27 13:49:02 +02002047 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_DIR, !input);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002048 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_FUNC, false);
2049 }
2050
2051 return 0;
2052}
2053
Julia Lawall5bf7b842017-08-10 12:06:23 +02002054static const struct pinmux_ops ingenic_pmxops = {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002055 .get_functions_count = pinmux_generic_get_function_count,
2056 .get_function_name = pinmux_generic_get_function_name,
2057 .get_function_groups = pinmux_generic_get_function_groups,
2058 .set_mux = ingenic_pinmux_set_mux,
2059 .gpio_set_direction = ingenic_pinmux_gpio_set_direction,
2060};
2061
2062static int ingenic_pinconf_get(struct pinctrl_dev *pctldev,
2063 unsigned int pin, unsigned long *config)
2064{
2065 struct ingenic_pinctrl *jzpc = pinctrl_dev_get_drvdata(pctldev);
2066 enum pin_config_param param = pinconf_to_config_param(*config);
2067 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
2068 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
2069 bool pull;
2070
Zhou Yanjie0257595a2019-07-14 11:53:52 +08002071 if (jzpc->version >= ID_JZ4760)
2072 pull = !ingenic_get_pin_config(jzpc, pin, JZ4760_GPIO_PEN);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002073 else
2074 pull = !ingenic_get_pin_config(jzpc, pin, JZ4740_GPIO_PULL_DIS);
2075
2076 switch (param) {
2077 case PIN_CONFIG_BIAS_DISABLE:
2078 if (pull)
2079 return -EINVAL;
2080 break;
2081
2082 case PIN_CONFIG_BIAS_PULL_UP:
2083 if (!pull || !(jzpc->info->pull_ups[offt] & BIT(idx)))
2084 return -EINVAL;
2085 break;
2086
2087 case PIN_CONFIG_BIAS_PULL_DOWN:
2088 if (!pull || !(jzpc->info->pull_downs[offt] & BIT(idx)))
2089 return -EINVAL;
2090 break;
2091
2092 default:
2093 return -ENOTSUPP;
2094 }
2095
2096 *config = pinconf_to_config_packed(param, 1);
2097 return 0;
2098}
2099
2100static void ingenic_set_bias(struct ingenic_pinctrl *jzpc,
周琰杰 (Zhou Yanjie)d7da2a12019-12-16 00:21:04 +08002101 unsigned int pin, unsigned int bias)
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002102{
周琰杰 (Zhou Yanjie)d7da2a12019-12-16 00:21:04 +08002103 if (jzpc->version >= ID_X1830) {
2104 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
2105 unsigned int half = PINS_PER_GPIO_CHIP / 2;
2106 unsigned int idxh = pin % half * 2;
2107 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
2108
2109 if (idx < half) {
2110 regmap_write(jzpc->map, offt * jzpc->info->reg_offset +
2111 REG_CLEAR(X1830_GPIO_PEL), 3 << idxh);
2112 regmap_write(jzpc->map, offt * jzpc->info->reg_offset +
2113 REG_SET(X1830_GPIO_PEL), bias << idxh);
2114 } else {
2115 regmap_write(jzpc->map, offt * jzpc->info->reg_offset +
2116 REG_CLEAR(X1830_GPIO_PEH), 3 << idxh);
2117 regmap_write(jzpc->map, offt * jzpc->info->reg_offset +
2118 REG_SET(X1830_GPIO_PEH), bias << idxh);
2119 }
2120
2121 } else if (jzpc->version >= ID_JZ4760) {
2122 ingenic_config_pin(jzpc, pin, JZ4760_GPIO_PEN, !bias);
2123 } else {
2124 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_PULL_DIS, !bias);
2125 }
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002126}
2127
Paul Cercueil7009d042019-11-19 16:52:10 +01002128static void ingenic_set_output_level(struct ingenic_pinctrl *jzpc,
2129 unsigned int pin, bool high)
2130{
Paul Cercueil9e655272019-12-10 17:44:46 +01002131 if (jzpc->version >= ID_JZ4760)
Paul Cercueil7009d042019-11-19 16:52:10 +01002132 ingenic_config_pin(jzpc, pin, JZ4760_GPIO_PAT0, high);
2133 else
2134 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_DATA, high);
2135}
2136
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002137static int ingenic_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
2138 unsigned long *configs, unsigned int num_configs)
2139{
2140 struct ingenic_pinctrl *jzpc = pinctrl_dev_get_drvdata(pctldev);
2141 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
2142 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
Paul Cercueil7009d042019-11-19 16:52:10 +01002143 unsigned int cfg, arg;
2144 int ret;
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002145
2146 for (cfg = 0; cfg < num_configs; cfg++) {
2147 switch (pinconf_to_config_param(configs[cfg])) {
2148 case PIN_CONFIG_BIAS_DISABLE:
2149 case PIN_CONFIG_BIAS_PULL_UP:
2150 case PIN_CONFIG_BIAS_PULL_DOWN:
Paul Cercueil7009d042019-11-19 16:52:10 +01002151 case PIN_CONFIG_OUTPUT:
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002152 continue;
2153 default:
2154 return -ENOTSUPP;
2155 }
2156 }
2157
2158 for (cfg = 0; cfg < num_configs; cfg++) {
Paul Cercueil7009d042019-11-19 16:52:10 +01002159 arg = pinconf_to_config_argument(configs[cfg]);
2160
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002161 switch (pinconf_to_config_param(configs[cfg])) {
2162 case PIN_CONFIG_BIAS_DISABLE:
2163 dev_dbg(jzpc->dev, "disable pull-over for pin P%c%u\n",
2164 'A' + offt, idx);
周琰杰 (Zhou Yanjie)d7da2a12019-12-16 00:21:04 +08002165 ingenic_set_bias(jzpc, pin, GPIO_PULL_DIS);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002166 break;
2167
2168 case PIN_CONFIG_BIAS_PULL_UP:
2169 if (!(jzpc->info->pull_ups[offt] & BIT(idx)))
2170 return -EINVAL;
2171 dev_dbg(jzpc->dev, "set pull-up for pin P%c%u\n",
2172 'A' + offt, idx);
周琰杰 (Zhou Yanjie)d7da2a12019-12-16 00:21:04 +08002173 ingenic_set_bias(jzpc, pin, GPIO_PULL_UP);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002174 break;
2175
2176 case PIN_CONFIG_BIAS_PULL_DOWN:
2177 if (!(jzpc->info->pull_downs[offt] & BIT(idx)))
2178 return -EINVAL;
2179 dev_dbg(jzpc->dev, "set pull-down for pin P%c%u\n",
2180 'A' + offt, idx);
周琰杰 (Zhou Yanjie)d7da2a12019-12-16 00:21:04 +08002181 ingenic_set_bias(jzpc, pin, GPIO_PULL_DOWN);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002182 break;
2183
Paul Cercueil7009d042019-11-19 16:52:10 +01002184 case PIN_CONFIG_OUTPUT:
2185 ret = pinctrl_gpio_direction_output(pin);
2186 if (ret)
2187 return ret;
2188
2189 ingenic_set_output_level(jzpc, pin, arg);
2190 break;
2191
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002192 default:
2193 unreachable();
2194 }
2195 }
2196
2197 return 0;
2198}
2199
2200static int ingenic_pinconf_group_get(struct pinctrl_dev *pctldev,
2201 unsigned int group, unsigned long *config)
2202{
2203 const unsigned int *pins;
2204 unsigned int i, npins, old = 0;
2205 int ret;
2206
2207 ret = pinctrl_generic_get_group_pins(pctldev, group, &pins, &npins);
2208 if (ret)
2209 return ret;
2210
2211 for (i = 0; i < npins; i++) {
2212 if (ingenic_pinconf_get(pctldev, pins[i], config))
2213 return -ENOTSUPP;
2214
2215 /* configs do not match between two pins */
2216 if (i && (old != *config))
2217 return -ENOTSUPP;
2218
2219 old = *config;
2220 }
2221
2222 return 0;
2223}
2224
2225static int ingenic_pinconf_group_set(struct pinctrl_dev *pctldev,
2226 unsigned int group, unsigned long *configs,
2227 unsigned int num_configs)
2228{
2229 const unsigned int *pins;
2230 unsigned int i, npins;
2231 int ret;
2232
2233 ret = pinctrl_generic_get_group_pins(pctldev, group, &pins, &npins);
2234 if (ret)
2235 return ret;
2236
2237 for (i = 0; i < npins; i++) {
2238 ret = ingenic_pinconf_set(pctldev,
2239 pins[i], configs, num_configs);
2240 if (ret)
2241 return ret;
2242 }
2243
2244 return 0;
2245}
2246
Julia Lawall5bf7b842017-08-10 12:06:23 +02002247static const struct pinconf_ops ingenic_confops = {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002248 .is_generic = true,
2249 .pin_config_get = ingenic_pinconf_get,
2250 .pin_config_set = ingenic_pinconf_set,
2251 .pin_config_group_get = ingenic_pinconf_group_get,
2252 .pin_config_group_set = ingenic_pinconf_group_set,
2253};
2254
2255static const struct regmap_config ingenic_pinctrl_regmap_config = {
2256 .reg_bits = 32,
2257 .val_bits = 32,
2258 .reg_stride = 4,
2259};
2260
2261static const struct of_device_id ingenic_pinctrl_of_match[] = {
2262 { .compatible = "ingenic,jz4740-pinctrl", .data = (void *) ID_JZ4740 },
Paul Cercueilf2a96762018-08-21 18:42:34 +02002263 { .compatible = "ingenic,jz4725b-pinctrl", .data = (void *)ID_JZ4725B },
Zhou Yanjie0257595a2019-07-14 11:53:52 +08002264 { .compatible = "ingenic,jz4760-pinctrl", .data = (void *) ID_JZ4760 },
2265 { .compatible = "ingenic,jz4760b-pinctrl", .data = (void *) ID_JZ4760B },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002266 { .compatible = "ingenic,jz4770-pinctrl", .data = (void *) ID_JZ4770 },
2267 { .compatible = "ingenic,jz4780-pinctrl", .data = (void *) ID_JZ4780 },
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08002268 { .compatible = "ingenic,x1000-pinctrl", .data = (void *) ID_X1000 },
2269 { .compatible = "ingenic,x1000e-pinctrl", .data = (void *) ID_X1000E },
Zhou Yanjie5d215952019-07-14 11:53:56 +08002270 { .compatible = "ingenic,x1500-pinctrl", .data = (void *) ID_X1500 },
周琰杰 (Zhou Yanjie)d7da2a12019-12-16 00:21:04 +08002271 { .compatible = "ingenic,x1830-pinctrl", .data = (void *) ID_X1830 },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002272 {},
2273};
2274
Paul Cercueile72394e2018-08-21 18:42:32 +02002275static const struct of_device_id ingenic_gpio_of_match[] __initconst = {
2276 { .compatible = "ingenic,jz4740-gpio", },
Zhou Yanjie0257595a2019-07-14 11:53:52 +08002277 { .compatible = "ingenic,jz4760-gpio", },
Paul Cercueile72394e2018-08-21 18:42:32 +02002278 { .compatible = "ingenic,jz4770-gpio", },
2279 { .compatible = "ingenic,jz4780-gpio", },
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08002280 { .compatible = "ingenic,x1000-gpio", },
周琰杰 (Zhou Yanjie)d7da2a12019-12-16 00:21:04 +08002281 { .compatible = "ingenic,x1830-gpio", },
Paul Cercueile72394e2018-08-21 18:42:32 +02002282 {},
2283};
2284
2285static int __init ingenic_gpio_probe(struct ingenic_pinctrl *jzpc,
2286 struct device_node *node)
2287{
2288 struct ingenic_gpio_chip *jzgc;
2289 struct device *dev = jzpc->dev;
Linus Walleij142b8762019-10-01 15:32:09 +02002290 struct gpio_irq_chip *girq;
Paul Cercueile72394e2018-08-21 18:42:32 +02002291 unsigned int bank;
2292 int err;
2293
2294 err = of_property_read_u32(node, "reg", &bank);
2295 if (err) {
2296 dev_err(dev, "Cannot read \"reg\" property: %i\n", err);
2297 return err;
2298 }
2299
2300 jzgc = devm_kzalloc(dev, sizeof(*jzgc), GFP_KERNEL);
2301 if (!jzgc)
2302 return -ENOMEM;
2303
2304 jzgc->jzpc = jzpc;
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +08002305 jzgc->reg_base = bank * jzpc->info->reg_offset;
Paul Cercueile72394e2018-08-21 18:42:32 +02002306
2307 jzgc->gc.label = devm_kasprintf(dev, GFP_KERNEL, "GPIO%c", 'A' + bank);
2308 if (!jzgc->gc.label)
2309 return -ENOMEM;
2310
2311 /* DO NOT EXPAND THIS: FOR BACKWARD GPIO NUMBERSPACE COMPATIBIBILITY
2312 * ONLY: WORK TO TRANSITION CONSUMERS TO USE THE GPIO DESCRIPTOR API IN
2313 * <linux/gpio/consumer.h> INSTEAD.
2314 */
2315 jzgc->gc.base = bank * 32;
2316
2317 jzgc->gc.ngpio = 32;
2318 jzgc->gc.parent = dev;
2319 jzgc->gc.of_node = node;
2320 jzgc->gc.owner = THIS_MODULE;
2321
2322 jzgc->gc.set = ingenic_gpio_set;
2323 jzgc->gc.get = ingenic_gpio_get;
2324 jzgc->gc.direction_input = ingenic_gpio_direction_input;
2325 jzgc->gc.direction_output = ingenic_gpio_direction_output;
Paul Cercueilebd66512018-08-21 18:42:33 +02002326 jzgc->gc.get_direction = ingenic_gpio_get_direction;
Paul Cercueile72394e2018-08-21 18:42:32 +02002327
2328 if (of_property_read_bool(node, "gpio-ranges")) {
2329 jzgc->gc.request = gpiochip_generic_request;
2330 jzgc->gc.free = gpiochip_generic_free;
2331 }
2332
Paul Cercueile72394e2018-08-21 18:42:32 +02002333 jzgc->irq = irq_of_parse_and_map(node, 0);
2334 if (!jzgc->irq)
2335 return -EINVAL;
2336
2337 jzgc->irq_chip.name = jzgc->gc.label;
2338 jzgc->irq_chip.irq_enable = ingenic_gpio_irq_enable;
2339 jzgc->irq_chip.irq_disable = ingenic_gpio_irq_disable;
2340 jzgc->irq_chip.irq_unmask = ingenic_gpio_irq_unmask;
2341 jzgc->irq_chip.irq_mask = ingenic_gpio_irq_mask;
2342 jzgc->irq_chip.irq_ack = ingenic_gpio_irq_ack;
2343 jzgc->irq_chip.irq_set_type = ingenic_gpio_irq_set_type;
2344 jzgc->irq_chip.irq_set_wake = ingenic_gpio_irq_set_wake;
2345 jzgc->irq_chip.flags = IRQCHIP_MASK_ON_SUSPEND;
2346
Linus Walleij142b8762019-10-01 15:32:09 +02002347 girq = &jzgc->gc.irq;
2348 girq->chip = &jzgc->irq_chip;
2349 girq->parent_handler = ingenic_gpio_irq_handler;
2350 girq->num_parents = 1;
2351 girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents),
2352 GFP_KERNEL);
2353 if (!girq->parents)
2354 return -ENOMEM;
2355 girq->parents[0] = jzgc->irq;
2356 girq->default_type = IRQ_TYPE_NONE;
2357 girq->handler = handle_level_irq;
2358
2359 err = devm_gpiochip_add_data(dev, &jzgc->gc, jzgc);
Paul Cercueile72394e2018-08-21 18:42:32 +02002360 if (err)
2361 return err;
2362
Paul Cercueile72394e2018-08-21 18:42:32 +02002363 return 0;
2364}
2365
Paul Cercueil4717b112018-08-21 18:42:31 +02002366static int __init ingenic_pinctrl_probe(struct platform_device *pdev)
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002367{
2368 struct device *dev = &pdev->dev;
2369 struct ingenic_pinctrl *jzpc;
2370 struct pinctrl_desc *pctl_desc;
2371 void __iomem *base;
2372 const struct platform_device_id *id = platform_get_device_id(pdev);
2373 const struct of_device_id *of_id = of_match_device(
2374 ingenic_pinctrl_of_match, dev);
2375 const struct ingenic_chip_info *chip_info;
Paul Cercueile72394e2018-08-21 18:42:32 +02002376 struct device_node *node;
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002377 unsigned int i;
2378 int err;
2379
2380 jzpc = devm_kzalloc(dev, sizeof(*jzpc), GFP_KERNEL);
2381 if (!jzpc)
2382 return -ENOMEM;
2383
2384 base = devm_ioremap_resource(dev,
2385 platform_get_resource(pdev, IORESOURCE_MEM, 0));
Wei Yongjun119fcf42018-01-17 11:29:17 +00002386 if (IS_ERR(base))
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002387 return PTR_ERR(base);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002388
2389 jzpc->map = devm_regmap_init_mmio(dev, base,
2390 &ingenic_pinctrl_regmap_config);
2391 if (IS_ERR(jzpc->map)) {
2392 dev_err(dev, "Failed to create regmap\n");
2393 return PTR_ERR(jzpc->map);
2394 }
2395
2396 jzpc->dev = dev;
2397
2398 if (of_id)
2399 jzpc->version = (enum jz_version)of_id->data;
2400 else
2401 jzpc->version = (enum jz_version)id->driver_data;
2402
周琰杰 (Zhou Yanjie)d7da2a12019-12-16 00:21:04 +08002403 if (jzpc->version >= ID_X1830)
2404 chip_info = &x1830_chip_info;
2405 else if (jzpc->version >= ID_X1500)
Zhou Yanjie5d215952019-07-14 11:53:56 +08002406 chip_info = &x1500_chip_info;
2407 else if (jzpc->version >= ID_X1000E)
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08002408 chip_info = &x1000e_chip_info;
2409 else if (jzpc->version >= ID_X1000)
2410 chip_info = &x1000_chip_info;
2411 else if (jzpc->version >= ID_JZ4780)
Zhou Yanjieff656e42019-01-28 23:19:57 +08002412 chip_info = &jz4780_chip_info;
2413 else if (jzpc->version >= ID_JZ4770)
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002414 chip_info = &jz4770_chip_info;
Zhou Yanjie0257595a2019-07-14 11:53:52 +08002415 else if (jzpc->version >= ID_JZ4760B)
2416 chip_info = &jz4760b_chip_info;
2417 else if (jzpc->version >= ID_JZ4760)
2418 chip_info = &jz4760_chip_info;
Paul Cercueilf2a96762018-08-21 18:42:34 +02002419 else if (jzpc->version >= ID_JZ4725B)
2420 chip_info = &jz4725b_chip_info;
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002421 else
2422 chip_info = &jz4740_chip_info;
2423 jzpc->info = chip_info;
2424
2425 pctl_desc = devm_kzalloc(&pdev->dev, sizeof(*pctl_desc), GFP_KERNEL);
2426 if (!pctl_desc)
2427 return -ENOMEM;
2428
2429 /* fill in pinctrl_desc structure */
2430 pctl_desc->name = dev_name(dev);
2431 pctl_desc->owner = THIS_MODULE;
2432 pctl_desc->pctlops = &ingenic_pctlops;
2433 pctl_desc->pmxops = &ingenic_pmxops;
2434 pctl_desc->confops = &ingenic_confops;
2435 pctl_desc->npins = chip_info->num_chips * PINS_PER_GPIO_CHIP;
Kees Cooka86854d2018-06-12 14:07:58 -07002436 pctl_desc->pins = jzpc->pdesc = devm_kcalloc(&pdev->dev,
2437 pctl_desc->npins, sizeof(*jzpc->pdesc), GFP_KERNEL);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002438 if (!jzpc->pdesc)
2439 return -ENOMEM;
2440
2441 for (i = 0; i < pctl_desc->npins; i++) {
2442 jzpc->pdesc[i].number = i;
2443 jzpc->pdesc[i].name = kasprintf(GFP_KERNEL, "P%c%d",
2444 'A' + (i / PINS_PER_GPIO_CHIP),
2445 i % PINS_PER_GPIO_CHIP);
2446 }
2447
2448 jzpc->pctl = devm_pinctrl_register(dev, pctl_desc, jzpc);
Dan Carpentere7f4c4b2017-06-14 12:12:09 +03002449 if (IS_ERR(jzpc->pctl)) {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002450 dev_err(dev, "Failed to register pinctrl\n");
Dan Carpentere7f4c4b2017-06-14 12:12:09 +03002451 return PTR_ERR(jzpc->pctl);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002452 }
2453
2454 for (i = 0; i < chip_info->num_groups; i++) {
2455 const struct group_desc *group = &chip_info->groups[i];
2456
2457 err = pinctrl_generic_add_group(jzpc->pctl, group->name,
2458 group->pins, group->num_pins, group->data);
Paul Burton823dd712018-08-25 10:53:28 -07002459 if (err < 0) {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002460 dev_err(dev, "Failed to register group %s\n",
2461 group->name);
2462 return err;
2463 }
2464 }
2465
2466 for (i = 0; i < chip_info->num_functions; i++) {
2467 const struct function_desc *func = &chip_info->functions[i];
2468
2469 err = pinmux_generic_add_function(jzpc->pctl, func->name,
2470 func->group_names, func->num_group_names,
2471 func->data);
Paul Burton823dd712018-08-25 10:53:28 -07002472 if (err < 0) {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002473 dev_err(dev, "Failed to register function %s\n",
2474 func->name);
2475 return err;
2476 }
2477 }
2478
2479 dev_set_drvdata(dev, jzpc->map);
2480
Paul Cercueile72394e2018-08-21 18:42:32 +02002481 for_each_child_of_node(dev->of_node, node) {
2482 if (of_match_node(ingenic_gpio_of_match, node)) {
2483 err = ingenic_gpio_probe(jzpc, node);
2484 if (err)
2485 return err;
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002486 }
2487 }
2488
2489 return 0;
2490}
2491
2492static const struct platform_device_id ingenic_pinctrl_ids[] = {
2493 { "jz4740-pinctrl", ID_JZ4740 },
Paul Cercueilf2a96762018-08-21 18:42:34 +02002494 { "jz4725b-pinctrl", ID_JZ4725B },
Zhou Yanjie0257595a2019-07-14 11:53:52 +08002495 { "jz4760-pinctrl", ID_JZ4760 },
2496 { "jz4760b-pinctrl", ID_JZ4760B },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002497 { "jz4770-pinctrl", ID_JZ4770 },
2498 { "jz4780-pinctrl", ID_JZ4780 },
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08002499 { "x1000-pinctrl", ID_X1000 },
2500 { "x1000e-pinctrl", ID_X1000E },
Zhou Yanjie5d215952019-07-14 11:53:56 +08002501 { "x1500-pinctrl", ID_X1500 },
周琰杰 (Zhou Yanjie)d7da2a12019-12-16 00:21:04 +08002502 { "x1830-pinctrl", ID_X1830 },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002503 {},
2504};
2505
2506static struct platform_driver ingenic_pinctrl_driver = {
2507 .driver = {
2508 .name = "pinctrl-ingenic",
2509 .of_match_table = of_match_ptr(ingenic_pinctrl_of_match),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002510 },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002511 .id_table = ingenic_pinctrl_ids,
2512};
2513
2514static int __init ingenic_pinctrl_drv_register(void)
2515{
Paul Cercueil4717b112018-08-21 18:42:31 +02002516 return platform_driver_probe(&ingenic_pinctrl_driver,
2517 ingenic_pinctrl_probe);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002518}
Paul Cercueil556a36a2018-08-21 18:42:30 +02002519subsys_initcall(ingenic_pinctrl_drv_register);