blob: 2b3f7e4708b0370e8c6335d87907b7c357d0394b [file] [log] [blame]
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001/*
2 * Ingenic SoCs pinctrl driver
3 *
4 * Copyright (c) 2017 Paul Cercueil <paul@crapouillou.net>
5 *
6 * License terms: GNU General Public License (GPL) version 2
7 */
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
39#define JZ4770_GPIO_INT 0x10
Paul Cercueilb5c23aa2017-05-12 18:52:56 +020040#define JZ4770_GPIO_PAT1 0x30
41#define JZ4770_GPIO_PAT0 0x40
42#define JZ4770_GPIO_FLAG 0x50
43#define JZ4770_GPIO_PEN 0x70
44
45#define REG_SET(x) ((x) + 0x4)
46#define REG_CLEAR(x) ((x) + 0x8)
47
48#define PINS_PER_GPIO_CHIP 32
49
50enum jz_version {
51 ID_JZ4740,
Paul Cercueilf2a96762018-08-21 18:42:34 +020052 ID_JZ4725B,
Paul Cercueilb5c23aa2017-05-12 18:52:56 +020053 ID_JZ4770,
54 ID_JZ4780,
55};
56
57struct ingenic_chip_info {
58 unsigned int num_chips;
59
60 const struct group_desc *groups;
61 unsigned int num_groups;
62
63 const struct function_desc *functions;
64 unsigned int num_functions;
65
66 const u32 *pull_ups, *pull_downs;
67};
68
69struct ingenic_pinctrl {
70 struct device *dev;
71 struct regmap *map;
72 struct pinctrl_dev *pctl;
73 struct pinctrl_pin_desc *pdesc;
74 enum jz_version version;
75
76 const struct ingenic_chip_info *info;
77};
78
Paul Cercueile72394e2018-08-21 18:42:32 +020079struct ingenic_gpio_chip {
80 struct ingenic_pinctrl *jzpc;
81 struct gpio_chip gc;
82 struct irq_chip irq_chip;
83 unsigned int irq, reg_base;
84};
85
Paul Cercueilb5c23aa2017-05-12 18:52:56 +020086static const u32 jz4740_pull_ups[4] = {
87 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
88};
89
90static const u32 jz4740_pull_downs[4] = {
91 0x00000000, 0x00000000, 0x00000000, 0x00000000,
92};
93
94static int jz4740_mmc_1bit_pins[] = { 0x69, 0x68, 0x6a, };
95static int jz4740_mmc_4bit_pins[] = { 0x6b, 0x6c, 0x6d, };
96static int jz4740_uart0_data_pins[] = { 0x7a, 0x79, };
97static int jz4740_uart0_hwflow_pins[] = { 0x7e, 0x7f, };
98static int jz4740_uart1_data_pins[] = { 0x7e, 0x7f, };
99static int jz4740_lcd_8bit_pins[] = {
100 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x52, 0x53, 0x54,
101};
102static int jz4740_lcd_16bit_pins[] = {
103 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x55,
104};
105static int jz4740_lcd_18bit_pins[] = { 0x50, 0x51, };
106static int jz4740_lcd_18bit_tft_pins[] = { 0x56, 0x57, 0x31, 0x32, };
107static int jz4740_nand_cs1_pins[] = { 0x39, };
108static int jz4740_nand_cs2_pins[] = { 0x3a, };
109static int jz4740_nand_cs3_pins[] = { 0x3b, };
110static int jz4740_nand_cs4_pins[] = { 0x3c, };
111static int jz4740_pwm_pwm0_pins[] = { 0x77, };
112static int jz4740_pwm_pwm1_pins[] = { 0x78, };
113static int jz4740_pwm_pwm2_pins[] = { 0x79, };
114static int jz4740_pwm_pwm3_pins[] = { 0x7a, };
115static int jz4740_pwm_pwm4_pins[] = { 0x7b, };
116static int jz4740_pwm_pwm5_pins[] = { 0x7c, };
117static int jz4740_pwm_pwm6_pins[] = { 0x7e, };
118static int jz4740_pwm_pwm7_pins[] = { 0x7f, };
119
120static int jz4740_mmc_1bit_funcs[] = { 0, 0, 0, };
121static int jz4740_mmc_4bit_funcs[] = { 0, 0, 0, };
122static int jz4740_uart0_data_funcs[] = { 1, 1, };
123static int jz4740_uart0_hwflow_funcs[] = { 1, 1, };
124static int jz4740_uart1_data_funcs[] = { 2, 2, };
125static int jz4740_lcd_8bit_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
126static int jz4740_lcd_16bit_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, };
127static int jz4740_lcd_18bit_funcs[] = { 0, 0, };
128static int jz4740_lcd_18bit_tft_funcs[] = { 0, 0, 0, 0, };
129static int jz4740_nand_cs1_funcs[] = { 0, };
130static int jz4740_nand_cs2_funcs[] = { 0, };
131static int jz4740_nand_cs3_funcs[] = { 0, };
132static int jz4740_nand_cs4_funcs[] = { 0, };
133static int jz4740_pwm_pwm0_funcs[] = { 0, };
134static int jz4740_pwm_pwm1_funcs[] = { 0, };
135static int jz4740_pwm_pwm2_funcs[] = { 0, };
136static int jz4740_pwm_pwm3_funcs[] = { 0, };
137static int jz4740_pwm_pwm4_funcs[] = { 0, };
138static int jz4740_pwm_pwm5_funcs[] = { 0, };
139static int jz4740_pwm_pwm6_funcs[] = { 0, };
140static int jz4740_pwm_pwm7_funcs[] = { 0, };
141
142#define INGENIC_PIN_GROUP(name, id) \
143 { \
144 name, \
145 id##_pins, \
146 ARRAY_SIZE(id##_pins), \
147 id##_funcs, \
148 }
149
150static const struct group_desc jz4740_groups[] = {
151 INGENIC_PIN_GROUP("mmc-1bit", jz4740_mmc_1bit),
152 INGENIC_PIN_GROUP("mmc-4bit", jz4740_mmc_4bit),
153 INGENIC_PIN_GROUP("uart0-data", jz4740_uart0_data),
154 INGENIC_PIN_GROUP("uart0-hwflow", jz4740_uart0_hwflow),
155 INGENIC_PIN_GROUP("uart1-data", jz4740_uart1_data),
156 INGENIC_PIN_GROUP("lcd-8bit", jz4740_lcd_8bit),
157 INGENIC_PIN_GROUP("lcd-16bit", jz4740_lcd_16bit),
158 INGENIC_PIN_GROUP("lcd-18bit", jz4740_lcd_18bit),
159 INGENIC_PIN_GROUP("lcd-18bit-tft", jz4740_lcd_18bit_tft),
160 { "lcd-no-pins", },
161 INGENIC_PIN_GROUP("nand-cs1", jz4740_nand_cs1),
162 INGENIC_PIN_GROUP("nand-cs2", jz4740_nand_cs2),
163 INGENIC_PIN_GROUP("nand-cs3", jz4740_nand_cs3),
164 INGENIC_PIN_GROUP("nand-cs4", jz4740_nand_cs4),
165 INGENIC_PIN_GROUP("pwm0", jz4740_pwm_pwm0),
166 INGENIC_PIN_GROUP("pwm1", jz4740_pwm_pwm1),
167 INGENIC_PIN_GROUP("pwm2", jz4740_pwm_pwm2),
168 INGENIC_PIN_GROUP("pwm3", jz4740_pwm_pwm3),
169 INGENIC_PIN_GROUP("pwm4", jz4740_pwm_pwm4),
170 INGENIC_PIN_GROUP("pwm5", jz4740_pwm_pwm5),
171 INGENIC_PIN_GROUP("pwm6", jz4740_pwm_pwm6),
172 INGENIC_PIN_GROUP("pwm7", jz4740_pwm_pwm7),
173};
174
175static const char *jz4740_mmc_groups[] = { "mmc-1bit", "mmc-4bit", };
176static const char *jz4740_uart0_groups[] = { "uart0-data", "uart0-hwflow", };
177static const char *jz4740_uart1_groups[] = { "uart1-data", };
178static const char *jz4740_lcd_groups[] = {
179 "lcd-8bit", "lcd-16bit", "lcd-18bit", "lcd-18bit-tft", "lcd-no-pins",
180};
181static const char *jz4740_nand_groups[] = {
182 "nand-cs1", "nand-cs2", "nand-cs3", "nand-cs4",
183};
184static const char *jz4740_pwm0_groups[] = { "pwm0", };
185static const char *jz4740_pwm1_groups[] = { "pwm1", };
186static const char *jz4740_pwm2_groups[] = { "pwm2", };
187static const char *jz4740_pwm3_groups[] = { "pwm3", };
188static const char *jz4740_pwm4_groups[] = { "pwm4", };
189static const char *jz4740_pwm5_groups[] = { "pwm5", };
190static const char *jz4740_pwm6_groups[] = { "pwm6", };
191static const char *jz4740_pwm7_groups[] = { "pwm7", };
192
193static const struct function_desc jz4740_functions[] = {
194 { "mmc", jz4740_mmc_groups, ARRAY_SIZE(jz4740_mmc_groups), },
195 { "uart0", jz4740_uart0_groups, ARRAY_SIZE(jz4740_uart0_groups), },
196 { "uart1", jz4740_uart1_groups, ARRAY_SIZE(jz4740_uart1_groups), },
197 { "lcd", jz4740_lcd_groups, ARRAY_SIZE(jz4740_lcd_groups), },
198 { "nand", jz4740_nand_groups, ARRAY_SIZE(jz4740_nand_groups), },
199 { "pwm0", jz4740_pwm0_groups, ARRAY_SIZE(jz4740_pwm0_groups), },
200 { "pwm1", jz4740_pwm1_groups, ARRAY_SIZE(jz4740_pwm1_groups), },
201 { "pwm2", jz4740_pwm2_groups, ARRAY_SIZE(jz4740_pwm2_groups), },
202 { "pwm3", jz4740_pwm3_groups, ARRAY_SIZE(jz4740_pwm3_groups), },
203 { "pwm4", jz4740_pwm4_groups, ARRAY_SIZE(jz4740_pwm4_groups), },
204 { "pwm5", jz4740_pwm5_groups, ARRAY_SIZE(jz4740_pwm5_groups), },
205 { "pwm6", jz4740_pwm6_groups, ARRAY_SIZE(jz4740_pwm6_groups), },
206 { "pwm7", jz4740_pwm7_groups, ARRAY_SIZE(jz4740_pwm7_groups), },
207};
208
209static const struct ingenic_chip_info jz4740_chip_info = {
210 .num_chips = 4,
211 .groups = jz4740_groups,
212 .num_groups = ARRAY_SIZE(jz4740_groups),
213 .functions = jz4740_functions,
214 .num_functions = ARRAY_SIZE(jz4740_functions),
215 .pull_ups = jz4740_pull_ups,
216 .pull_downs = jz4740_pull_downs,
217};
218
Paul Cercueilf2a96762018-08-21 18:42:34 +0200219static int jz4725b_mmc0_1bit_pins[] = { 0x48, 0x49, 0x5c, };
220static int jz4725b_mmc0_4bit_pins[] = { 0x5d, 0x5b, 0x56, };
221static int jz4725b_mmc1_1bit_pins[] = { 0x7a, 0x7b, 0x7c, };
222static int jz4725b_mmc1_4bit_pins[] = { 0x7d, 0x7e, 0x7f, };
223static int jz4725b_uart_data_pins[] = { 0x4c, 0x4d, };
224static int jz4725b_nand_cs1_pins[] = { 0x55, };
225static int jz4725b_nand_cs2_pins[] = { 0x56, };
226static int jz4725b_nand_cs3_pins[] = { 0x57, };
227static int jz4725b_nand_cs4_pins[] = { 0x58, };
228static int jz4725b_nand_cle_ale_pins[] = { 0x48, 0x49 };
229static int jz4725b_nand_fre_fwe_pins[] = { 0x5c, 0x5d };
230static int jz4725b_pwm_pwm0_pins[] = { 0x4a, };
231static int jz4725b_pwm_pwm1_pins[] = { 0x4b, };
232static int jz4725b_pwm_pwm2_pins[] = { 0x4c, };
233static int jz4725b_pwm_pwm3_pins[] = { 0x4d, };
234static int jz4725b_pwm_pwm4_pins[] = { 0x4e, };
235static int jz4725b_pwm_pwm5_pins[] = { 0x4f, };
236
237static int jz4725b_mmc0_1bit_funcs[] = { 1, 1, 1, };
238static int jz4725b_mmc0_4bit_funcs[] = { 1, 0, 1, };
239static int jz4725b_mmc1_1bit_funcs[] = { 0, 0, 0, };
240static int jz4725b_mmc1_4bit_funcs[] = { 0, 0, 0, };
241static int jz4725b_uart_data_funcs[] = { 1, 1, };
242static int jz4725b_nand_cs1_funcs[] = { 0, };
243static int jz4725b_nand_cs2_funcs[] = { 0, };
244static int jz4725b_nand_cs3_funcs[] = { 0, };
245static int jz4725b_nand_cs4_funcs[] = { 0, };
246static int jz4725b_nand_cle_ale_funcs[] = { 0, 0, };
247static int jz4725b_nand_fre_fwe_funcs[] = { 0, 0, };
248static int jz4725b_pwm_pwm0_funcs[] = { 0, };
249static int jz4725b_pwm_pwm1_funcs[] = { 0, };
250static int jz4725b_pwm_pwm2_funcs[] = { 0, };
251static int jz4725b_pwm_pwm3_funcs[] = { 0, };
252static int jz4725b_pwm_pwm4_funcs[] = { 0, };
253static int jz4725b_pwm_pwm5_funcs[] = { 0, };
254
255static const struct group_desc jz4725b_groups[] = {
256 INGENIC_PIN_GROUP("mmc0-1bit", jz4725b_mmc0_1bit),
257 INGENIC_PIN_GROUP("mmc0-4bit", jz4725b_mmc0_4bit),
258 INGENIC_PIN_GROUP("mmc1-1bit", jz4725b_mmc1_1bit),
259 INGENIC_PIN_GROUP("mmc1-4bit", jz4725b_mmc1_4bit),
260 INGENIC_PIN_GROUP("uart-data", jz4725b_uart_data),
261 INGENIC_PIN_GROUP("nand-cs1", jz4725b_nand_cs1),
262 INGENIC_PIN_GROUP("nand-cs2", jz4725b_nand_cs2),
263 INGENIC_PIN_GROUP("nand-cs3", jz4725b_nand_cs3),
264 INGENIC_PIN_GROUP("nand-cs4", jz4725b_nand_cs4),
265 INGENIC_PIN_GROUP("nand-cle-ale", jz4725b_nand_cle_ale),
266 INGENIC_PIN_GROUP("nand-fre-fwe", jz4725b_nand_fre_fwe),
267 INGENIC_PIN_GROUP("pwm0", jz4725b_pwm_pwm0),
268 INGENIC_PIN_GROUP("pwm1", jz4725b_pwm_pwm1),
269 INGENIC_PIN_GROUP("pwm2", jz4725b_pwm_pwm2),
270 INGENIC_PIN_GROUP("pwm3", jz4725b_pwm_pwm3),
271 INGENIC_PIN_GROUP("pwm4", jz4725b_pwm_pwm4),
272 INGENIC_PIN_GROUP("pwm5", jz4725b_pwm_pwm5),
273};
274
275static const char *jz4725b_mmc0_groups[] = { "mmc0-1bit", "mmc0-4bit", };
276static const char *jz4725b_mmc1_groups[] = { "mmc1-1bit", "mmc1-4bit", };
277static const char *jz4725b_uart_groups[] = { "uart-data", };
278static const char *jz4725b_nand_groups[] = {
279 "nand-cs1", "nand-cs2", "nand-cs3", "nand-cs4",
280 "nand-cle-ale", "nand-fre-fwe",
281};
282static const char *jz4725b_pwm0_groups[] = { "pwm0", };
283static const char *jz4725b_pwm1_groups[] = { "pwm1", };
284static const char *jz4725b_pwm2_groups[] = { "pwm2", };
285static const char *jz4725b_pwm3_groups[] = { "pwm3", };
286static const char *jz4725b_pwm4_groups[] = { "pwm4", };
287static const char *jz4725b_pwm5_groups[] = { "pwm5", };
288
289static const struct function_desc jz4725b_functions[] = {
290 { "mmc0", jz4725b_mmc0_groups, ARRAY_SIZE(jz4725b_mmc0_groups), },
291 { "mmc1", jz4725b_mmc1_groups, ARRAY_SIZE(jz4725b_mmc1_groups), },
292 { "uart", jz4725b_uart_groups, ARRAY_SIZE(jz4725b_uart_groups), },
293 { "nand", jz4725b_nand_groups, ARRAY_SIZE(jz4725b_nand_groups), },
294 { "pwm0", jz4725b_pwm0_groups, ARRAY_SIZE(jz4725b_pwm0_groups), },
295 { "pwm1", jz4725b_pwm1_groups, ARRAY_SIZE(jz4725b_pwm1_groups), },
296 { "pwm2", jz4725b_pwm2_groups, ARRAY_SIZE(jz4725b_pwm2_groups), },
297 { "pwm3", jz4725b_pwm3_groups, ARRAY_SIZE(jz4725b_pwm3_groups), },
298 { "pwm4", jz4725b_pwm4_groups, ARRAY_SIZE(jz4725b_pwm4_groups), },
299 { "pwm5", jz4725b_pwm5_groups, ARRAY_SIZE(jz4725b_pwm5_groups), },
300};
301
302static const struct ingenic_chip_info jz4725b_chip_info = {
303 .num_chips = 4,
304 .groups = jz4725b_groups,
305 .num_groups = ARRAY_SIZE(jz4725b_groups),
306 .functions = jz4725b_functions,
307 .num_functions = ARRAY_SIZE(jz4725b_functions),
308 .pull_ups = jz4740_pull_ups,
309 .pull_downs = jz4740_pull_downs,
310};
311
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200312static const u32 jz4770_pull_ups[6] = {
313 0x3fffffff, 0xfff0030c, 0xffffffff, 0xffff4fff, 0xfffffb7c, 0xffa7f00f,
314};
315
316static const u32 jz4770_pull_downs[6] = {
317 0x00000000, 0x000f0c03, 0x00000000, 0x0000b000, 0x00000483, 0x00580ff0,
318};
319
320static int jz4770_uart0_data_pins[] = { 0xa0, 0xa3, };
321static int jz4770_uart0_hwflow_pins[] = { 0xa1, 0xa2, };
322static int jz4770_uart1_data_pins[] = { 0x7a, 0x7c, };
323static int jz4770_uart1_hwflow_pins[] = { 0x7b, 0x7d, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800324static int jz4770_uart2_data_pins[] = { 0x5c, 0x5e, };
325static int jz4770_uart2_hwflow_pins[] = { 0x5d, 0x5f, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200326static int jz4770_uart3_data_pins[] = { 0x6c, 0x85, };
327static int jz4770_uart3_hwflow_pins[] = { 0x88, 0x89, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200328static int jz4770_mmc0_1bit_a_pins[] = { 0x12, 0x13, 0x14, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800329static int jz4770_mmc0_4bit_a_pins[] = { 0x15, 0x16, 0x17, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200330static int jz4770_mmc0_1bit_e_pins[] = { 0x9c, 0x9d, 0x94, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800331static int jz4770_mmc0_4bit_e_pins[] = { 0x95, 0x96, 0x97, };
332static int jz4770_mmc0_8bit_e_pins[] = { 0x98, 0x99, 0x9a, 0x9b, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200333static int jz4770_mmc1_1bit_d_pins[] = { 0x78, 0x79, 0x74, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800334static int jz4770_mmc1_4bit_d_pins[] = { 0x75, 0x76, 0x77, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200335static int jz4770_mmc1_1bit_e_pins[] = { 0x9c, 0x9d, 0x94, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800336static int jz4770_mmc1_4bit_e_pins[] = { 0x95, 0x96, 0x97, };
337static int jz4770_mmc1_8bit_e_pins[] = { 0x98, 0x99, 0x9a, 0x9b, };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800338static int jz4770_mmc2_1bit_b_pins[] = { 0x3c, 0x3d, 0x34, };
339static int jz4770_mmc2_4bit_b_pins[] = { 0x35, 0x3e, 0x3f, };
340static int jz4770_mmc2_1bit_e_pins[] = { 0x9c, 0x9d, 0x94, };
341static int jz4770_mmc2_4bit_e_pins[] = { 0x95, 0x96, 0x97, };
342static int jz4770_mmc2_8bit_e_pins[] = { 0x98, 0x99, 0x9a, 0x9b, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800343static int jz4770_nemc_8bit_data_pins[] = {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200344 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
345};
Zhou Yanjieff656e42019-01-28 23:19:57 +0800346static int jz4770_nemc_16bit_data_pins[] = {
347 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
348};
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200349static int jz4770_nemc_cle_ale_pins[] = { 0x20, 0x21, };
350static int jz4770_nemc_addr_pins[] = { 0x22, 0x23, 0x24, 0x25, };
351static int jz4770_nemc_rd_we_pins[] = { 0x10, 0x11, };
352static int jz4770_nemc_frd_fwe_pins[] = { 0x12, 0x13, };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800353static int jz4770_nemc_wait_pins[] = { 0x1b, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200354static int jz4770_nemc_cs1_pins[] = { 0x15, };
355static int jz4770_nemc_cs2_pins[] = { 0x16, };
356static int jz4770_nemc_cs3_pins[] = { 0x17, };
357static int jz4770_nemc_cs4_pins[] = { 0x18, };
358static int jz4770_nemc_cs5_pins[] = { 0x19, };
359static int jz4770_nemc_cs6_pins[] = { 0x1a, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800360static int jz4770_i2c0_pins[] = { 0x7e, 0x7f, };
361static int jz4770_i2c1_pins[] = { 0x9e, 0x9f, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200362static int jz4770_i2c2_pins[] = { 0xb0, 0xb1, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800363static int jz4770_cim_8bit_pins[] = {
364 0x26, 0x27, 0x28, 0x29,
365 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31,
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200366};
Zhou Yanjieff656e42019-01-28 23:19:57 +0800367static int jz4770_cim_12bit_pins[] = {
368 0x32, 0x33, 0xb0, 0xb1,
369};
370static int jz4770_lcd_24bit_pins[] = {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200371 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
372 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
373 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
Zhou Yanjieff656e42019-01-28 23:19:57 +0800374 0x58, 0x59, 0x5a, 0x5b,
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200375};
376static int jz4770_pwm_pwm0_pins[] = { 0x80, };
377static int jz4770_pwm_pwm1_pins[] = { 0x81, };
378static int jz4770_pwm_pwm2_pins[] = { 0x82, };
379static int jz4770_pwm_pwm3_pins[] = { 0x83, };
380static int jz4770_pwm_pwm4_pins[] = { 0x84, };
381static int jz4770_pwm_pwm5_pins[] = { 0x85, };
382static int jz4770_pwm_pwm6_pins[] = { 0x6a, };
383static int jz4770_pwm_pwm7_pins[] = { 0x6b, };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800384static int jz4770_mac_rmii_pins[] = {
385 0xa9, 0xab, 0xaa, 0xac, 0xa5, 0xa4, 0xad, 0xae, 0xa6, 0xa8,
386};
387static int jz4770_mac_mii_pins[] = { 0xa7, 0xaf, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200388
389static int jz4770_uart0_data_funcs[] = { 0, 0, };
390static int jz4770_uart0_hwflow_funcs[] = { 0, 0, };
391static int jz4770_uart1_data_funcs[] = { 0, 0, };
392static int jz4770_uart1_hwflow_funcs[] = { 0, 0, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800393static int jz4770_uart2_data_funcs[] = { 0, 0, };
394static int jz4770_uart2_hwflow_funcs[] = { 0, 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200395static int jz4770_uart3_data_funcs[] = { 0, 1, };
396static int jz4770_uart3_hwflow_funcs[] = { 0, 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200397static int jz4770_mmc0_1bit_a_funcs[] = { 1, 1, 0, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800398static int jz4770_mmc0_4bit_a_funcs[] = { 1, 1, 1, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200399static int jz4770_mmc0_1bit_e_funcs[] = { 0, 0, 0, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800400static int jz4770_mmc0_4bit_e_funcs[] = { 0, 0, 0, };
401static int jz4770_mmc0_8bit_e_funcs[] = { 0, 0, 0, 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200402static int jz4770_mmc1_1bit_d_funcs[] = { 0, 0, 0, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800403static int jz4770_mmc1_4bit_d_funcs[] = { 0, 0, 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200404static int jz4770_mmc1_1bit_e_funcs[] = { 1, 1, 1, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800405static int jz4770_mmc1_4bit_e_funcs[] = { 1, 1, 1, };
406static int jz4770_mmc1_8bit_e_funcs[] = { 1, 1, 1, 1, };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800407static int jz4770_mmc2_1bit_b_funcs[] = { 0, 0, 0, };
408static int jz4770_mmc2_4bit_b_funcs[] = { 0, 0, 0, };
409static int jz4770_mmc2_1bit_e_funcs[] = { 2, 2, 2, };
410static int jz4770_mmc2_4bit_e_funcs[] = { 2, 2, 2, };
411static int jz4770_mmc2_8bit_e_funcs[] = { 2, 2, 2, 2, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800412static int jz4770_nemc_8bit_data_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, };
413static int jz4770_nemc_16bit_data_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200414static int jz4770_nemc_cle_ale_funcs[] = { 0, 0, };
415static int jz4770_nemc_addr_funcs[] = { 0, 0, 0, 0, };
416static int jz4770_nemc_rd_we_funcs[] = { 0, 0, };
417static int jz4770_nemc_frd_fwe_funcs[] = { 0, 0, };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800418static int jz4770_nemc_wait_funcs[] = { 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200419static int jz4770_nemc_cs1_funcs[] = { 0, };
420static int jz4770_nemc_cs2_funcs[] = { 0, };
421static int jz4770_nemc_cs3_funcs[] = { 0, };
422static int jz4770_nemc_cs4_funcs[] = { 0, };
423static int jz4770_nemc_cs5_funcs[] = { 0, };
424static int jz4770_nemc_cs6_funcs[] = { 0, };
425static int jz4770_i2c0_funcs[] = { 0, 0, };
426static int jz4770_i2c1_funcs[] = { 0, 0, };
427static int jz4770_i2c2_funcs[] = { 2, 2, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800428static int jz4770_cim_8bit_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
429static int jz4770_cim_12bit_funcs[] = { 0, 0, 0, 0, };
430static int jz4770_lcd_24bit_funcs[] = {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200431 0, 0, 0, 0, 0, 0, 0, 0,
432 0, 0, 0, 0, 0, 0, 0, 0,
Zhou Yanjieff656e42019-01-28 23:19:57 +0800433 0, 0, 0, 0, 0, 0, 0, 0,
434 0, 0, 0, 0,
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200435};
436static int jz4770_pwm_pwm0_funcs[] = { 0, };
437static int jz4770_pwm_pwm1_funcs[] = { 0, };
438static int jz4770_pwm_pwm2_funcs[] = { 0, };
439static int jz4770_pwm_pwm3_funcs[] = { 0, };
440static int jz4770_pwm_pwm4_funcs[] = { 0, };
441static int jz4770_pwm_pwm5_funcs[] = { 0, };
442static int jz4770_pwm_pwm6_funcs[] = { 0, };
443static int jz4770_pwm_pwm7_funcs[] = { 0, };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800444static int jz4770_mac_rmii_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
445static int jz4770_mac_mii_funcs[] = { 0, 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200446
447static const struct group_desc jz4770_groups[] = {
448 INGENIC_PIN_GROUP("uart0-data", jz4770_uart0_data),
449 INGENIC_PIN_GROUP("uart0-hwflow", jz4770_uart0_hwflow),
450 INGENIC_PIN_GROUP("uart1-data", jz4770_uart1_data),
451 INGENIC_PIN_GROUP("uart1-hwflow", jz4770_uart1_hwflow),
452 INGENIC_PIN_GROUP("uart2-data", jz4770_uart2_data),
453 INGENIC_PIN_GROUP("uart2-hwflow", jz4770_uart2_hwflow),
454 INGENIC_PIN_GROUP("uart3-data", jz4770_uart3_data),
455 INGENIC_PIN_GROUP("uart3-hwflow", jz4770_uart3_hwflow),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200456 INGENIC_PIN_GROUP("mmc0-1bit-a", jz4770_mmc0_1bit_a),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800457 INGENIC_PIN_GROUP("mmc0-4bit-a", jz4770_mmc0_4bit_a),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200458 INGENIC_PIN_GROUP("mmc0-1bit-e", jz4770_mmc0_1bit_e),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800459 INGENIC_PIN_GROUP("mmc0-4bit-e", jz4770_mmc0_4bit_e),
460 INGENIC_PIN_GROUP("mmc0-8bit-e", jz4770_mmc0_8bit_e),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200461 INGENIC_PIN_GROUP("mmc1-1bit-d", jz4770_mmc1_1bit_d),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800462 INGENIC_PIN_GROUP("mmc1-4bit-d", jz4770_mmc1_4bit_d),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200463 INGENIC_PIN_GROUP("mmc1-1bit-e", jz4770_mmc1_1bit_e),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800464 INGENIC_PIN_GROUP("mmc1-4bit-e", jz4770_mmc1_4bit_e),
465 INGENIC_PIN_GROUP("mmc1-8bit-e", jz4770_mmc1_8bit_e),
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800466 INGENIC_PIN_GROUP("mmc2-1bit-b", jz4770_mmc2_1bit_b),
467 INGENIC_PIN_GROUP("mmc2-4bit-b", jz4770_mmc2_4bit_b),
468 INGENIC_PIN_GROUP("mmc2-1bit-e", jz4770_mmc2_1bit_e),
469 INGENIC_PIN_GROUP("mmc2-4bit-e", jz4770_mmc2_4bit_e),
470 INGENIC_PIN_GROUP("mmc2-8bit-e", jz4770_mmc2_8bit_e),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800471 INGENIC_PIN_GROUP("nemc-8bit-data", jz4770_nemc_8bit_data),
472 INGENIC_PIN_GROUP("nemc-16bit-data", jz4770_nemc_16bit_data),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200473 INGENIC_PIN_GROUP("nemc-cle-ale", jz4770_nemc_cle_ale),
474 INGENIC_PIN_GROUP("nemc-addr", jz4770_nemc_addr),
475 INGENIC_PIN_GROUP("nemc-rd-we", jz4770_nemc_rd_we),
476 INGENIC_PIN_GROUP("nemc-frd-fwe", jz4770_nemc_frd_fwe),
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800477 INGENIC_PIN_GROUP("nemc-wait", jz4770_nemc_wait),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200478 INGENIC_PIN_GROUP("nemc-cs1", jz4770_nemc_cs1),
479 INGENIC_PIN_GROUP("nemc-cs2", jz4770_nemc_cs2),
480 INGENIC_PIN_GROUP("nemc-cs3", jz4770_nemc_cs3),
481 INGENIC_PIN_GROUP("nemc-cs4", jz4770_nemc_cs4),
482 INGENIC_PIN_GROUP("nemc-cs5", jz4770_nemc_cs5),
483 INGENIC_PIN_GROUP("nemc-cs6", jz4770_nemc_cs6),
484 INGENIC_PIN_GROUP("i2c0-data", jz4770_i2c0),
485 INGENIC_PIN_GROUP("i2c1-data", jz4770_i2c1),
486 INGENIC_PIN_GROUP("i2c2-data", jz4770_i2c2),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800487 INGENIC_PIN_GROUP("cim-data-8bit", jz4770_cim_8bit),
488 INGENIC_PIN_GROUP("cim-data-12bit", jz4770_cim_12bit),
489 INGENIC_PIN_GROUP("lcd-24bit", jz4770_lcd_24bit),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200490 { "lcd-no-pins", },
491 INGENIC_PIN_GROUP("pwm0", jz4770_pwm_pwm0),
492 INGENIC_PIN_GROUP("pwm1", jz4770_pwm_pwm1),
493 INGENIC_PIN_GROUP("pwm2", jz4770_pwm_pwm2),
494 INGENIC_PIN_GROUP("pwm3", jz4770_pwm_pwm3),
495 INGENIC_PIN_GROUP("pwm4", jz4770_pwm_pwm4),
496 INGENIC_PIN_GROUP("pwm5", jz4770_pwm_pwm5),
497 INGENIC_PIN_GROUP("pwm6", jz4770_pwm_pwm6),
498 INGENIC_PIN_GROUP("pwm7", jz4770_pwm_pwm7),
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800499 INGENIC_PIN_GROUP("mac-rmii", jz4770_mac_rmii),
500 INGENIC_PIN_GROUP("mac-mii", jz4770_mac_mii),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200501};
502
503static const char *jz4770_uart0_groups[] = { "uart0-data", "uart0-hwflow", };
504static const char *jz4770_uart1_groups[] = { "uart1-data", "uart1-hwflow", };
505static const char *jz4770_uart2_groups[] = { "uart2-data", "uart2-hwflow", };
506static const char *jz4770_uart3_groups[] = { "uart3-data", "uart3-hwflow", };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200507static const char *jz4770_mmc0_groups[] = {
Zhou Yanjieff656e42019-01-28 23:19:57 +0800508 "mmc0-1bit-a", "mmc0-4bit-a",
509 "mmc0-1bit-e", "mmc0-4bit-e", "mmc0-8bit-e",
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200510};
511static const char *jz4770_mmc1_groups[] = {
Zhou Yanjieff656e42019-01-28 23:19:57 +0800512 "mmc1-1bit-d", "mmc1-4bit-d",
513 "mmc1-1bit-e", "mmc1-4bit-e", "mmc1-8bit-e",
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200514};
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800515static const char *jz4770_mmc2_groups[] = {
516 "mmc2-1bit-b", "mmc2-4bit-b",
517 "mmc2-1bit-e", "mmc2-4bit-e", "mmc2-8bit-e",
518};
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200519static const char *jz4770_nemc_groups[] = {
Zhou Yanjieff656e42019-01-28 23:19:57 +0800520 "nemc-8bit-data", "nemc-16bit-data", "nemc-cle-ale",
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800521 "nemc-addr", "nemc-rd-we", "nemc-frd-fwe", "nemc-wait",
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200522};
523static const char *jz4770_cs1_groups[] = { "nemc-cs1", };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800524static const char *jz4770_cs2_groups[] = { "nemc-cs2", };
525static const char *jz4770_cs3_groups[] = { "nemc-cs3", };
526static const char *jz4770_cs4_groups[] = { "nemc-cs4", };
527static const char *jz4770_cs5_groups[] = { "nemc-cs5", };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200528static const char *jz4770_cs6_groups[] = { "nemc-cs6", };
529static const char *jz4770_i2c0_groups[] = { "i2c0-data", };
530static const char *jz4770_i2c1_groups[] = { "i2c1-data", };
531static const char *jz4770_i2c2_groups[] = { "i2c2-data", };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800532static const char *jz4770_cim_groups[] = { "cim-data-8bit", "cim-data-12bit", };
533static const char *jz4770_lcd_groups[] = { "lcd-24bit", "lcd-no-pins", };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200534static const char *jz4770_pwm0_groups[] = { "pwm0", };
535static const char *jz4770_pwm1_groups[] = { "pwm1", };
536static const char *jz4770_pwm2_groups[] = { "pwm2", };
537static const char *jz4770_pwm3_groups[] = { "pwm3", };
538static const char *jz4770_pwm4_groups[] = { "pwm4", };
539static const char *jz4770_pwm5_groups[] = { "pwm5", };
540static const char *jz4770_pwm6_groups[] = { "pwm6", };
541static const char *jz4770_pwm7_groups[] = { "pwm7", };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800542static const char *jz4770_mac_groups[] = { "mac-rmii", "mac-mii", };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200543
544static const struct function_desc jz4770_functions[] = {
545 { "uart0", jz4770_uart0_groups, ARRAY_SIZE(jz4770_uart0_groups), },
546 { "uart1", jz4770_uart1_groups, ARRAY_SIZE(jz4770_uart1_groups), },
547 { "uart2", jz4770_uart2_groups, ARRAY_SIZE(jz4770_uart2_groups), },
548 { "uart3", jz4770_uart3_groups, ARRAY_SIZE(jz4770_uart3_groups), },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200549 { "mmc0", jz4770_mmc0_groups, ARRAY_SIZE(jz4770_mmc0_groups), },
550 { "mmc1", jz4770_mmc1_groups, ARRAY_SIZE(jz4770_mmc1_groups), },
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800551 { "mmc2", jz4770_mmc2_groups, ARRAY_SIZE(jz4770_mmc2_groups), },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200552 { "nemc", jz4770_nemc_groups, ARRAY_SIZE(jz4770_nemc_groups), },
553 { "nemc-cs1", jz4770_cs1_groups, ARRAY_SIZE(jz4770_cs1_groups), },
Zhou Yanjieff656e42019-01-28 23:19:57 +0800554 { "nemc-cs2", jz4770_cs2_groups, ARRAY_SIZE(jz4770_cs2_groups), },
555 { "nemc-cs3", jz4770_cs3_groups, ARRAY_SIZE(jz4770_cs3_groups), },
556 { "nemc-cs4", jz4770_cs4_groups, ARRAY_SIZE(jz4770_cs4_groups), },
557 { "nemc-cs5", jz4770_cs5_groups, ARRAY_SIZE(jz4770_cs5_groups), },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200558 { "nemc-cs6", jz4770_cs6_groups, ARRAY_SIZE(jz4770_cs6_groups), },
559 { "i2c0", jz4770_i2c0_groups, ARRAY_SIZE(jz4770_i2c0_groups), },
560 { "i2c1", jz4770_i2c1_groups, ARRAY_SIZE(jz4770_i2c1_groups), },
561 { "i2c2", jz4770_i2c2_groups, ARRAY_SIZE(jz4770_i2c2_groups), },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200562 { "cim", jz4770_cim_groups, ARRAY_SIZE(jz4770_cim_groups), },
563 { "lcd", jz4770_lcd_groups, ARRAY_SIZE(jz4770_lcd_groups), },
564 { "pwm0", jz4770_pwm0_groups, ARRAY_SIZE(jz4770_pwm0_groups), },
565 { "pwm1", jz4770_pwm1_groups, ARRAY_SIZE(jz4770_pwm1_groups), },
566 { "pwm2", jz4770_pwm2_groups, ARRAY_SIZE(jz4770_pwm2_groups), },
567 { "pwm3", jz4770_pwm3_groups, ARRAY_SIZE(jz4770_pwm3_groups), },
568 { "pwm4", jz4770_pwm4_groups, ARRAY_SIZE(jz4770_pwm4_groups), },
569 { "pwm5", jz4770_pwm5_groups, ARRAY_SIZE(jz4770_pwm5_groups), },
570 { "pwm6", jz4770_pwm6_groups, ARRAY_SIZE(jz4770_pwm6_groups), },
571 { "pwm7", jz4770_pwm7_groups, ARRAY_SIZE(jz4770_pwm7_groups), },
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800572 { "mac", jz4770_mac_groups, ARRAY_SIZE(jz4770_mac_groups), },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200573};
574
575static const struct ingenic_chip_info jz4770_chip_info = {
576 .num_chips = 6,
577 .groups = jz4770_groups,
578 .num_groups = ARRAY_SIZE(jz4770_groups),
579 .functions = jz4770_functions,
580 .num_functions = ARRAY_SIZE(jz4770_functions),
581 .pull_ups = jz4770_pull_ups,
582 .pull_downs = jz4770_pull_downs,
583};
584
Zhou Yanjieff656e42019-01-28 23:19:57 +0800585static int jz4780_uart2_data_pins[] = { 0x66, 0x67, };
586static int jz4780_uart2_hwflow_pins[] = { 0x65, 0x64, };
587static int jz4780_uart4_data_pins[] = { 0x54, 0x4a, };
588static int jz4780_mmc0_8bit_a_pins[] = { 0x04, 0x05, 0x06, 0x07, 0x18, };
589static int jz4780_i2c3_pins[] = { 0x6a, 0x6b, };
590static int jz4780_i2c4_e_pins[] = { 0x8c, 0x8d, };
591static int jz4780_i2c4_f_pins[] = { 0xb9, 0xb8, };
592
593static int jz4780_uart2_data_funcs[] = { 1, 1, };
594static int jz4780_uart2_hwflow_funcs[] = { 1, 1, };
595static int jz4780_uart4_data_funcs[] = { 2, 2, };
596static int jz4780_mmc0_8bit_a_funcs[] = { 1, 1, 1, 1, 1, };
597static int jz4780_i2c3_funcs[] = { 1, 1, };
598static int jz4780_i2c4_e_funcs[] = { 1, 1, };
599static int jz4780_i2c4_f_funcs[] = { 1, 1, };
600
601static const struct group_desc jz4780_groups[] = {
602 INGENIC_PIN_GROUP("uart0-data", jz4770_uart0_data),
603 INGENIC_PIN_GROUP("uart0-hwflow", jz4770_uart0_hwflow),
604 INGENIC_PIN_GROUP("uart1-data", jz4770_uart1_data),
605 INGENIC_PIN_GROUP("uart1-hwflow", jz4770_uart1_hwflow),
606 INGENIC_PIN_GROUP("uart2-data", jz4780_uart2_data),
607 INGENIC_PIN_GROUP("uart2-hwflow", jz4780_uart2_hwflow),
608 INGENIC_PIN_GROUP("uart3-data", jz4770_uart3_data),
609 INGENIC_PIN_GROUP("uart3-hwflow", jz4770_uart3_hwflow),
610 INGENIC_PIN_GROUP("uart4-data", jz4780_uart4_data),
611 INGENIC_PIN_GROUP("mmc0-1bit-a", jz4770_mmc0_1bit_a),
612 INGENIC_PIN_GROUP("mmc0-4bit-a", jz4770_mmc0_4bit_a),
613 INGENIC_PIN_GROUP("mmc0-8bit-a", jz4780_mmc0_8bit_a),
614 INGENIC_PIN_GROUP("mmc0-1bit-e", jz4770_mmc0_1bit_e),
615 INGENIC_PIN_GROUP("mmc0-4bit-e", jz4770_mmc0_4bit_e),
616 INGENIC_PIN_GROUP("mmc1-1bit-d", jz4770_mmc1_1bit_d),
617 INGENIC_PIN_GROUP("mmc1-4bit-d", jz4770_mmc1_4bit_d),
618 INGENIC_PIN_GROUP("mmc1-1bit-e", jz4770_mmc1_1bit_e),
619 INGENIC_PIN_GROUP("mmc1-4bit-e", jz4770_mmc1_4bit_e),
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800620 INGENIC_PIN_GROUP("mmc2-1bit-b", jz4770_mmc2_1bit_b),
621 INGENIC_PIN_GROUP("mmc2-4bit-b", jz4770_mmc2_4bit_b),
622 INGENIC_PIN_GROUP("mmc2-1bit-e", jz4770_mmc2_1bit_e),
623 INGENIC_PIN_GROUP("mmc2-4bit-e", jz4770_mmc2_4bit_e),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800624 INGENIC_PIN_GROUP("nemc-data", jz4770_nemc_8bit_data),
625 INGENIC_PIN_GROUP("nemc-cle-ale", jz4770_nemc_cle_ale),
626 INGENIC_PIN_GROUP("nemc-addr", jz4770_nemc_addr),
627 INGENIC_PIN_GROUP("nemc-rd-we", jz4770_nemc_rd_we),
628 INGENIC_PIN_GROUP("nemc-frd-fwe", jz4770_nemc_frd_fwe),
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800629 INGENIC_PIN_GROUP("nemc-wait", jz4770_nemc_wait),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800630 INGENIC_PIN_GROUP("nemc-cs1", jz4770_nemc_cs1),
631 INGENIC_PIN_GROUP("nemc-cs2", jz4770_nemc_cs2),
632 INGENIC_PIN_GROUP("nemc-cs3", jz4770_nemc_cs3),
633 INGENIC_PIN_GROUP("nemc-cs4", jz4770_nemc_cs4),
634 INGENIC_PIN_GROUP("nemc-cs5", jz4770_nemc_cs5),
635 INGENIC_PIN_GROUP("nemc-cs6", jz4770_nemc_cs6),
636 INGENIC_PIN_GROUP("i2c0-data", jz4770_i2c0),
637 INGENIC_PIN_GROUP("i2c1-data", jz4770_i2c1),
638 INGENIC_PIN_GROUP("i2c2-data", jz4770_i2c2),
639 INGENIC_PIN_GROUP("i2c3-data", jz4780_i2c3),
640 INGENIC_PIN_GROUP("i2c4-data-e", jz4780_i2c4_e),
641 INGENIC_PIN_GROUP("i2c4-data-f", jz4780_i2c4_f),
642 INGENIC_PIN_GROUP("cim-data", jz4770_cim_8bit),
643 INGENIC_PIN_GROUP("lcd-24bit", jz4770_lcd_24bit),
644 { "lcd-no-pins", },
645 INGENIC_PIN_GROUP("pwm0", jz4770_pwm_pwm0),
646 INGENIC_PIN_GROUP("pwm1", jz4770_pwm_pwm1),
647 INGENIC_PIN_GROUP("pwm2", jz4770_pwm_pwm2),
648 INGENIC_PIN_GROUP("pwm3", jz4770_pwm_pwm3),
649 INGENIC_PIN_GROUP("pwm4", jz4770_pwm_pwm4),
650 INGENIC_PIN_GROUP("pwm5", jz4770_pwm_pwm5),
651 INGENIC_PIN_GROUP("pwm6", jz4770_pwm_pwm6),
652 INGENIC_PIN_GROUP("pwm7", jz4770_pwm_pwm7),
653};
654
655static const char *jz4780_uart2_groups[] = { "uart2-data", "uart2-hwflow", };
656static const char *jz4780_uart4_groups[] = { "uart4-data", };
657static const char *jz4780_mmc0_groups[] = {
658 "mmc0-1bit-a", "mmc0-4bit-a", "mmc0-8bit-a",
659 "mmc0-1bit-e", "mmc0-4bit-e",
660};
661static const char *jz4780_mmc1_groups[] = {
662 "mmc1-1bit-d", "mmc1-4bit-d", "mmc1-1bit-e", "mmc1-4bit-e",
663};
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800664static const char *jz4780_mmc2_groups[] = {
665 "mmc2-1bit-b", "mmc2-4bit-b", "mmc2-1bit-e", "mmc2-4bit-e",
666};
Zhou Yanjieff656e42019-01-28 23:19:57 +0800667static const char *jz4780_nemc_groups[] = {
668 "nemc-data", "nemc-cle-ale", "nemc-addr",
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800669 "nemc-rd-we", "nemc-frd-fwe", "nemc-wait",
Zhou Yanjieff656e42019-01-28 23:19:57 +0800670};
671static const char *jz4780_i2c3_groups[] = { "i2c3-data", };
672static const char *jz4780_i2c4_groups[] = { "i2c4-data-e", "i2c4-data-f", };
673static const char *jz4780_cim_groups[] = { "cim-data", };
674
675static const struct function_desc jz4780_functions[] = {
676 { "uart0", jz4770_uart0_groups, ARRAY_SIZE(jz4770_uart0_groups), },
677 { "uart1", jz4770_uart1_groups, ARRAY_SIZE(jz4770_uart1_groups), },
678 { "uart2", jz4780_uart2_groups, ARRAY_SIZE(jz4780_uart2_groups), },
679 { "uart3", jz4770_uart3_groups, ARRAY_SIZE(jz4770_uart3_groups), },
680 { "uart4", jz4780_uart4_groups, ARRAY_SIZE(jz4780_uart4_groups), },
681 { "mmc0", jz4780_mmc0_groups, ARRAY_SIZE(jz4780_mmc0_groups), },
682 { "mmc1", jz4780_mmc1_groups, ARRAY_SIZE(jz4780_mmc1_groups), },
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800683 { "mmc2", jz4780_mmc2_groups, ARRAY_SIZE(jz4780_mmc2_groups), },
Zhou Yanjieff656e42019-01-28 23:19:57 +0800684 { "nemc", jz4780_nemc_groups, ARRAY_SIZE(jz4780_nemc_groups), },
685 { "nemc-cs1", jz4770_cs1_groups, ARRAY_SIZE(jz4770_cs1_groups), },
686 { "nemc-cs2", jz4770_cs2_groups, ARRAY_SIZE(jz4770_cs2_groups), },
687 { "nemc-cs3", jz4770_cs3_groups, ARRAY_SIZE(jz4770_cs3_groups), },
688 { "nemc-cs4", jz4770_cs4_groups, ARRAY_SIZE(jz4770_cs4_groups), },
689 { "nemc-cs5", jz4770_cs5_groups, ARRAY_SIZE(jz4770_cs5_groups), },
690 { "nemc-cs6", jz4770_cs6_groups, ARRAY_SIZE(jz4770_cs6_groups), },
691 { "i2c0", jz4770_i2c0_groups, ARRAY_SIZE(jz4770_i2c0_groups), },
692 { "i2c1", jz4770_i2c1_groups, ARRAY_SIZE(jz4770_i2c1_groups), },
693 { "i2c2", jz4770_i2c2_groups, ARRAY_SIZE(jz4770_i2c2_groups), },
694 { "i2c3", jz4780_i2c3_groups, ARRAY_SIZE(jz4780_i2c3_groups), },
695 { "i2c4", jz4780_i2c4_groups, ARRAY_SIZE(jz4780_i2c4_groups), },
696 { "cim", jz4780_cim_groups, ARRAY_SIZE(jz4780_cim_groups), },
697 { "lcd", jz4770_lcd_groups, ARRAY_SIZE(jz4770_lcd_groups), },
698 { "pwm0", jz4770_pwm0_groups, ARRAY_SIZE(jz4770_pwm0_groups), },
699 { "pwm1", jz4770_pwm1_groups, ARRAY_SIZE(jz4770_pwm1_groups), },
700 { "pwm2", jz4770_pwm2_groups, ARRAY_SIZE(jz4770_pwm2_groups), },
701 { "pwm3", jz4770_pwm3_groups, ARRAY_SIZE(jz4770_pwm3_groups), },
702 { "pwm4", jz4770_pwm4_groups, ARRAY_SIZE(jz4770_pwm4_groups), },
703 { "pwm5", jz4770_pwm5_groups, ARRAY_SIZE(jz4770_pwm5_groups), },
704 { "pwm6", jz4770_pwm6_groups, ARRAY_SIZE(jz4770_pwm6_groups), },
705 { "pwm7", jz4770_pwm7_groups, ARRAY_SIZE(jz4770_pwm7_groups), },
706};
707
708static const struct ingenic_chip_info jz4780_chip_info = {
709 .num_chips = 6,
710 .groups = jz4780_groups,
711 .num_groups = ARRAY_SIZE(jz4780_groups),
712 .functions = jz4780_functions,
713 .num_functions = ARRAY_SIZE(jz4780_functions),
714 .pull_ups = jz4770_pull_ups,
715 .pull_downs = jz4770_pull_downs,
716};
717
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800718static u32 ingenic_gpio_read_reg(struct ingenic_gpio_chip *jzgc, u8 reg)
Paul Cercueile72394e2018-08-21 18:42:32 +0200719{
720 unsigned int val;
721
722 regmap_read(jzgc->jzpc->map, jzgc->reg_base + reg, &val);
723
724 return (u32) val;
725}
726
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800727static void ingenic_gpio_set_bit(struct ingenic_gpio_chip *jzgc,
Paul Cercueile72394e2018-08-21 18:42:32 +0200728 u8 reg, u8 offset, bool set)
729{
730 if (set)
731 reg = REG_SET(reg);
732 else
733 reg = REG_CLEAR(reg);
734
735 regmap_write(jzgc->jzpc->map, jzgc->reg_base + reg, BIT(offset));
736}
737
738static inline bool ingenic_gpio_get_value(struct ingenic_gpio_chip *jzgc,
739 u8 offset)
740{
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800741 unsigned int val = ingenic_gpio_read_reg(jzgc, GPIO_PIN);
Paul Cercueile72394e2018-08-21 18:42:32 +0200742
743 return !!(val & BIT(offset));
744}
745
746static void ingenic_gpio_set_value(struct ingenic_gpio_chip *jzgc,
747 u8 offset, int value)
748{
749 if (jzgc->jzpc->version >= ID_JZ4770)
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800750 ingenic_gpio_set_bit(jzgc, JZ4770_GPIO_PAT0, offset, !!value);
Paul Cercueile72394e2018-08-21 18:42:32 +0200751 else
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800752 ingenic_gpio_set_bit(jzgc, JZ4740_GPIO_DATA, offset, !!value);
Paul Cercueile72394e2018-08-21 18:42:32 +0200753}
754
755static void irq_set_type(struct ingenic_gpio_chip *jzgc,
756 u8 offset, unsigned int type)
757{
758 u8 reg1, reg2;
759
760 if (jzgc->jzpc->version >= ID_JZ4770) {
761 reg1 = JZ4770_GPIO_PAT1;
762 reg2 = JZ4770_GPIO_PAT0;
763 } else {
764 reg1 = JZ4740_GPIO_TRIG;
765 reg2 = JZ4740_GPIO_DIR;
766 }
767
768 switch (type) {
769 case IRQ_TYPE_EDGE_RISING:
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800770 ingenic_gpio_set_bit(jzgc, reg2, offset, true);
771 ingenic_gpio_set_bit(jzgc, reg1, offset, true);
Paul Cercueile72394e2018-08-21 18:42:32 +0200772 break;
773 case IRQ_TYPE_EDGE_FALLING:
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800774 ingenic_gpio_set_bit(jzgc, reg2, offset, false);
775 ingenic_gpio_set_bit(jzgc, reg1, offset, true);
Paul Cercueile72394e2018-08-21 18:42:32 +0200776 break;
777 case IRQ_TYPE_LEVEL_HIGH:
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800778 ingenic_gpio_set_bit(jzgc, reg2, offset, true);
779 ingenic_gpio_set_bit(jzgc, reg1, offset, false);
Paul Cercueile72394e2018-08-21 18:42:32 +0200780 break;
781 case IRQ_TYPE_LEVEL_LOW:
782 default:
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800783 ingenic_gpio_set_bit(jzgc, reg2, offset, false);
784 ingenic_gpio_set_bit(jzgc, reg1, offset, false);
Paul Cercueile72394e2018-08-21 18:42:32 +0200785 break;
786 }
787}
788
789static void ingenic_gpio_irq_mask(struct irq_data *irqd)
790{
791 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
792 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
793
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800794 ingenic_gpio_set_bit(jzgc, GPIO_MSK, irqd->hwirq, true);
Paul Cercueile72394e2018-08-21 18:42:32 +0200795}
796
797static void ingenic_gpio_irq_unmask(struct irq_data *irqd)
798{
799 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
800 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
801
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800802 ingenic_gpio_set_bit(jzgc, GPIO_MSK, irqd->hwirq, false);
Paul Cercueile72394e2018-08-21 18:42:32 +0200803}
804
805static void ingenic_gpio_irq_enable(struct irq_data *irqd)
806{
807 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
808 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
809 int irq = irqd->hwirq;
810
811 if (jzgc->jzpc->version >= ID_JZ4770)
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800812 ingenic_gpio_set_bit(jzgc, JZ4770_GPIO_INT, irq, true);
Paul Cercueile72394e2018-08-21 18:42:32 +0200813 else
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800814 ingenic_gpio_set_bit(jzgc, JZ4740_GPIO_SELECT, irq, true);
Paul Cercueile72394e2018-08-21 18:42:32 +0200815
816 ingenic_gpio_irq_unmask(irqd);
817}
818
819static void ingenic_gpio_irq_disable(struct irq_data *irqd)
820{
821 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
822 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
823 int irq = irqd->hwirq;
824
825 ingenic_gpio_irq_mask(irqd);
826
827 if (jzgc->jzpc->version >= ID_JZ4770)
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800828 ingenic_gpio_set_bit(jzgc, JZ4770_GPIO_INT, irq, false);
Paul Cercueile72394e2018-08-21 18:42:32 +0200829 else
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800830 ingenic_gpio_set_bit(jzgc, JZ4740_GPIO_SELECT, irq, false);
Paul Cercueile72394e2018-08-21 18:42:32 +0200831}
832
833static void ingenic_gpio_irq_ack(struct irq_data *irqd)
834{
835 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
836 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
837 int irq = irqd->hwirq;
838 bool high;
839
840 if (irqd_get_trigger_type(irqd) == IRQ_TYPE_EDGE_BOTH) {
841 /*
842 * Switch to an interrupt for the opposite edge to the one that
843 * triggered the interrupt being ACKed.
844 */
845 high = ingenic_gpio_get_value(jzgc, irq);
846 if (high)
847 irq_set_type(jzgc, irq, IRQ_TYPE_EDGE_FALLING);
848 else
849 irq_set_type(jzgc, irq, IRQ_TYPE_EDGE_RISING);
850 }
851
852 if (jzgc->jzpc->version >= ID_JZ4770)
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800853 ingenic_gpio_set_bit(jzgc, JZ4770_GPIO_FLAG, irq, false);
Paul Cercueile72394e2018-08-21 18:42:32 +0200854 else
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800855 ingenic_gpio_set_bit(jzgc, JZ4740_GPIO_DATA, irq, true);
Paul Cercueile72394e2018-08-21 18:42:32 +0200856}
857
858static int ingenic_gpio_irq_set_type(struct irq_data *irqd, unsigned int type)
859{
860 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
861 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
862
863 switch (type) {
864 case IRQ_TYPE_EDGE_BOTH:
865 case IRQ_TYPE_EDGE_RISING:
866 case IRQ_TYPE_EDGE_FALLING:
867 irq_set_handler_locked(irqd, handle_edge_irq);
868 break;
869 case IRQ_TYPE_LEVEL_HIGH:
870 case IRQ_TYPE_LEVEL_LOW:
871 irq_set_handler_locked(irqd, handle_level_irq);
872 break;
873 default:
874 irq_set_handler_locked(irqd, handle_bad_irq);
875 }
876
877 if (type == IRQ_TYPE_EDGE_BOTH) {
878 /*
879 * The hardware does not support interrupts on both edges. The
880 * best we can do is to set up a single-edge interrupt and then
881 * switch to the opposing edge when ACKing the interrupt.
882 */
883 bool high = ingenic_gpio_get_value(jzgc, irqd->hwirq);
884
885 type = high ? IRQ_TYPE_EDGE_FALLING : IRQ_TYPE_EDGE_RISING;
886 }
887
888 irq_set_type(jzgc, irqd->hwirq, type);
889 return 0;
890}
891
892static int ingenic_gpio_irq_set_wake(struct irq_data *irqd, unsigned int on)
893{
894 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
895 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
896
897 return irq_set_irq_wake(jzgc->irq, on);
898}
899
900static void ingenic_gpio_irq_handler(struct irq_desc *desc)
901{
902 struct gpio_chip *gc = irq_desc_get_handler_data(desc);
903 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
904 struct irq_chip *irq_chip = irq_data_get_irq_chip(&desc->irq_data);
905 unsigned long flag, i;
906
907 chained_irq_enter(irq_chip, desc);
908
909 if (jzgc->jzpc->version >= ID_JZ4770)
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800910 flag = ingenic_gpio_read_reg(jzgc, JZ4770_GPIO_FLAG);
Paul Cercueile72394e2018-08-21 18:42:32 +0200911 else
Zhou Yanjieb71c1842019-01-28 23:19:59 +0800912 flag = ingenic_gpio_read_reg(jzgc, JZ4740_GPIO_FLAG);
Paul Cercueile72394e2018-08-21 18:42:32 +0200913
914 for_each_set_bit(i, &flag, 32)
915 generic_handle_irq(irq_linear_revmap(gc->irq.domain, i));
916 chained_irq_exit(irq_chip, desc);
917}
918
919static void ingenic_gpio_set(struct gpio_chip *gc,
920 unsigned int offset, int value)
921{
922 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
923
924 ingenic_gpio_set_value(jzgc, offset, value);
925}
926
927static int ingenic_gpio_get(struct gpio_chip *gc, unsigned int offset)
928{
929 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
930
931 return (int) ingenic_gpio_get_value(jzgc, offset);
932}
933
934static int ingenic_gpio_direction_input(struct gpio_chip *gc,
935 unsigned int offset)
936{
937 return pinctrl_gpio_direction_input(gc->base + offset);
938}
939
940static int ingenic_gpio_direction_output(struct gpio_chip *gc,
941 unsigned int offset, int value)
942{
943 ingenic_gpio_set(gc, offset, value);
944 return pinctrl_gpio_direction_output(gc->base + offset);
945}
946
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200947static inline void ingenic_config_pin(struct ingenic_pinctrl *jzpc,
948 unsigned int pin, u8 reg, bool set)
949{
950 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
951 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
952
953 regmap_write(jzpc->map, offt * 0x100 +
954 (set ? REG_SET(reg) : REG_CLEAR(reg)), BIT(idx));
955}
956
957static inline bool ingenic_get_pin_config(struct ingenic_pinctrl *jzpc,
958 unsigned int pin, u8 reg)
959{
960 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
961 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
962 unsigned int val;
963
964 regmap_read(jzpc->map, offt * 0x100 + reg, &val);
965
966 return val & BIT(idx);
967}
968
Paul Cercueilebd66512018-08-21 18:42:33 +0200969static int ingenic_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
970{
971 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
972 struct ingenic_pinctrl *jzpc = jzgc->jzpc;
973 unsigned int pin = gc->base + offset;
974
975 if (jzpc->version >= ID_JZ4770)
976 return ingenic_get_pin_config(jzpc, pin, JZ4770_GPIO_PAT1);
977
978 if (ingenic_get_pin_config(jzpc, pin, JZ4740_GPIO_SELECT))
979 return true;
980
981 return !ingenic_get_pin_config(jzpc, pin, JZ4740_GPIO_DIR);
982}
983
Julia Lawall5bf7b842017-08-10 12:06:23 +0200984static const struct pinctrl_ops ingenic_pctlops = {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200985 .get_groups_count = pinctrl_generic_get_group_count,
986 .get_group_name = pinctrl_generic_get_group_name,
987 .get_group_pins = pinctrl_generic_get_group_pins,
988 .dt_node_to_map = pinconf_generic_dt_node_to_map_all,
989 .dt_free_map = pinconf_generic_dt_free_map,
990};
991
992static int ingenic_pinmux_set_pin_fn(struct ingenic_pinctrl *jzpc,
993 int pin, int func)
994{
995 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
996 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
997
998 dev_dbg(jzpc->dev, "set pin P%c%u to function %u\n",
999 'A' + offt, idx, func);
1000
1001 if (jzpc->version >= ID_JZ4770) {
1002 ingenic_config_pin(jzpc, pin, JZ4770_GPIO_INT, false);
Paul Cercueile72394e2018-08-21 18:42:32 +02001003 ingenic_config_pin(jzpc, pin, GPIO_MSK, false);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001004 ingenic_config_pin(jzpc, pin, JZ4770_GPIO_PAT1, func & 0x2);
1005 ingenic_config_pin(jzpc, pin, JZ4770_GPIO_PAT0, func & 0x1);
1006 } else {
1007 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_FUNC, true);
1008 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_TRIG, func & 0x2);
1009 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_SELECT, func > 0);
1010 }
1011
1012 return 0;
1013}
1014
1015static int ingenic_pinmux_set_mux(struct pinctrl_dev *pctldev,
1016 unsigned int selector, unsigned int group)
1017{
1018 struct ingenic_pinctrl *jzpc = pinctrl_dev_get_drvdata(pctldev);
1019 struct function_desc *func;
1020 struct group_desc *grp;
1021 unsigned int i;
1022
1023 func = pinmux_generic_get_function(pctldev, selector);
1024 if (!func)
1025 return -EINVAL;
1026
1027 grp = pinctrl_generic_get_group(pctldev, group);
1028 if (!grp)
1029 return -EINVAL;
1030
1031 dev_dbg(pctldev->dev, "enable function %s group %s\n",
1032 func->name, grp->name);
1033
1034 for (i = 0; i < grp->num_pins; i++) {
1035 int *pin_modes = grp->data;
1036
1037 ingenic_pinmux_set_pin_fn(jzpc, grp->pins[i], pin_modes[i]);
1038 }
1039
1040 return 0;
1041}
1042
1043static int ingenic_pinmux_gpio_set_direction(struct pinctrl_dev *pctldev,
1044 struct pinctrl_gpio_range *range,
1045 unsigned int pin, bool input)
1046{
1047 struct ingenic_pinctrl *jzpc = pinctrl_dev_get_drvdata(pctldev);
1048 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
1049 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
1050
1051 dev_dbg(pctldev->dev, "set pin P%c%u to %sput\n",
1052 'A' + offt, idx, input ? "in" : "out");
1053
1054 if (jzpc->version >= ID_JZ4770) {
1055 ingenic_config_pin(jzpc, pin, JZ4770_GPIO_INT, false);
Paul Cercueile72394e2018-08-21 18:42:32 +02001056 ingenic_config_pin(jzpc, pin, GPIO_MSK, true);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001057 ingenic_config_pin(jzpc, pin, JZ4770_GPIO_PAT1, input);
1058 } else {
1059 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_SELECT, false);
Paul Cercueil0084a782018-06-27 13:49:02 +02001060 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_DIR, !input);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001061 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_FUNC, false);
1062 }
1063
1064 return 0;
1065}
1066
Julia Lawall5bf7b842017-08-10 12:06:23 +02001067static const struct pinmux_ops ingenic_pmxops = {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001068 .get_functions_count = pinmux_generic_get_function_count,
1069 .get_function_name = pinmux_generic_get_function_name,
1070 .get_function_groups = pinmux_generic_get_function_groups,
1071 .set_mux = ingenic_pinmux_set_mux,
1072 .gpio_set_direction = ingenic_pinmux_gpio_set_direction,
1073};
1074
1075static int ingenic_pinconf_get(struct pinctrl_dev *pctldev,
1076 unsigned int pin, unsigned long *config)
1077{
1078 struct ingenic_pinctrl *jzpc = pinctrl_dev_get_drvdata(pctldev);
1079 enum pin_config_param param = pinconf_to_config_param(*config);
1080 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
1081 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
1082 bool pull;
1083
1084 if (jzpc->version >= ID_JZ4770)
1085 pull = !ingenic_get_pin_config(jzpc, pin, JZ4770_GPIO_PEN);
1086 else
1087 pull = !ingenic_get_pin_config(jzpc, pin, JZ4740_GPIO_PULL_DIS);
1088
1089 switch (param) {
1090 case PIN_CONFIG_BIAS_DISABLE:
1091 if (pull)
1092 return -EINVAL;
1093 break;
1094
1095 case PIN_CONFIG_BIAS_PULL_UP:
1096 if (!pull || !(jzpc->info->pull_ups[offt] & BIT(idx)))
1097 return -EINVAL;
1098 break;
1099
1100 case PIN_CONFIG_BIAS_PULL_DOWN:
1101 if (!pull || !(jzpc->info->pull_downs[offt] & BIT(idx)))
1102 return -EINVAL;
1103 break;
1104
1105 default:
1106 return -ENOTSUPP;
1107 }
1108
1109 *config = pinconf_to_config_packed(param, 1);
1110 return 0;
1111}
1112
1113static void ingenic_set_bias(struct ingenic_pinctrl *jzpc,
1114 unsigned int pin, bool enabled)
1115{
1116 if (jzpc->version >= ID_JZ4770)
1117 ingenic_config_pin(jzpc, pin, JZ4770_GPIO_PEN, !enabled);
1118 else
1119 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_PULL_DIS, !enabled);
1120}
1121
1122static int ingenic_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
1123 unsigned long *configs, unsigned int num_configs)
1124{
1125 struct ingenic_pinctrl *jzpc = pinctrl_dev_get_drvdata(pctldev);
1126 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
1127 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
1128 unsigned int cfg;
1129
1130 for (cfg = 0; cfg < num_configs; cfg++) {
1131 switch (pinconf_to_config_param(configs[cfg])) {
1132 case PIN_CONFIG_BIAS_DISABLE:
1133 case PIN_CONFIG_BIAS_PULL_UP:
1134 case PIN_CONFIG_BIAS_PULL_DOWN:
1135 continue;
1136 default:
1137 return -ENOTSUPP;
1138 }
1139 }
1140
1141 for (cfg = 0; cfg < num_configs; cfg++) {
1142 switch (pinconf_to_config_param(configs[cfg])) {
1143 case PIN_CONFIG_BIAS_DISABLE:
1144 dev_dbg(jzpc->dev, "disable pull-over for pin P%c%u\n",
1145 'A' + offt, idx);
1146 ingenic_set_bias(jzpc, pin, false);
1147 break;
1148
1149 case PIN_CONFIG_BIAS_PULL_UP:
1150 if (!(jzpc->info->pull_ups[offt] & BIT(idx)))
1151 return -EINVAL;
1152 dev_dbg(jzpc->dev, "set pull-up for pin P%c%u\n",
1153 'A' + offt, idx);
1154 ingenic_set_bias(jzpc, pin, true);
1155 break;
1156
1157 case PIN_CONFIG_BIAS_PULL_DOWN:
1158 if (!(jzpc->info->pull_downs[offt] & BIT(idx)))
1159 return -EINVAL;
1160 dev_dbg(jzpc->dev, "set pull-down for pin P%c%u\n",
1161 'A' + offt, idx);
1162 ingenic_set_bias(jzpc, pin, true);
1163 break;
1164
1165 default:
1166 unreachable();
1167 }
1168 }
1169
1170 return 0;
1171}
1172
1173static int ingenic_pinconf_group_get(struct pinctrl_dev *pctldev,
1174 unsigned int group, unsigned long *config)
1175{
1176 const unsigned int *pins;
1177 unsigned int i, npins, old = 0;
1178 int ret;
1179
1180 ret = pinctrl_generic_get_group_pins(pctldev, group, &pins, &npins);
1181 if (ret)
1182 return ret;
1183
1184 for (i = 0; i < npins; i++) {
1185 if (ingenic_pinconf_get(pctldev, pins[i], config))
1186 return -ENOTSUPP;
1187
1188 /* configs do not match between two pins */
1189 if (i && (old != *config))
1190 return -ENOTSUPP;
1191
1192 old = *config;
1193 }
1194
1195 return 0;
1196}
1197
1198static int ingenic_pinconf_group_set(struct pinctrl_dev *pctldev,
1199 unsigned int group, unsigned long *configs,
1200 unsigned int num_configs)
1201{
1202 const unsigned int *pins;
1203 unsigned int i, npins;
1204 int ret;
1205
1206 ret = pinctrl_generic_get_group_pins(pctldev, group, &pins, &npins);
1207 if (ret)
1208 return ret;
1209
1210 for (i = 0; i < npins; i++) {
1211 ret = ingenic_pinconf_set(pctldev,
1212 pins[i], configs, num_configs);
1213 if (ret)
1214 return ret;
1215 }
1216
1217 return 0;
1218}
1219
Julia Lawall5bf7b842017-08-10 12:06:23 +02001220static const struct pinconf_ops ingenic_confops = {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001221 .is_generic = true,
1222 .pin_config_get = ingenic_pinconf_get,
1223 .pin_config_set = ingenic_pinconf_set,
1224 .pin_config_group_get = ingenic_pinconf_group_get,
1225 .pin_config_group_set = ingenic_pinconf_group_set,
1226};
1227
1228static const struct regmap_config ingenic_pinctrl_regmap_config = {
1229 .reg_bits = 32,
1230 .val_bits = 32,
1231 .reg_stride = 4,
1232};
1233
1234static const struct of_device_id ingenic_pinctrl_of_match[] = {
1235 { .compatible = "ingenic,jz4740-pinctrl", .data = (void *) ID_JZ4740 },
Paul Cercueilf2a96762018-08-21 18:42:34 +02001236 { .compatible = "ingenic,jz4725b-pinctrl", .data = (void *)ID_JZ4725B },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001237 { .compatible = "ingenic,jz4770-pinctrl", .data = (void *) ID_JZ4770 },
1238 { .compatible = "ingenic,jz4780-pinctrl", .data = (void *) ID_JZ4780 },
1239 {},
1240};
1241
Paul Cercueile72394e2018-08-21 18:42:32 +02001242static const struct of_device_id ingenic_gpio_of_match[] __initconst = {
1243 { .compatible = "ingenic,jz4740-gpio", },
1244 { .compatible = "ingenic,jz4770-gpio", },
1245 { .compatible = "ingenic,jz4780-gpio", },
1246 {},
1247};
1248
1249static int __init ingenic_gpio_probe(struct ingenic_pinctrl *jzpc,
1250 struct device_node *node)
1251{
1252 struct ingenic_gpio_chip *jzgc;
1253 struct device *dev = jzpc->dev;
1254 unsigned int bank;
1255 int err;
1256
1257 err = of_property_read_u32(node, "reg", &bank);
1258 if (err) {
1259 dev_err(dev, "Cannot read \"reg\" property: %i\n", err);
1260 return err;
1261 }
1262
1263 jzgc = devm_kzalloc(dev, sizeof(*jzgc), GFP_KERNEL);
1264 if (!jzgc)
1265 return -ENOMEM;
1266
1267 jzgc->jzpc = jzpc;
1268 jzgc->reg_base = bank * 0x100;
1269
1270 jzgc->gc.label = devm_kasprintf(dev, GFP_KERNEL, "GPIO%c", 'A' + bank);
1271 if (!jzgc->gc.label)
1272 return -ENOMEM;
1273
1274 /* DO NOT EXPAND THIS: FOR BACKWARD GPIO NUMBERSPACE COMPATIBIBILITY
1275 * ONLY: WORK TO TRANSITION CONSUMERS TO USE THE GPIO DESCRIPTOR API IN
1276 * <linux/gpio/consumer.h> INSTEAD.
1277 */
1278 jzgc->gc.base = bank * 32;
1279
1280 jzgc->gc.ngpio = 32;
1281 jzgc->gc.parent = dev;
1282 jzgc->gc.of_node = node;
1283 jzgc->gc.owner = THIS_MODULE;
1284
1285 jzgc->gc.set = ingenic_gpio_set;
1286 jzgc->gc.get = ingenic_gpio_get;
1287 jzgc->gc.direction_input = ingenic_gpio_direction_input;
1288 jzgc->gc.direction_output = ingenic_gpio_direction_output;
Paul Cercueilebd66512018-08-21 18:42:33 +02001289 jzgc->gc.get_direction = ingenic_gpio_get_direction;
Paul Cercueile72394e2018-08-21 18:42:32 +02001290
1291 if (of_property_read_bool(node, "gpio-ranges")) {
1292 jzgc->gc.request = gpiochip_generic_request;
1293 jzgc->gc.free = gpiochip_generic_free;
1294 }
1295
1296 err = devm_gpiochip_add_data(dev, &jzgc->gc, jzgc);
1297 if (err)
1298 return err;
1299
1300 jzgc->irq = irq_of_parse_and_map(node, 0);
1301 if (!jzgc->irq)
1302 return -EINVAL;
1303
1304 jzgc->irq_chip.name = jzgc->gc.label;
1305 jzgc->irq_chip.irq_enable = ingenic_gpio_irq_enable;
1306 jzgc->irq_chip.irq_disable = ingenic_gpio_irq_disable;
1307 jzgc->irq_chip.irq_unmask = ingenic_gpio_irq_unmask;
1308 jzgc->irq_chip.irq_mask = ingenic_gpio_irq_mask;
1309 jzgc->irq_chip.irq_ack = ingenic_gpio_irq_ack;
1310 jzgc->irq_chip.irq_set_type = ingenic_gpio_irq_set_type;
1311 jzgc->irq_chip.irq_set_wake = ingenic_gpio_irq_set_wake;
1312 jzgc->irq_chip.flags = IRQCHIP_MASK_ON_SUSPEND;
1313
1314 err = gpiochip_irqchip_add(&jzgc->gc, &jzgc->irq_chip, 0,
1315 handle_level_irq, IRQ_TYPE_NONE);
1316 if (err)
1317 return err;
1318
1319 gpiochip_set_chained_irqchip(&jzgc->gc, &jzgc->irq_chip,
1320 jzgc->irq, ingenic_gpio_irq_handler);
1321 return 0;
1322}
1323
Paul Cercueil4717b112018-08-21 18:42:31 +02001324static int __init ingenic_pinctrl_probe(struct platform_device *pdev)
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001325{
1326 struct device *dev = &pdev->dev;
1327 struct ingenic_pinctrl *jzpc;
1328 struct pinctrl_desc *pctl_desc;
1329 void __iomem *base;
1330 const struct platform_device_id *id = platform_get_device_id(pdev);
1331 const struct of_device_id *of_id = of_match_device(
1332 ingenic_pinctrl_of_match, dev);
1333 const struct ingenic_chip_info *chip_info;
Paul Cercueile72394e2018-08-21 18:42:32 +02001334 struct device_node *node;
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001335 unsigned int i;
1336 int err;
1337
1338 jzpc = devm_kzalloc(dev, sizeof(*jzpc), GFP_KERNEL);
1339 if (!jzpc)
1340 return -ENOMEM;
1341
1342 base = devm_ioremap_resource(dev,
1343 platform_get_resource(pdev, IORESOURCE_MEM, 0));
Wei Yongjun119fcf42018-01-17 11:29:17 +00001344 if (IS_ERR(base))
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001345 return PTR_ERR(base);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001346
1347 jzpc->map = devm_regmap_init_mmio(dev, base,
1348 &ingenic_pinctrl_regmap_config);
1349 if (IS_ERR(jzpc->map)) {
1350 dev_err(dev, "Failed to create regmap\n");
1351 return PTR_ERR(jzpc->map);
1352 }
1353
1354 jzpc->dev = dev;
1355
1356 if (of_id)
1357 jzpc->version = (enum jz_version)of_id->data;
1358 else
1359 jzpc->version = (enum jz_version)id->driver_data;
1360
Zhou Yanjieff656e42019-01-28 23:19:57 +08001361 if (jzpc->version >= ID_JZ4780)
1362 chip_info = &jz4780_chip_info;
1363 else if (jzpc->version >= ID_JZ4770)
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001364 chip_info = &jz4770_chip_info;
Paul Cercueilf2a96762018-08-21 18:42:34 +02001365 else if (jzpc->version >= ID_JZ4725B)
1366 chip_info = &jz4725b_chip_info;
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001367 else
1368 chip_info = &jz4740_chip_info;
1369 jzpc->info = chip_info;
1370
1371 pctl_desc = devm_kzalloc(&pdev->dev, sizeof(*pctl_desc), GFP_KERNEL);
1372 if (!pctl_desc)
1373 return -ENOMEM;
1374
1375 /* fill in pinctrl_desc structure */
1376 pctl_desc->name = dev_name(dev);
1377 pctl_desc->owner = THIS_MODULE;
1378 pctl_desc->pctlops = &ingenic_pctlops;
1379 pctl_desc->pmxops = &ingenic_pmxops;
1380 pctl_desc->confops = &ingenic_confops;
1381 pctl_desc->npins = chip_info->num_chips * PINS_PER_GPIO_CHIP;
Kees Cooka86854d2018-06-12 14:07:58 -07001382 pctl_desc->pins = jzpc->pdesc = devm_kcalloc(&pdev->dev,
1383 pctl_desc->npins, sizeof(*jzpc->pdesc), GFP_KERNEL);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001384 if (!jzpc->pdesc)
1385 return -ENOMEM;
1386
1387 for (i = 0; i < pctl_desc->npins; i++) {
1388 jzpc->pdesc[i].number = i;
1389 jzpc->pdesc[i].name = kasprintf(GFP_KERNEL, "P%c%d",
1390 'A' + (i / PINS_PER_GPIO_CHIP),
1391 i % PINS_PER_GPIO_CHIP);
1392 }
1393
1394 jzpc->pctl = devm_pinctrl_register(dev, pctl_desc, jzpc);
Dan Carpentere7f4c4b2017-06-14 12:12:09 +03001395 if (IS_ERR(jzpc->pctl)) {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001396 dev_err(dev, "Failed to register pinctrl\n");
Dan Carpentere7f4c4b2017-06-14 12:12:09 +03001397 return PTR_ERR(jzpc->pctl);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001398 }
1399
1400 for (i = 0; i < chip_info->num_groups; i++) {
1401 const struct group_desc *group = &chip_info->groups[i];
1402
1403 err = pinctrl_generic_add_group(jzpc->pctl, group->name,
1404 group->pins, group->num_pins, group->data);
Paul Burton823dd712018-08-25 10:53:28 -07001405 if (err < 0) {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001406 dev_err(dev, "Failed to register group %s\n",
1407 group->name);
1408 return err;
1409 }
1410 }
1411
1412 for (i = 0; i < chip_info->num_functions; i++) {
1413 const struct function_desc *func = &chip_info->functions[i];
1414
1415 err = pinmux_generic_add_function(jzpc->pctl, func->name,
1416 func->group_names, func->num_group_names,
1417 func->data);
Paul Burton823dd712018-08-25 10:53:28 -07001418 if (err < 0) {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001419 dev_err(dev, "Failed to register function %s\n",
1420 func->name);
1421 return err;
1422 }
1423 }
1424
1425 dev_set_drvdata(dev, jzpc->map);
1426
Paul Cercueile72394e2018-08-21 18:42:32 +02001427 for_each_child_of_node(dev->of_node, node) {
1428 if (of_match_node(ingenic_gpio_of_match, node)) {
1429 err = ingenic_gpio_probe(jzpc, node);
1430 if (err)
1431 return err;
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001432 }
1433 }
1434
1435 return 0;
1436}
1437
1438static const struct platform_device_id ingenic_pinctrl_ids[] = {
1439 { "jz4740-pinctrl", ID_JZ4740 },
Paul Cercueilf2a96762018-08-21 18:42:34 +02001440 { "jz4725b-pinctrl", ID_JZ4725B },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001441 { "jz4770-pinctrl", ID_JZ4770 },
1442 { "jz4780-pinctrl", ID_JZ4780 },
1443 {},
1444};
1445
1446static struct platform_driver ingenic_pinctrl_driver = {
1447 .driver = {
1448 .name = "pinctrl-ingenic",
1449 .of_match_table = of_match_ptr(ingenic_pinctrl_of_match),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001450 },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001451 .id_table = ingenic_pinctrl_ids,
1452};
1453
1454static int __init ingenic_pinctrl_drv_register(void)
1455{
Paul Cercueil4717b112018-08-21 18:42:31 +02001456 return platform_driver_probe(&ingenic_pinctrl_driver,
1457 ingenic_pinctrl_probe);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001458}
Paul Cercueil556a36a2018-08-21 18:42:30 +02001459subsys_initcall(ingenic_pinctrl_drv_register);