blob: 265b591fbd53eb4b5101571dcd9f32323dfb93ec [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 Yanjie5d215952019-07-14 11:53:56 +08006 * Copyright (c) 2019 Zhou Yanjie <zhouyanjie@zoho.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 Yanjiefe1ad5e2019-07-14 11:53:54 +080045#define X1000_GPIO_PZ_BASE 0x700
46#define X1000_GPIO_PZ_GID2LD 0x7f0
47
Paul Cercueilb5c23aa2017-05-12 18:52:56 +020048#define REG_SET(x) ((x) + 0x4)
49#define REG_CLEAR(x) ((x) + 0x8)
50
51#define PINS_PER_GPIO_CHIP 32
52
53enum jz_version {
54 ID_JZ4740,
Paul Cercueilf2a96762018-08-21 18:42:34 +020055 ID_JZ4725B,
Zhou Yanjie0257595a2019-07-14 11:53:52 +080056 ID_JZ4760,
57 ID_JZ4760B,
Paul Cercueilb5c23aa2017-05-12 18:52:56 +020058 ID_JZ4770,
59 ID_JZ4780,
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +080060 ID_X1000,
61 ID_X1000E,
Zhou Yanjie5d215952019-07-14 11:53:56 +080062 ID_X1500,
Paul Cercueilb5c23aa2017-05-12 18:52:56 +020063};
64
65struct ingenic_chip_info {
66 unsigned int num_chips;
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +080067 unsigned int reg_offset;
Paul Cercueilb5c23aa2017-05-12 18:52:56 +020068
69 const struct group_desc *groups;
70 unsigned int num_groups;
71
72 const struct function_desc *functions;
73 unsigned int num_functions;
74
75 const u32 *pull_ups, *pull_downs;
76};
77
78struct ingenic_pinctrl {
79 struct device *dev;
80 struct regmap *map;
81 struct pinctrl_dev *pctl;
82 struct pinctrl_pin_desc *pdesc;
83 enum jz_version version;
84
85 const struct ingenic_chip_info *info;
86};
87
Paul Cercueile72394e2018-08-21 18:42:32 +020088struct ingenic_gpio_chip {
89 struct ingenic_pinctrl *jzpc;
90 struct gpio_chip gc;
91 struct irq_chip irq_chip;
92 unsigned int irq, reg_base;
93};
94
Paul Cercueilb5c23aa2017-05-12 18:52:56 +020095static const u32 jz4740_pull_ups[4] = {
96 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
97};
98
99static const u32 jz4740_pull_downs[4] = {
100 0x00000000, 0x00000000, 0x00000000, 0x00000000,
101};
102
103static int jz4740_mmc_1bit_pins[] = { 0x69, 0x68, 0x6a, };
104static int jz4740_mmc_4bit_pins[] = { 0x6b, 0x6c, 0x6d, };
105static int jz4740_uart0_data_pins[] = { 0x7a, 0x79, };
106static int jz4740_uart0_hwflow_pins[] = { 0x7e, 0x7f, };
107static int jz4740_uart1_data_pins[] = { 0x7e, 0x7f, };
108static int jz4740_lcd_8bit_pins[] = {
109 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x52, 0x53, 0x54,
110};
111static int jz4740_lcd_16bit_pins[] = {
112 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x55,
113};
114static int jz4740_lcd_18bit_pins[] = { 0x50, 0x51, };
115static int jz4740_lcd_18bit_tft_pins[] = { 0x56, 0x57, 0x31, 0x32, };
116static int jz4740_nand_cs1_pins[] = { 0x39, };
117static int jz4740_nand_cs2_pins[] = { 0x3a, };
118static int jz4740_nand_cs3_pins[] = { 0x3b, };
119static int jz4740_nand_cs4_pins[] = { 0x3c, };
120static int jz4740_pwm_pwm0_pins[] = { 0x77, };
121static int jz4740_pwm_pwm1_pins[] = { 0x78, };
122static int jz4740_pwm_pwm2_pins[] = { 0x79, };
123static int jz4740_pwm_pwm3_pins[] = { 0x7a, };
124static int jz4740_pwm_pwm4_pins[] = { 0x7b, };
125static int jz4740_pwm_pwm5_pins[] = { 0x7c, };
126static int jz4740_pwm_pwm6_pins[] = { 0x7e, };
127static int jz4740_pwm_pwm7_pins[] = { 0x7f, };
128
129static int jz4740_mmc_1bit_funcs[] = { 0, 0, 0, };
130static int jz4740_mmc_4bit_funcs[] = { 0, 0, 0, };
131static int jz4740_uart0_data_funcs[] = { 1, 1, };
132static int jz4740_uart0_hwflow_funcs[] = { 1, 1, };
133static int jz4740_uart1_data_funcs[] = { 2, 2, };
134static int jz4740_lcd_8bit_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
135static int jz4740_lcd_16bit_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, };
136static int jz4740_lcd_18bit_funcs[] = { 0, 0, };
137static int jz4740_lcd_18bit_tft_funcs[] = { 0, 0, 0, 0, };
138static int jz4740_nand_cs1_funcs[] = { 0, };
139static int jz4740_nand_cs2_funcs[] = { 0, };
140static int jz4740_nand_cs3_funcs[] = { 0, };
141static int jz4740_nand_cs4_funcs[] = { 0, };
142static int jz4740_pwm_pwm0_funcs[] = { 0, };
143static int jz4740_pwm_pwm1_funcs[] = { 0, };
144static int jz4740_pwm_pwm2_funcs[] = { 0, };
145static int jz4740_pwm_pwm3_funcs[] = { 0, };
146static int jz4740_pwm_pwm4_funcs[] = { 0, };
147static int jz4740_pwm_pwm5_funcs[] = { 0, };
148static int jz4740_pwm_pwm6_funcs[] = { 0, };
149static int jz4740_pwm_pwm7_funcs[] = { 0, };
150
151#define INGENIC_PIN_GROUP(name, id) \
152 { \
153 name, \
154 id##_pins, \
155 ARRAY_SIZE(id##_pins), \
156 id##_funcs, \
157 }
158
159static const struct group_desc jz4740_groups[] = {
160 INGENIC_PIN_GROUP("mmc-1bit", jz4740_mmc_1bit),
161 INGENIC_PIN_GROUP("mmc-4bit", jz4740_mmc_4bit),
162 INGENIC_PIN_GROUP("uart0-data", jz4740_uart0_data),
163 INGENIC_PIN_GROUP("uart0-hwflow", jz4740_uart0_hwflow),
164 INGENIC_PIN_GROUP("uart1-data", jz4740_uart1_data),
165 INGENIC_PIN_GROUP("lcd-8bit", jz4740_lcd_8bit),
166 INGENIC_PIN_GROUP("lcd-16bit", jz4740_lcd_16bit),
167 INGENIC_PIN_GROUP("lcd-18bit", jz4740_lcd_18bit),
168 INGENIC_PIN_GROUP("lcd-18bit-tft", jz4740_lcd_18bit_tft),
169 { "lcd-no-pins", },
170 INGENIC_PIN_GROUP("nand-cs1", jz4740_nand_cs1),
171 INGENIC_PIN_GROUP("nand-cs2", jz4740_nand_cs2),
172 INGENIC_PIN_GROUP("nand-cs3", jz4740_nand_cs3),
173 INGENIC_PIN_GROUP("nand-cs4", jz4740_nand_cs4),
174 INGENIC_PIN_GROUP("pwm0", jz4740_pwm_pwm0),
175 INGENIC_PIN_GROUP("pwm1", jz4740_pwm_pwm1),
176 INGENIC_PIN_GROUP("pwm2", jz4740_pwm_pwm2),
177 INGENIC_PIN_GROUP("pwm3", jz4740_pwm_pwm3),
178 INGENIC_PIN_GROUP("pwm4", jz4740_pwm_pwm4),
179 INGENIC_PIN_GROUP("pwm5", jz4740_pwm_pwm5),
180 INGENIC_PIN_GROUP("pwm6", jz4740_pwm_pwm6),
181 INGENIC_PIN_GROUP("pwm7", jz4740_pwm_pwm7),
182};
183
184static const char *jz4740_mmc_groups[] = { "mmc-1bit", "mmc-4bit", };
185static const char *jz4740_uart0_groups[] = { "uart0-data", "uart0-hwflow", };
186static const char *jz4740_uart1_groups[] = { "uart1-data", };
187static const char *jz4740_lcd_groups[] = {
188 "lcd-8bit", "lcd-16bit", "lcd-18bit", "lcd-18bit-tft", "lcd-no-pins",
189};
190static const char *jz4740_nand_groups[] = {
191 "nand-cs1", "nand-cs2", "nand-cs3", "nand-cs4",
192};
193static const char *jz4740_pwm0_groups[] = { "pwm0", };
194static const char *jz4740_pwm1_groups[] = { "pwm1", };
195static const char *jz4740_pwm2_groups[] = { "pwm2", };
196static const char *jz4740_pwm3_groups[] = { "pwm3", };
197static const char *jz4740_pwm4_groups[] = { "pwm4", };
198static const char *jz4740_pwm5_groups[] = { "pwm5", };
199static const char *jz4740_pwm6_groups[] = { "pwm6", };
200static const char *jz4740_pwm7_groups[] = { "pwm7", };
201
202static const struct function_desc jz4740_functions[] = {
203 { "mmc", jz4740_mmc_groups, ARRAY_SIZE(jz4740_mmc_groups), },
204 { "uart0", jz4740_uart0_groups, ARRAY_SIZE(jz4740_uart0_groups), },
205 { "uart1", jz4740_uart1_groups, ARRAY_SIZE(jz4740_uart1_groups), },
206 { "lcd", jz4740_lcd_groups, ARRAY_SIZE(jz4740_lcd_groups), },
207 { "nand", jz4740_nand_groups, ARRAY_SIZE(jz4740_nand_groups), },
208 { "pwm0", jz4740_pwm0_groups, ARRAY_SIZE(jz4740_pwm0_groups), },
209 { "pwm1", jz4740_pwm1_groups, ARRAY_SIZE(jz4740_pwm1_groups), },
210 { "pwm2", jz4740_pwm2_groups, ARRAY_SIZE(jz4740_pwm2_groups), },
211 { "pwm3", jz4740_pwm3_groups, ARRAY_SIZE(jz4740_pwm3_groups), },
212 { "pwm4", jz4740_pwm4_groups, ARRAY_SIZE(jz4740_pwm4_groups), },
213 { "pwm5", jz4740_pwm5_groups, ARRAY_SIZE(jz4740_pwm5_groups), },
214 { "pwm6", jz4740_pwm6_groups, ARRAY_SIZE(jz4740_pwm6_groups), },
215 { "pwm7", jz4740_pwm7_groups, ARRAY_SIZE(jz4740_pwm7_groups), },
216};
217
218static const struct ingenic_chip_info jz4740_chip_info = {
219 .num_chips = 4,
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +0800220 .reg_offset = 0x100,
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200221 .groups = jz4740_groups,
222 .num_groups = ARRAY_SIZE(jz4740_groups),
223 .functions = jz4740_functions,
224 .num_functions = ARRAY_SIZE(jz4740_functions),
225 .pull_ups = jz4740_pull_ups,
226 .pull_downs = jz4740_pull_downs,
227};
228
Paul Cercueilf2a96762018-08-21 18:42:34 +0200229static int jz4725b_mmc0_1bit_pins[] = { 0x48, 0x49, 0x5c, };
230static int jz4725b_mmc0_4bit_pins[] = { 0x5d, 0x5b, 0x56, };
231static int jz4725b_mmc1_1bit_pins[] = { 0x7a, 0x7b, 0x7c, };
232static int jz4725b_mmc1_4bit_pins[] = { 0x7d, 0x7e, 0x7f, };
233static int jz4725b_uart_data_pins[] = { 0x4c, 0x4d, };
234static int jz4725b_nand_cs1_pins[] = { 0x55, };
235static int jz4725b_nand_cs2_pins[] = { 0x56, };
236static int jz4725b_nand_cs3_pins[] = { 0x57, };
237static int jz4725b_nand_cs4_pins[] = { 0x58, };
238static int jz4725b_nand_cle_ale_pins[] = { 0x48, 0x49 };
239static int jz4725b_nand_fre_fwe_pins[] = { 0x5c, 0x5d };
240static int jz4725b_pwm_pwm0_pins[] = { 0x4a, };
241static int jz4725b_pwm_pwm1_pins[] = { 0x4b, };
242static int jz4725b_pwm_pwm2_pins[] = { 0x4c, };
243static int jz4725b_pwm_pwm3_pins[] = { 0x4d, };
244static int jz4725b_pwm_pwm4_pins[] = { 0x4e, };
245static int jz4725b_pwm_pwm5_pins[] = { 0x4f, };
Paul Cercueila3240f02019-02-07 10:55:36 -0300246static int jz4725b_lcd_8bit_pins[] = {
247 0x72, 0x73, 0x74,
248 0x60, 0x61, 0x62, 0x63,
249 0x64, 0x65, 0x66, 0x67,
250};
251static int jz4725b_lcd_16bit_pins[] = {
252 0x68, 0x69, 0x6a, 0x6b,
253 0x6c, 0x6d, 0x6e, 0x6f,
254};
255static int jz4725b_lcd_18bit_pins[] = { 0x70, 0x71, };
256static int jz4725b_lcd_24bit_pins[] = { 0x76, 0x77, 0x78, 0x79, };
257static int jz4725b_lcd_special_pins[] = { 0x76, 0x77, 0x78, 0x79, };
258static int jz4725b_lcd_generic_pins[] = { 0x75, };
Paul Cercueilf2a96762018-08-21 18:42:34 +0200259
260static int jz4725b_mmc0_1bit_funcs[] = { 1, 1, 1, };
261static int jz4725b_mmc0_4bit_funcs[] = { 1, 0, 1, };
262static int jz4725b_mmc1_1bit_funcs[] = { 0, 0, 0, };
263static int jz4725b_mmc1_4bit_funcs[] = { 0, 0, 0, };
264static int jz4725b_uart_data_funcs[] = { 1, 1, };
265static int jz4725b_nand_cs1_funcs[] = { 0, };
266static int jz4725b_nand_cs2_funcs[] = { 0, };
267static int jz4725b_nand_cs3_funcs[] = { 0, };
268static int jz4725b_nand_cs4_funcs[] = { 0, };
269static int jz4725b_nand_cle_ale_funcs[] = { 0, 0, };
270static int jz4725b_nand_fre_fwe_funcs[] = { 0, 0, };
271static int jz4725b_pwm_pwm0_funcs[] = { 0, };
272static int jz4725b_pwm_pwm1_funcs[] = { 0, };
273static int jz4725b_pwm_pwm2_funcs[] = { 0, };
274static int jz4725b_pwm_pwm3_funcs[] = { 0, };
275static int jz4725b_pwm_pwm4_funcs[] = { 0, };
276static int jz4725b_pwm_pwm5_funcs[] = { 0, };
Paul Cercueila3240f02019-02-07 10:55:36 -0300277static int jz4725b_lcd_8bit_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
278static int jz4725b_lcd_16bit_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, };
279static int jz4725b_lcd_18bit_funcs[] = { 0, 0, };
280static int jz4725b_lcd_24bit_funcs[] = { 1, 1, 1, 1, };
281static int jz4725b_lcd_special_funcs[] = { 0, 0, 0, 0, };
282static int jz4725b_lcd_generic_funcs[] = { 0, };
Paul Cercueilf2a96762018-08-21 18:42:34 +0200283
284static const struct group_desc jz4725b_groups[] = {
285 INGENIC_PIN_GROUP("mmc0-1bit", jz4725b_mmc0_1bit),
286 INGENIC_PIN_GROUP("mmc0-4bit", jz4725b_mmc0_4bit),
287 INGENIC_PIN_GROUP("mmc1-1bit", jz4725b_mmc1_1bit),
288 INGENIC_PIN_GROUP("mmc1-4bit", jz4725b_mmc1_4bit),
289 INGENIC_PIN_GROUP("uart-data", jz4725b_uart_data),
290 INGENIC_PIN_GROUP("nand-cs1", jz4725b_nand_cs1),
291 INGENIC_PIN_GROUP("nand-cs2", jz4725b_nand_cs2),
292 INGENIC_PIN_GROUP("nand-cs3", jz4725b_nand_cs3),
293 INGENIC_PIN_GROUP("nand-cs4", jz4725b_nand_cs4),
294 INGENIC_PIN_GROUP("nand-cle-ale", jz4725b_nand_cle_ale),
295 INGENIC_PIN_GROUP("nand-fre-fwe", jz4725b_nand_fre_fwe),
296 INGENIC_PIN_GROUP("pwm0", jz4725b_pwm_pwm0),
297 INGENIC_PIN_GROUP("pwm1", jz4725b_pwm_pwm1),
298 INGENIC_PIN_GROUP("pwm2", jz4725b_pwm_pwm2),
299 INGENIC_PIN_GROUP("pwm3", jz4725b_pwm_pwm3),
300 INGENIC_PIN_GROUP("pwm4", jz4725b_pwm_pwm4),
301 INGENIC_PIN_GROUP("pwm5", jz4725b_pwm_pwm5),
Paul Cercueila3240f02019-02-07 10:55:36 -0300302 INGENIC_PIN_GROUP("lcd-8bit", jz4725b_lcd_8bit),
303 INGENIC_PIN_GROUP("lcd-16bit", jz4725b_lcd_16bit),
304 INGENIC_PIN_GROUP("lcd-18bit", jz4725b_lcd_18bit),
305 INGENIC_PIN_GROUP("lcd-24bit", jz4725b_lcd_24bit),
306 INGENIC_PIN_GROUP("lcd-special", jz4725b_lcd_special),
307 INGENIC_PIN_GROUP("lcd-generic", jz4725b_lcd_generic),
Paul Cercueilf2a96762018-08-21 18:42:34 +0200308};
309
310static const char *jz4725b_mmc0_groups[] = { "mmc0-1bit", "mmc0-4bit", };
311static const char *jz4725b_mmc1_groups[] = { "mmc1-1bit", "mmc1-4bit", };
312static const char *jz4725b_uart_groups[] = { "uart-data", };
313static const char *jz4725b_nand_groups[] = {
314 "nand-cs1", "nand-cs2", "nand-cs3", "nand-cs4",
315 "nand-cle-ale", "nand-fre-fwe",
316};
317static const char *jz4725b_pwm0_groups[] = { "pwm0", };
318static const char *jz4725b_pwm1_groups[] = { "pwm1", };
319static const char *jz4725b_pwm2_groups[] = { "pwm2", };
320static const char *jz4725b_pwm3_groups[] = { "pwm3", };
321static const char *jz4725b_pwm4_groups[] = { "pwm4", };
322static const char *jz4725b_pwm5_groups[] = { "pwm5", };
Paul Cercueila3240f02019-02-07 10:55:36 -0300323static const char *jz4725b_lcd_groups[] = {
324 "lcd-8bit", "lcd-16bit", "lcd-18bit", "lcd-24bit",
325 "lcd-special", "lcd-generic",
326};
Paul Cercueilf2a96762018-08-21 18:42:34 +0200327
328static const struct function_desc jz4725b_functions[] = {
329 { "mmc0", jz4725b_mmc0_groups, ARRAY_SIZE(jz4725b_mmc0_groups), },
330 { "mmc1", jz4725b_mmc1_groups, ARRAY_SIZE(jz4725b_mmc1_groups), },
331 { "uart", jz4725b_uart_groups, ARRAY_SIZE(jz4725b_uart_groups), },
332 { "nand", jz4725b_nand_groups, ARRAY_SIZE(jz4725b_nand_groups), },
333 { "pwm0", jz4725b_pwm0_groups, ARRAY_SIZE(jz4725b_pwm0_groups), },
334 { "pwm1", jz4725b_pwm1_groups, ARRAY_SIZE(jz4725b_pwm1_groups), },
335 { "pwm2", jz4725b_pwm2_groups, ARRAY_SIZE(jz4725b_pwm2_groups), },
336 { "pwm3", jz4725b_pwm3_groups, ARRAY_SIZE(jz4725b_pwm3_groups), },
337 { "pwm4", jz4725b_pwm4_groups, ARRAY_SIZE(jz4725b_pwm4_groups), },
338 { "pwm5", jz4725b_pwm5_groups, ARRAY_SIZE(jz4725b_pwm5_groups), },
Paul Cercueila3240f02019-02-07 10:55:36 -0300339 { "lcd", jz4725b_lcd_groups, ARRAY_SIZE(jz4725b_lcd_groups), },
Paul Cercueilf2a96762018-08-21 18:42:34 +0200340};
341
342static const struct ingenic_chip_info jz4725b_chip_info = {
343 .num_chips = 4,
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +0800344 .reg_offset = 0x100,
Paul Cercueilf2a96762018-08-21 18:42:34 +0200345 .groups = jz4725b_groups,
346 .num_groups = ARRAY_SIZE(jz4725b_groups),
347 .functions = jz4725b_functions,
348 .num_functions = ARRAY_SIZE(jz4725b_functions),
349 .pull_ups = jz4740_pull_ups,
350 .pull_downs = jz4740_pull_downs,
351};
352
Zhou Yanjie0257595a2019-07-14 11:53:52 +0800353static const u32 jz4760_pull_ups[6] = {
354 0xffffffff, 0xfffcf3ff, 0xffffffff, 0xffffcfff, 0xfffffb7c, 0xfffff00f,
355};
356
357static const u32 jz4760_pull_downs[6] = {
358 0x00000000, 0x00030c00, 0x00000000, 0x00003000, 0x00000483, 0x00000ff0,
359};
360
361static int jz4760_uart0_data_pins[] = { 0xa0, 0xa3, };
362static int jz4760_uart0_hwflow_pins[] = { 0xa1, 0xa2, };
363static int jz4760_uart1_data_pins[] = { 0x7a, 0x7c, };
364static int jz4760_uart1_hwflow_pins[] = { 0x7b, 0x7d, };
365static int jz4760_uart2_data_pins[] = { 0x5c, 0x5e, };
366static int jz4760_uart2_hwflow_pins[] = { 0x5d, 0x5f, };
367static int jz4760_uart3_data_pins[] = { 0x6c, 0x85, };
368static int jz4760_uart3_hwflow_pins[] = { 0x88, 0x89, };
369static int jz4760_mmc0_1bit_a_pins[] = { 0x12, 0x13, 0x14, };
370static int jz4760_mmc0_4bit_a_pins[] = { 0x15, 0x16, 0x17, };
371static int jz4760_mmc0_1bit_e_pins[] = { 0x9c, 0x9d, 0x94, };
372static int jz4760_mmc0_4bit_e_pins[] = { 0x95, 0x96, 0x97, };
373static int jz4760_mmc0_8bit_e_pins[] = { 0x98, 0x99, 0x9a, 0x9b, };
374static int jz4760_mmc1_1bit_d_pins[] = { 0x78, 0x79, 0x74, };
375static int jz4760_mmc1_4bit_d_pins[] = { 0x75, 0x76, 0x77, };
376static int jz4760_mmc1_1bit_e_pins[] = { 0x9c, 0x9d, 0x94, };
377static int jz4760_mmc1_4bit_e_pins[] = { 0x95, 0x96, 0x97, };
378static int jz4760_mmc1_8bit_e_pins[] = { 0x98, 0x99, 0x9a, 0x9b, };
379static int jz4760_mmc2_1bit_b_pins[] = { 0x3c, 0x3d, 0x34, };
380static int jz4760_mmc2_4bit_b_pins[] = { 0x35, 0x3e, 0x3f, };
381static int jz4760_mmc2_1bit_e_pins[] = { 0x9c, 0x9d, 0x94, };
382static int jz4760_mmc2_4bit_e_pins[] = { 0x95, 0x96, 0x97, };
383static int jz4760_mmc2_8bit_e_pins[] = { 0x98, 0x99, 0x9a, 0x9b, };
384static int jz4760_nemc_8bit_data_pins[] = {
385 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
386};
387static int jz4760_nemc_16bit_data_pins[] = {
388 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
389};
390static int jz4760_nemc_cle_ale_pins[] = { 0x20, 0x21, };
391static int jz4760_nemc_addr_pins[] = { 0x22, 0x23, 0x24, 0x25, };
392static int jz4760_nemc_rd_we_pins[] = { 0x10, 0x11, };
393static int jz4760_nemc_frd_fwe_pins[] = { 0x12, 0x13, };
394static int jz4760_nemc_wait_pins[] = { 0x1b, };
395static int jz4760_nemc_cs1_pins[] = { 0x15, };
396static int jz4760_nemc_cs2_pins[] = { 0x16, };
397static int jz4760_nemc_cs3_pins[] = { 0x17, };
398static int jz4760_nemc_cs4_pins[] = { 0x18, };
399static int jz4760_nemc_cs5_pins[] = { 0x19, };
400static int jz4760_nemc_cs6_pins[] = { 0x1a, };
401static int jz4760_i2c0_pins[] = { 0x7e, 0x7f, };
402static int jz4760_i2c1_pins[] = { 0x9e, 0x9f, };
403static int jz4760_cim_pins[] = {
404 0x26, 0x27, 0x28, 0x29,
405 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31,
406};
407static int jz4760_lcd_24bit_pins[] = {
408 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
409 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
410 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
411 0x58, 0x59, 0x5a, 0x5b,
412};
413static int jz4760_pwm_pwm0_pins[] = { 0x80, };
414static int jz4760_pwm_pwm1_pins[] = { 0x81, };
415static int jz4760_pwm_pwm2_pins[] = { 0x82, };
416static int jz4760_pwm_pwm3_pins[] = { 0x83, };
417static int jz4760_pwm_pwm4_pins[] = { 0x84, };
418static int jz4760_pwm_pwm5_pins[] = { 0x85, };
419static int jz4760_pwm_pwm6_pins[] = { 0x6a, };
420static int jz4760_pwm_pwm7_pins[] = { 0x6b, };
421
422static int jz4760_uart0_data_funcs[] = { 0, 0, };
423static int jz4760_uart0_hwflow_funcs[] = { 0, 0, };
424static int jz4760_uart1_data_funcs[] = { 0, 0, };
425static int jz4760_uart1_hwflow_funcs[] = { 0, 0, };
426static int jz4760_uart2_data_funcs[] = { 0, 0, };
427static int jz4760_uart2_hwflow_funcs[] = { 0, 0, };
428static int jz4760_uart3_data_funcs[] = { 0, 1, };
429static int jz4760_uart3_hwflow_funcs[] = { 0, 0, };
430static int jz4760_mmc0_1bit_a_funcs[] = { 1, 1, 0, };
431static int jz4760_mmc0_4bit_a_funcs[] = { 1, 1, 1, };
432static int jz4760_mmc0_1bit_e_funcs[] = { 0, 0, 0, };
433static int jz4760_mmc0_4bit_e_funcs[] = { 0, 0, 0, };
434static int jz4760_mmc0_8bit_e_funcs[] = { 0, 0, 0, 0, };
435static int jz4760_mmc1_1bit_d_funcs[] = { 0, 0, 0, };
436static int jz4760_mmc1_4bit_d_funcs[] = { 0, 0, 0, };
437static int jz4760_mmc1_1bit_e_funcs[] = { 1, 1, 1, };
438static int jz4760_mmc1_4bit_e_funcs[] = { 1, 1, 1, };
439static int jz4760_mmc1_8bit_e_funcs[] = { 1, 1, 1, 1, };
440static int jz4760_mmc2_1bit_b_funcs[] = { 0, 0, 0, };
441static int jz4760_mmc2_4bit_b_funcs[] = { 0, 0, 0, };
442static int jz4760_mmc2_1bit_e_funcs[] = { 2, 2, 2, };
443static int jz4760_mmc2_4bit_e_funcs[] = { 2, 2, 2, };
444static int jz4760_mmc2_8bit_e_funcs[] = { 2, 2, 2, 2, };
445static int jz4760_nemc_8bit_data_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, };
446static int jz4760_nemc_16bit_data_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, };
447static int jz4760_nemc_cle_ale_funcs[] = { 0, 0, };
448static int jz4760_nemc_addr_funcs[] = { 0, 0, 0, 0, };
449static int jz4760_nemc_rd_we_funcs[] = { 0, 0, };
450static int jz4760_nemc_frd_fwe_funcs[] = { 0, 0, };
451static int jz4760_nemc_wait_funcs[] = { 0, };
452static int jz4760_nemc_cs1_funcs[] = { 0, };
453static int jz4760_nemc_cs2_funcs[] = { 0, };
454static int jz4760_nemc_cs3_funcs[] = { 0, };
455static int jz4760_nemc_cs4_funcs[] = { 0, };
456static int jz4760_nemc_cs5_funcs[] = { 0, };
457static int jz4760_nemc_cs6_funcs[] = { 0, };
458static int jz4760_i2c0_funcs[] = { 0, 0, };
459static int jz4760_i2c1_funcs[] = { 0, 0, };
460static int jz4760_cim_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
461static int jz4760_lcd_24bit_funcs[] = {
462 0, 0, 0, 0, 0, 0, 0, 0,
463 0, 0, 0, 0, 0, 0, 0, 0,
464 0, 0, 0, 0, 0, 0, 0, 0,
465 0, 0, 0, 0,
466};
467static int jz4760_pwm_pwm0_funcs[] = { 0, };
468static int jz4760_pwm_pwm1_funcs[] = { 0, };
469static int jz4760_pwm_pwm2_funcs[] = { 0, };
470static int jz4760_pwm_pwm3_funcs[] = { 0, };
471static int jz4760_pwm_pwm4_funcs[] = { 0, };
472static int jz4760_pwm_pwm5_funcs[] = { 0, };
473static int jz4760_pwm_pwm6_funcs[] = { 0, };
474static int jz4760_pwm_pwm7_funcs[] = { 0, };
475
476static const struct group_desc jz4760_groups[] = {
477 INGENIC_PIN_GROUP("uart0-data", jz4760_uart0_data),
478 INGENIC_PIN_GROUP("uart0-hwflow", jz4760_uart0_hwflow),
479 INGENIC_PIN_GROUP("uart1-data", jz4760_uart1_data),
480 INGENIC_PIN_GROUP("uart1-hwflow", jz4760_uart1_hwflow),
481 INGENIC_PIN_GROUP("uart2-data", jz4760_uart2_data),
482 INGENIC_PIN_GROUP("uart2-hwflow", jz4760_uart2_hwflow),
483 INGENIC_PIN_GROUP("uart3-data", jz4760_uart3_data),
484 INGENIC_PIN_GROUP("uart3-hwflow", jz4760_uart3_hwflow),
485 INGENIC_PIN_GROUP("mmc0-1bit-a", jz4760_mmc0_1bit_a),
486 INGENIC_PIN_GROUP("mmc0-4bit-a", jz4760_mmc0_4bit_a),
487 INGENIC_PIN_GROUP("mmc0-1bit-e", jz4760_mmc0_1bit_e),
488 INGENIC_PIN_GROUP("mmc0-4bit-e", jz4760_mmc0_4bit_e),
489 INGENIC_PIN_GROUP("mmc0-8bit-e", jz4760_mmc0_8bit_e),
490 INGENIC_PIN_GROUP("mmc1-1bit-d", jz4760_mmc1_1bit_d),
491 INGENIC_PIN_GROUP("mmc1-4bit-d", jz4760_mmc1_4bit_d),
492 INGENIC_PIN_GROUP("mmc1-1bit-e", jz4760_mmc1_1bit_e),
493 INGENIC_PIN_GROUP("mmc1-4bit-e", jz4760_mmc1_4bit_e),
494 INGENIC_PIN_GROUP("mmc1-8bit-e", jz4760_mmc1_8bit_e),
495 INGENIC_PIN_GROUP("mmc2-1bit-b", jz4760_mmc2_1bit_b),
496 INGENIC_PIN_GROUP("mmc2-4bit-b", jz4760_mmc2_4bit_b),
497 INGENIC_PIN_GROUP("mmc2-1bit-e", jz4760_mmc2_1bit_e),
498 INGENIC_PIN_GROUP("mmc2-4bit-e", jz4760_mmc2_4bit_e),
499 INGENIC_PIN_GROUP("mmc2-8bit-e", jz4760_mmc2_8bit_e),
500 INGENIC_PIN_GROUP("nemc-8bit-data", jz4760_nemc_8bit_data),
501 INGENIC_PIN_GROUP("nemc-16bit-data", jz4760_nemc_16bit_data),
502 INGENIC_PIN_GROUP("nemc-cle-ale", jz4760_nemc_cle_ale),
503 INGENIC_PIN_GROUP("nemc-addr", jz4760_nemc_addr),
504 INGENIC_PIN_GROUP("nemc-rd-we", jz4760_nemc_rd_we),
505 INGENIC_PIN_GROUP("nemc-frd-fwe", jz4760_nemc_frd_fwe),
506 INGENIC_PIN_GROUP("nemc-wait", jz4760_nemc_wait),
507 INGENIC_PIN_GROUP("nemc-cs1", jz4760_nemc_cs1),
508 INGENIC_PIN_GROUP("nemc-cs2", jz4760_nemc_cs2),
509 INGENIC_PIN_GROUP("nemc-cs3", jz4760_nemc_cs3),
510 INGENIC_PIN_GROUP("nemc-cs4", jz4760_nemc_cs4),
511 INGENIC_PIN_GROUP("nemc-cs5", jz4760_nemc_cs5),
512 INGENIC_PIN_GROUP("nemc-cs6", jz4760_nemc_cs6),
513 INGENIC_PIN_GROUP("i2c0-data", jz4760_i2c0),
514 INGENIC_PIN_GROUP("i2c1-data", jz4760_i2c1),
515 INGENIC_PIN_GROUP("cim-data", jz4760_cim),
516 INGENIC_PIN_GROUP("lcd-24bit", jz4760_lcd_24bit),
517 { "lcd-no-pins", },
518 INGENIC_PIN_GROUP("pwm0", jz4760_pwm_pwm0),
519 INGENIC_PIN_GROUP("pwm1", jz4760_pwm_pwm1),
520 INGENIC_PIN_GROUP("pwm2", jz4760_pwm_pwm2),
521 INGENIC_PIN_GROUP("pwm3", jz4760_pwm_pwm3),
522 INGENIC_PIN_GROUP("pwm4", jz4760_pwm_pwm4),
523 INGENIC_PIN_GROUP("pwm5", jz4760_pwm_pwm5),
524 INGENIC_PIN_GROUP("pwm6", jz4760_pwm_pwm6),
525 INGENIC_PIN_GROUP("pwm7", jz4760_pwm_pwm7),
526};
527
528static const char *jz4760_uart0_groups[] = { "uart0-data", "uart0-hwflow", };
529static const char *jz4760_uart1_groups[] = { "uart1-data", "uart1-hwflow", };
530static const char *jz4760_uart2_groups[] = { "uart2-data", "uart2-hwflow", };
531static const char *jz4760_uart3_groups[] = { "uart3-data", "uart3-hwflow", };
532static const char *jz4760_mmc0_groups[] = {
533 "mmc0-1bit-a", "mmc0-4bit-a",
534 "mmc0-1bit-e", "mmc0-4bit-e", "mmc0-8bit-e",
535};
536static const char *jz4760_mmc1_groups[] = {
537 "mmc1-1bit-d", "mmc1-4bit-d",
538 "mmc1-1bit-e", "mmc1-4bit-e", "mmc1-8bit-e",
539};
540static const char *jz4760_mmc2_groups[] = {
541 "mmc2-1bit-b", "mmc2-4bit-b",
542 "mmc2-1bit-e", "mmc2-4bit-e", "mmc2-8bit-e",
543};
544static const char *jz4760_nemc_groups[] = {
545 "nemc-8bit-data", "nemc-16bit-data", "nemc-cle-ale",
546 "nemc-addr", "nemc-rd-we", "nemc-frd-fwe", "nemc-wait",
547};
548static const char *jz4760_cs1_groups[] = { "nemc-cs1", };
549static const char *jz4760_cs2_groups[] = { "nemc-cs2", };
550static const char *jz4760_cs3_groups[] = { "nemc-cs3", };
551static const char *jz4760_cs4_groups[] = { "nemc-cs4", };
552static const char *jz4760_cs5_groups[] = { "nemc-cs5", };
553static const char *jz4760_cs6_groups[] = { "nemc-cs6", };
554static const char *jz4760_i2c0_groups[] = { "i2c0-data", };
555static const char *jz4760_i2c1_groups[] = { "i2c1-data", };
556static const char *jz4760_cim_groups[] = { "cim-data", };
557static const char *jz4760_lcd_groups[] = { "lcd-24bit", "lcd-no-pins", };
558static const char *jz4760_pwm0_groups[] = { "pwm0", };
559static const char *jz4760_pwm1_groups[] = { "pwm1", };
560static const char *jz4760_pwm2_groups[] = { "pwm2", };
561static const char *jz4760_pwm3_groups[] = { "pwm3", };
562static const char *jz4760_pwm4_groups[] = { "pwm4", };
563static const char *jz4760_pwm5_groups[] = { "pwm5", };
564static const char *jz4760_pwm6_groups[] = { "pwm6", };
565static const char *jz4760_pwm7_groups[] = { "pwm7", };
566
567static const struct function_desc jz4760_functions[] = {
568 { "uart0", jz4760_uart0_groups, ARRAY_SIZE(jz4760_uart0_groups), },
569 { "uart1", jz4760_uart1_groups, ARRAY_SIZE(jz4760_uart1_groups), },
570 { "uart2", jz4760_uart2_groups, ARRAY_SIZE(jz4760_uart2_groups), },
571 { "uart3", jz4760_uart3_groups, ARRAY_SIZE(jz4760_uart3_groups), },
572 { "mmc0", jz4760_mmc0_groups, ARRAY_SIZE(jz4760_mmc0_groups), },
573 { "mmc1", jz4760_mmc1_groups, ARRAY_SIZE(jz4760_mmc1_groups), },
574 { "mmc2", jz4760_mmc2_groups, ARRAY_SIZE(jz4760_mmc2_groups), },
575 { "nemc", jz4760_nemc_groups, ARRAY_SIZE(jz4760_nemc_groups), },
576 { "nemc-cs1", jz4760_cs1_groups, ARRAY_SIZE(jz4760_cs1_groups), },
577 { "nemc-cs2", jz4760_cs2_groups, ARRAY_SIZE(jz4760_cs2_groups), },
578 { "nemc-cs3", jz4760_cs3_groups, ARRAY_SIZE(jz4760_cs3_groups), },
579 { "nemc-cs4", jz4760_cs4_groups, ARRAY_SIZE(jz4760_cs4_groups), },
580 { "nemc-cs5", jz4760_cs5_groups, ARRAY_SIZE(jz4760_cs5_groups), },
581 { "nemc-cs6", jz4760_cs6_groups, ARRAY_SIZE(jz4760_cs6_groups), },
582 { "i2c0", jz4760_i2c0_groups, ARRAY_SIZE(jz4760_i2c0_groups), },
583 { "i2c1", jz4760_i2c1_groups, ARRAY_SIZE(jz4760_i2c1_groups), },
584 { "cim", jz4760_cim_groups, ARRAY_SIZE(jz4760_cim_groups), },
585 { "lcd", jz4760_lcd_groups, ARRAY_SIZE(jz4760_lcd_groups), },
586 { "pwm0", jz4760_pwm0_groups, ARRAY_SIZE(jz4760_pwm0_groups), },
587 { "pwm1", jz4760_pwm1_groups, ARRAY_SIZE(jz4760_pwm1_groups), },
588 { "pwm2", jz4760_pwm2_groups, ARRAY_SIZE(jz4760_pwm2_groups), },
589 { "pwm3", jz4760_pwm3_groups, ARRAY_SIZE(jz4760_pwm3_groups), },
590 { "pwm4", jz4760_pwm4_groups, ARRAY_SIZE(jz4760_pwm4_groups), },
591 { "pwm5", jz4760_pwm5_groups, ARRAY_SIZE(jz4760_pwm5_groups), },
592 { "pwm6", jz4760_pwm6_groups, ARRAY_SIZE(jz4760_pwm6_groups), },
593 { "pwm7", jz4760_pwm7_groups, ARRAY_SIZE(jz4760_pwm7_groups), },
594};
595
596static const struct ingenic_chip_info jz4760_chip_info = {
597 .num_chips = 6,
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +0800598 .reg_offset = 0x100,
Zhou Yanjie0257595a2019-07-14 11:53:52 +0800599 .groups = jz4760_groups,
600 .num_groups = ARRAY_SIZE(jz4760_groups),
601 .functions = jz4760_functions,
602 .num_functions = ARRAY_SIZE(jz4760_functions),
603 .pull_ups = jz4760_pull_ups,
604 .pull_downs = jz4760_pull_downs,
605};
606
607static const struct ingenic_chip_info jz4760b_chip_info = {
608 .num_chips = 6,
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +0800609 .reg_offset = 0x100,
Zhou Yanjie0257595a2019-07-14 11:53:52 +0800610 .groups = jz4760_groups,
611 .num_groups = ARRAY_SIZE(jz4760_groups),
612 .functions = jz4760_functions,
613 .num_functions = ARRAY_SIZE(jz4760_functions),
614 .pull_ups = jz4760_pull_ups,
615 .pull_downs = jz4760_pull_downs,
616};
617
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200618static const u32 jz4770_pull_ups[6] = {
619 0x3fffffff, 0xfff0030c, 0xffffffff, 0xffff4fff, 0xfffffb7c, 0xffa7f00f,
620};
621
622static const u32 jz4770_pull_downs[6] = {
623 0x00000000, 0x000f0c03, 0x00000000, 0x0000b000, 0x00000483, 0x00580ff0,
624};
625
626static int jz4770_uart0_data_pins[] = { 0xa0, 0xa3, };
627static int jz4770_uart0_hwflow_pins[] = { 0xa1, 0xa2, };
628static int jz4770_uart1_data_pins[] = { 0x7a, 0x7c, };
629static int jz4770_uart1_hwflow_pins[] = { 0x7b, 0x7d, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800630static int jz4770_uart2_data_pins[] = { 0x5c, 0x5e, };
631static int jz4770_uart2_hwflow_pins[] = { 0x5d, 0x5f, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200632static int jz4770_uart3_data_pins[] = { 0x6c, 0x85, };
633static int jz4770_uart3_hwflow_pins[] = { 0x88, 0x89, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200634static int jz4770_mmc0_1bit_a_pins[] = { 0x12, 0x13, 0x14, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800635static int jz4770_mmc0_4bit_a_pins[] = { 0x15, 0x16, 0x17, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200636static int jz4770_mmc0_1bit_e_pins[] = { 0x9c, 0x9d, 0x94, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800637static int jz4770_mmc0_4bit_e_pins[] = { 0x95, 0x96, 0x97, };
638static int jz4770_mmc0_8bit_e_pins[] = { 0x98, 0x99, 0x9a, 0x9b, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200639static int jz4770_mmc1_1bit_d_pins[] = { 0x78, 0x79, 0x74, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800640static int jz4770_mmc1_4bit_d_pins[] = { 0x75, 0x76, 0x77, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200641static int jz4770_mmc1_1bit_e_pins[] = { 0x9c, 0x9d, 0x94, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800642static int jz4770_mmc1_4bit_e_pins[] = { 0x95, 0x96, 0x97, };
643static int jz4770_mmc1_8bit_e_pins[] = { 0x98, 0x99, 0x9a, 0x9b, };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800644static int jz4770_mmc2_1bit_b_pins[] = { 0x3c, 0x3d, 0x34, };
645static int jz4770_mmc2_4bit_b_pins[] = { 0x35, 0x3e, 0x3f, };
646static int jz4770_mmc2_1bit_e_pins[] = { 0x9c, 0x9d, 0x94, };
647static int jz4770_mmc2_4bit_e_pins[] = { 0x95, 0x96, 0x97, };
648static int jz4770_mmc2_8bit_e_pins[] = { 0x98, 0x99, 0x9a, 0x9b, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800649static int jz4770_nemc_8bit_data_pins[] = {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200650 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
651};
Zhou Yanjieff656e42019-01-28 23:19:57 +0800652static int jz4770_nemc_16bit_data_pins[] = {
653 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
654};
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200655static int jz4770_nemc_cle_ale_pins[] = { 0x20, 0x21, };
656static int jz4770_nemc_addr_pins[] = { 0x22, 0x23, 0x24, 0x25, };
657static int jz4770_nemc_rd_we_pins[] = { 0x10, 0x11, };
658static int jz4770_nemc_frd_fwe_pins[] = { 0x12, 0x13, };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800659static int jz4770_nemc_wait_pins[] = { 0x1b, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200660static int jz4770_nemc_cs1_pins[] = { 0x15, };
661static int jz4770_nemc_cs2_pins[] = { 0x16, };
662static int jz4770_nemc_cs3_pins[] = { 0x17, };
663static int jz4770_nemc_cs4_pins[] = { 0x18, };
664static int jz4770_nemc_cs5_pins[] = { 0x19, };
665static int jz4770_nemc_cs6_pins[] = { 0x1a, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800666static int jz4770_i2c0_pins[] = { 0x7e, 0x7f, };
667static int jz4770_i2c1_pins[] = { 0x9e, 0x9f, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200668static int jz4770_i2c2_pins[] = { 0xb0, 0xb1, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800669static int jz4770_cim_8bit_pins[] = {
670 0x26, 0x27, 0x28, 0x29,
671 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31,
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200672};
Zhou Yanjieff656e42019-01-28 23:19:57 +0800673static int jz4770_cim_12bit_pins[] = {
674 0x32, 0x33, 0xb0, 0xb1,
675};
676static int jz4770_lcd_24bit_pins[] = {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200677 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
678 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
679 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
Zhou Yanjieff656e42019-01-28 23:19:57 +0800680 0x58, 0x59, 0x5a, 0x5b,
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200681};
682static int jz4770_pwm_pwm0_pins[] = { 0x80, };
683static int jz4770_pwm_pwm1_pins[] = { 0x81, };
684static int jz4770_pwm_pwm2_pins[] = { 0x82, };
685static int jz4770_pwm_pwm3_pins[] = { 0x83, };
686static int jz4770_pwm_pwm4_pins[] = { 0x84, };
687static int jz4770_pwm_pwm5_pins[] = { 0x85, };
688static int jz4770_pwm_pwm6_pins[] = { 0x6a, };
689static int jz4770_pwm_pwm7_pins[] = { 0x6b, };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800690static int jz4770_mac_rmii_pins[] = {
691 0xa9, 0xab, 0xaa, 0xac, 0xa5, 0xa4, 0xad, 0xae, 0xa6, 0xa8,
692};
693static int jz4770_mac_mii_pins[] = { 0xa7, 0xaf, };
Paul Cercueilae75b532019-11-19 16:52:11 +0100694static int jz4770_otg_pins[] = { 0x8a, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200695
696static int jz4770_uart0_data_funcs[] = { 0, 0, };
697static int jz4770_uart0_hwflow_funcs[] = { 0, 0, };
698static int jz4770_uart1_data_funcs[] = { 0, 0, };
699static int jz4770_uart1_hwflow_funcs[] = { 0, 0, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800700static int jz4770_uart2_data_funcs[] = { 0, 0, };
701static int jz4770_uart2_hwflow_funcs[] = { 0, 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200702static int jz4770_uart3_data_funcs[] = { 0, 1, };
703static int jz4770_uart3_hwflow_funcs[] = { 0, 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200704static int jz4770_mmc0_1bit_a_funcs[] = { 1, 1, 0, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800705static int jz4770_mmc0_4bit_a_funcs[] = { 1, 1, 1, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200706static int jz4770_mmc0_1bit_e_funcs[] = { 0, 0, 0, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800707static int jz4770_mmc0_4bit_e_funcs[] = { 0, 0, 0, };
708static int jz4770_mmc0_8bit_e_funcs[] = { 0, 0, 0, 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200709static int jz4770_mmc1_1bit_d_funcs[] = { 0, 0, 0, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800710static int jz4770_mmc1_4bit_d_funcs[] = { 0, 0, 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200711static int jz4770_mmc1_1bit_e_funcs[] = { 1, 1, 1, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800712static int jz4770_mmc1_4bit_e_funcs[] = { 1, 1, 1, };
713static int jz4770_mmc1_8bit_e_funcs[] = { 1, 1, 1, 1, };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800714static int jz4770_mmc2_1bit_b_funcs[] = { 0, 0, 0, };
715static int jz4770_mmc2_4bit_b_funcs[] = { 0, 0, 0, };
716static int jz4770_mmc2_1bit_e_funcs[] = { 2, 2, 2, };
717static int jz4770_mmc2_4bit_e_funcs[] = { 2, 2, 2, };
718static int jz4770_mmc2_8bit_e_funcs[] = { 2, 2, 2, 2, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800719static int jz4770_nemc_8bit_data_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, };
720static int jz4770_nemc_16bit_data_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200721static int jz4770_nemc_cle_ale_funcs[] = { 0, 0, };
722static int jz4770_nemc_addr_funcs[] = { 0, 0, 0, 0, };
723static int jz4770_nemc_rd_we_funcs[] = { 0, 0, };
724static int jz4770_nemc_frd_fwe_funcs[] = { 0, 0, };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800725static int jz4770_nemc_wait_funcs[] = { 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200726static int jz4770_nemc_cs1_funcs[] = { 0, };
727static int jz4770_nemc_cs2_funcs[] = { 0, };
728static int jz4770_nemc_cs3_funcs[] = { 0, };
729static int jz4770_nemc_cs4_funcs[] = { 0, };
730static int jz4770_nemc_cs5_funcs[] = { 0, };
731static int jz4770_nemc_cs6_funcs[] = { 0, };
732static int jz4770_i2c0_funcs[] = { 0, 0, };
733static int jz4770_i2c1_funcs[] = { 0, 0, };
734static int jz4770_i2c2_funcs[] = { 2, 2, };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800735static int jz4770_cim_8bit_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
736static int jz4770_cim_12bit_funcs[] = { 0, 0, 0, 0, };
737static int jz4770_lcd_24bit_funcs[] = {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200738 0, 0, 0, 0, 0, 0, 0, 0,
739 0, 0, 0, 0, 0, 0, 0, 0,
Zhou Yanjieff656e42019-01-28 23:19:57 +0800740 0, 0, 0, 0, 0, 0, 0, 0,
741 0, 0, 0, 0,
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200742};
743static int jz4770_pwm_pwm0_funcs[] = { 0, };
744static int jz4770_pwm_pwm1_funcs[] = { 0, };
745static int jz4770_pwm_pwm2_funcs[] = { 0, };
746static int jz4770_pwm_pwm3_funcs[] = { 0, };
747static int jz4770_pwm_pwm4_funcs[] = { 0, };
748static int jz4770_pwm_pwm5_funcs[] = { 0, };
749static int jz4770_pwm_pwm6_funcs[] = { 0, };
750static int jz4770_pwm_pwm7_funcs[] = { 0, };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800751static int jz4770_mac_rmii_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
752static int jz4770_mac_mii_funcs[] = { 0, 0, };
Paul Cercueilae75b532019-11-19 16:52:11 +0100753static int jz4770_otg_funcs[] = { 0, };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200754
755static const struct group_desc jz4770_groups[] = {
756 INGENIC_PIN_GROUP("uart0-data", jz4770_uart0_data),
757 INGENIC_PIN_GROUP("uart0-hwflow", jz4770_uart0_hwflow),
758 INGENIC_PIN_GROUP("uart1-data", jz4770_uart1_data),
759 INGENIC_PIN_GROUP("uart1-hwflow", jz4770_uart1_hwflow),
760 INGENIC_PIN_GROUP("uart2-data", jz4770_uart2_data),
761 INGENIC_PIN_GROUP("uart2-hwflow", jz4770_uart2_hwflow),
762 INGENIC_PIN_GROUP("uart3-data", jz4770_uart3_data),
763 INGENIC_PIN_GROUP("uart3-hwflow", jz4770_uart3_hwflow),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200764 INGENIC_PIN_GROUP("mmc0-1bit-a", jz4770_mmc0_1bit_a),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800765 INGENIC_PIN_GROUP("mmc0-4bit-a", jz4770_mmc0_4bit_a),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200766 INGENIC_PIN_GROUP("mmc0-1bit-e", jz4770_mmc0_1bit_e),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800767 INGENIC_PIN_GROUP("mmc0-4bit-e", jz4770_mmc0_4bit_e),
768 INGENIC_PIN_GROUP("mmc0-8bit-e", jz4770_mmc0_8bit_e),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200769 INGENIC_PIN_GROUP("mmc1-1bit-d", jz4770_mmc1_1bit_d),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800770 INGENIC_PIN_GROUP("mmc1-4bit-d", jz4770_mmc1_4bit_d),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200771 INGENIC_PIN_GROUP("mmc1-1bit-e", jz4770_mmc1_1bit_e),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800772 INGENIC_PIN_GROUP("mmc1-4bit-e", jz4770_mmc1_4bit_e),
773 INGENIC_PIN_GROUP("mmc1-8bit-e", jz4770_mmc1_8bit_e),
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800774 INGENIC_PIN_GROUP("mmc2-1bit-b", jz4770_mmc2_1bit_b),
775 INGENIC_PIN_GROUP("mmc2-4bit-b", jz4770_mmc2_4bit_b),
776 INGENIC_PIN_GROUP("mmc2-1bit-e", jz4770_mmc2_1bit_e),
777 INGENIC_PIN_GROUP("mmc2-4bit-e", jz4770_mmc2_4bit_e),
778 INGENIC_PIN_GROUP("mmc2-8bit-e", jz4770_mmc2_8bit_e),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800779 INGENIC_PIN_GROUP("nemc-8bit-data", jz4770_nemc_8bit_data),
780 INGENIC_PIN_GROUP("nemc-16bit-data", jz4770_nemc_16bit_data),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200781 INGENIC_PIN_GROUP("nemc-cle-ale", jz4770_nemc_cle_ale),
782 INGENIC_PIN_GROUP("nemc-addr", jz4770_nemc_addr),
783 INGENIC_PIN_GROUP("nemc-rd-we", jz4770_nemc_rd_we),
784 INGENIC_PIN_GROUP("nemc-frd-fwe", jz4770_nemc_frd_fwe),
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800785 INGENIC_PIN_GROUP("nemc-wait", jz4770_nemc_wait),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200786 INGENIC_PIN_GROUP("nemc-cs1", jz4770_nemc_cs1),
787 INGENIC_PIN_GROUP("nemc-cs2", jz4770_nemc_cs2),
788 INGENIC_PIN_GROUP("nemc-cs3", jz4770_nemc_cs3),
789 INGENIC_PIN_GROUP("nemc-cs4", jz4770_nemc_cs4),
790 INGENIC_PIN_GROUP("nemc-cs5", jz4770_nemc_cs5),
791 INGENIC_PIN_GROUP("nemc-cs6", jz4770_nemc_cs6),
792 INGENIC_PIN_GROUP("i2c0-data", jz4770_i2c0),
793 INGENIC_PIN_GROUP("i2c1-data", jz4770_i2c1),
794 INGENIC_PIN_GROUP("i2c2-data", jz4770_i2c2),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800795 INGENIC_PIN_GROUP("cim-data-8bit", jz4770_cim_8bit),
796 INGENIC_PIN_GROUP("cim-data-12bit", jz4770_cim_12bit),
797 INGENIC_PIN_GROUP("lcd-24bit", jz4770_lcd_24bit),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200798 { "lcd-no-pins", },
799 INGENIC_PIN_GROUP("pwm0", jz4770_pwm_pwm0),
800 INGENIC_PIN_GROUP("pwm1", jz4770_pwm_pwm1),
801 INGENIC_PIN_GROUP("pwm2", jz4770_pwm_pwm2),
802 INGENIC_PIN_GROUP("pwm3", jz4770_pwm_pwm3),
803 INGENIC_PIN_GROUP("pwm4", jz4770_pwm_pwm4),
804 INGENIC_PIN_GROUP("pwm5", jz4770_pwm_pwm5),
805 INGENIC_PIN_GROUP("pwm6", jz4770_pwm_pwm6),
806 INGENIC_PIN_GROUP("pwm7", jz4770_pwm_pwm7),
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800807 INGENIC_PIN_GROUP("mac-rmii", jz4770_mac_rmii),
808 INGENIC_PIN_GROUP("mac-mii", jz4770_mac_mii),
Paul Cercueilae75b532019-11-19 16:52:11 +0100809 INGENIC_PIN_GROUP("otg-vbus", jz4770_otg),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200810};
811
812static const char *jz4770_uart0_groups[] = { "uart0-data", "uart0-hwflow", };
813static const char *jz4770_uart1_groups[] = { "uart1-data", "uart1-hwflow", };
814static const char *jz4770_uart2_groups[] = { "uart2-data", "uart2-hwflow", };
815static const char *jz4770_uart3_groups[] = { "uart3-data", "uart3-hwflow", };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200816static const char *jz4770_mmc0_groups[] = {
Zhou Yanjieff656e42019-01-28 23:19:57 +0800817 "mmc0-1bit-a", "mmc0-4bit-a",
818 "mmc0-1bit-e", "mmc0-4bit-e", "mmc0-8bit-e",
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200819};
820static const char *jz4770_mmc1_groups[] = {
Zhou Yanjieff656e42019-01-28 23:19:57 +0800821 "mmc1-1bit-d", "mmc1-4bit-d",
822 "mmc1-1bit-e", "mmc1-4bit-e", "mmc1-8bit-e",
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200823};
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800824static const char *jz4770_mmc2_groups[] = {
825 "mmc2-1bit-b", "mmc2-4bit-b",
826 "mmc2-1bit-e", "mmc2-4bit-e", "mmc2-8bit-e",
827};
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200828static const char *jz4770_nemc_groups[] = {
Zhou Yanjieff656e42019-01-28 23:19:57 +0800829 "nemc-8bit-data", "nemc-16bit-data", "nemc-cle-ale",
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800830 "nemc-addr", "nemc-rd-we", "nemc-frd-fwe", "nemc-wait",
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200831};
832static const char *jz4770_cs1_groups[] = { "nemc-cs1", };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800833static const char *jz4770_cs2_groups[] = { "nemc-cs2", };
834static const char *jz4770_cs3_groups[] = { "nemc-cs3", };
835static const char *jz4770_cs4_groups[] = { "nemc-cs4", };
836static const char *jz4770_cs5_groups[] = { "nemc-cs5", };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200837static const char *jz4770_cs6_groups[] = { "nemc-cs6", };
838static const char *jz4770_i2c0_groups[] = { "i2c0-data", };
839static const char *jz4770_i2c1_groups[] = { "i2c1-data", };
840static const char *jz4770_i2c2_groups[] = { "i2c2-data", };
Zhou Yanjieff656e42019-01-28 23:19:57 +0800841static const char *jz4770_cim_groups[] = { "cim-data-8bit", "cim-data-12bit", };
842static const char *jz4770_lcd_groups[] = { "lcd-24bit", "lcd-no-pins", };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200843static const char *jz4770_pwm0_groups[] = { "pwm0", };
844static const char *jz4770_pwm1_groups[] = { "pwm1", };
845static const char *jz4770_pwm2_groups[] = { "pwm2", };
846static const char *jz4770_pwm3_groups[] = { "pwm3", };
847static const char *jz4770_pwm4_groups[] = { "pwm4", };
848static const char *jz4770_pwm5_groups[] = { "pwm5", };
849static const char *jz4770_pwm6_groups[] = { "pwm6", };
850static const char *jz4770_pwm7_groups[] = { "pwm7", };
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800851static const char *jz4770_mac_groups[] = { "mac-rmii", "mac-mii", };
Paul Cercueilae75b532019-11-19 16:52:11 +0100852static const char *jz4770_otg_groups[] = { "otg-vbus", };
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200853
854static const struct function_desc jz4770_functions[] = {
855 { "uart0", jz4770_uart0_groups, ARRAY_SIZE(jz4770_uart0_groups), },
856 { "uart1", jz4770_uart1_groups, ARRAY_SIZE(jz4770_uart1_groups), },
857 { "uart2", jz4770_uart2_groups, ARRAY_SIZE(jz4770_uart2_groups), },
858 { "uart3", jz4770_uart3_groups, ARRAY_SIZE(jz4770_uart3_groups), },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200859 { "mmc0", jz4770_mmc0_groups, ARRAY_SIZE(jz4770_mmc0_groups), },
860 { "mmc1", jz4770_mmc1_groups, ARRAY_SIZE(jz4770_mmc1_groups), },
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800861 { "mmc2", jz4770_mmc2_groups, ARRAY_SIZE(jz4770_mmc2_groups), },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200862 { "nemc", jz4770_nemc_groups, ARRAY_SIZE(jz4770_nemc_groups), },
863 { "nemc-cs1", jz4770_cs1_groups, ARRAY_SIZE(jz4770_cs1_groups), },
Zhou Yanjieff656e42019-01-28 23:19:57 +0800864 { "nemc-cs2", jz4770_cs2_groups, ARRAY_SIZE(jz4770_cs2_groups), },
865 { "nemc-cs3", jz4770_cs3_groups, ARRAY_SIZE(jz4770_cs3_groups), },
866 { "nemc-cs4", jz4770_cs4_groups, ARRAY_SIZE(jz4770_cs4_groups), },
867 { "nemc-cs5", jz4770_cs5_groups, ARRAY_SIZE(jz4770_cs5_groups), },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200868 { "nemc-cs6", jz4770_cs6_groups, ARRAY_SIZE(jz4770_cs6_groups), },
869 { "i2c0", jz4770_i2c0_groups, ARRAY_SIZE(jz4770_i2c0_groups), },
870 { "i2c1", jz4770_i2c1_groups, ARRAY_SIZE(jz4770_i2c1_groups), },
871 { "i2c2", jz4770_i2c2_groups, ARRAY_SIZE(jz4770_i2c2_groups), },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200872 { "cim", jz4770_cim_groups, ARRAY_SIZE(jz4770_cim_groups), },
873 { "lcd", jz4770_lcd_groups, ARRAY_SIZE(jz4770_lcd_groups), },
874 { "pwm0", jz4770_pwm0_groups, ARRAY_SIZE(jz4770_pwm0_groups), },
875 { "pwm1", jz4770_pwm1_groups, ARRAY_SIZE(jz4770_pwm1_groups), },
876 { "pwm2", jz4770_pwm2_groups, ARRAY_SIZE(jz4770_pwm2_groups), },
877 { "pwm3", jz4770_pwm3_groups, ARRAY_SIZE(jz4770_pwm3_groups), },
878 { "pwm4", jz4770_pwm4_groups, ARRAY_SIZE(jz4770_pwm4_groups), },
879 { "pwm5", jz4770_pwm5_groups, ARRAY_SIZE(jz4770_pwm5_groups), },
880 { "pwm6", jz4770_pwm6_groups, ARRAY_SIZE(jz4770_pwm6_groups), },
881 { "pwm7", jz4770_pwm7_groups, ARRAY_SIZE(jz4770_pwm7_groups), },
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800882 { "mac", jz4770_mac_groups, ARRAY_SIZE(jz4770_mac_groups), },
Paul Cercueilae75b532019-11-19 16:52:11 +0100883 { "otg", jz4770_otg_groups, ARRAY_SIZE(jz4770_otg_groups), },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200884};
885
886static const struct ingenic_chip_info jz4770_chip_info = {
887 .num_chips = 6,
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +0800888 .reg_offset = 0x100,
Paul Cercueilb5c23aa2017-05-12 18:52:56 +0200889 .groups = jz4770_groups,
890 .num_groups = ARRAY_SIZE(jz4770_groups),
891 .functions = jz4770_functions,
892 .num_functions = ARRAY_SIZE(jz4770_functions),
893 .pull_ups = jz4770_pull_ups,
894 .pull_downs = jz4770_pull_downs,
895};
896
Zhou Yanjieff656e42019-01-28 23:19:57 +0800897static int jz4780_uart2_data_pins[] = { 0x66, 0x67, };
898static int jz4780_uart2_hwflow_pins[] = { 0x65, 0x64, };
899static int jz4780_uart4_data_pins[] = { 0x54, 0x4a, };
900static int jz4780_mmc0_8bit_a_pins[] = { 0x04, 0x05, 0x06, 0x07, 0x18, };
901static int jz4780_i2c3_pins[] = { 0x6a, 0x6b, };
902static int jz4780_i2c4_e_pins[] = { 0x8c, 0x8d, };
903static int jz4780_i2c4_f_pins[] = { 0xb9, 0xb8, };
904
905static int jz4780_uart2_data_funcs[] = { 1, 1, };
906static int jz4780_uart2_hwflow_funcs[] = { 1, 1, };
907static int jz4780_uart4_data_funcs[] = { 2, 2, };
908static int jz4780_mmc0_8bit_a_funcs[] = { 1, 1, 1, 1, 1, };
909static int jz4780_i2c3_funcs[] = { 1, 1, };
910static int jz4780_i2c4_e_funcs[] = { 1, 1, };
911static int jz4780_i2c4_f_funcs[] = { 1, 1, };
912
913static const struct group_desc jz4780_groups[] = {
914 INGENIC_PIN_GROUP("uart0-data", jz4770_uart0_data),
915 INGENIC_PIN_GROUP("uart0-hwflow", jz4770_uart0_hwflow),
916 INGENIC_PIN_GROUP("uart1-data", jz4770_uart1_data),
917 INGENIC_PIN_GROUP("uart1-hwflow", jz4770_uart1_hwflow),
918 INGENIC_PIN_GROUP("uart2-data", jz4780_uart2_data),
919 INGENIC_PIN_GROUP("uart2-hwflow", jz4780_uart2_hwflow),
920 INGENIC_PIN_GROUP("uart3-data", jz4770_uart3_data),
921 INGENIC_PIN_GROUP("uart3-hwflow", jz4770_uart3_hwflow),
922 INGENIC_PIN_GROUP("uart4-data", jz4780_uart4_data),
923 INGENIC_PIN_GROUP("mmc0-1bit-a", jz4770_mmc0_1bit_a),
924 INGENIC_PIN_GROUP("mmc0-4bit-a", jz4770_mmc0_4bit_a),
925 INGENIC_PIN_GROUP("mmc0-8bit-a", jz4780_mmc0_8bit_a),
926 INGENIC_PIN_GROUP("mmc0-1bit-e", jz4770_mmc0_1bit_e),
927 INGENIC_PIN_GROUP("mmc0-4bit-e", jz4770_mmc0_4bit_e),
928 INGENIC_PIN_GROUP("mmc1-1bit-d", jz4770_mmc1_1bit_d),
929 INGENIC_PIN_GROUP("mmc1-4bit-d", jz4770_mmc1_4bit_d),
930 INGENIC_PIN_GROUP("mmc1-1bit-e", jz4770_mmc1_1bit_e),
931 INGENIC_PIN_GROUP("mmc1-4bit-e", jz4770_mmc1_4bit_e),
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800932 INGENIC_PIN_GROUP("mmc2-1bit-b", jz4770_mmc2_1bit_b),
933 INGENIC_PIN_GROUP("mmc2-4bit-b", jz4770_mmc2_4bit_b),
934 INGENIC_PIN_GROUP("mmc2-1bit-e", jz4770_mmc2_1bit_e),
935 INGENIC_PIN_GROUP("mmc2-4bit-e", jz4770_mmc2_4bit_e),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800936 INGENIC_PIN_GROUP("nemc-data", jz4770_nemc_8bit_data),
937 INGENIC_PIN_GROUP("nemc-cle-ale", jz4770_nemc_cle_ale),
938 INGENIC_PIN_GROUP("nemc-addr", jz4770_nemc_addr),
939 INGENIC_PIN_GROUP("nemc-rd-we", jz4770_nemc_rd_we),
940 INGENIC_PIN_GROUP("nemc-frd-fwe", jz4770_nemc_frd_fwe),
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800941 INGENIC_PIN_GROUP("nemc-wait", jz4770_nemc_wait),
Zhou Yanjieff656e42019-01-28 23:19:57 +0800942 INGENIC_PIN_GROUP("nemc-cs1", jz4770_nemc_cs1),
943 INGENIC_PIN_GROUP("nemc-cs2", jz4770_nemc_cs2),
944 INGENIC_PIN_GROUP("nemc-cs3", jz4770_nemc_cs3),
945 INGENIC_PIN_GROUP("nemc-cs4", jz4770_nemc_cs4),
946 INGENIC_PIN_GROUP("nemc-cs5", jz4770_nemc_cs5),
947 INGENIC_PIN_GROUP("nemc-cs6", jz4770_nemc_cs6),
948 INGENIC_PIN_GROUP("i2c0-data", jz4770_i2c0),
949 INGENIC_PIN_GROUP("i2c1-data", jz4770_i2c1),
950 INGENIC_PIN_GROUP("i2c2-data", jz4770_i2c2),
951 INGENIC_PIN_GROUP("i2c3-data", jz4780_i2c3),
952 INGENIC_PIN_GROUP("i2c4-data-e", jz4780_i2c4_e),
953 INGENIC_PIN_GROUP("i2c4-data-f", jz4780_i2c4_f),
954 INGENIC_PIN_GROUP("cim-data", jz4770_cim_8bit),
955 INGENIC_PIN_GROUP("lcd-24bit", jz4770_lcd_24bit),
956 { "lcd-no-pins", },
957 INGENIC_PIN_GROUP("pwm0", jz4770_pwm_pwm0),
958 INGENIC_PIN_GROUP("pwm1", jz4770_pwm_pwm1),
959 INGENIC_PIN_GROUP("pwm2", jz4770_pwm_pwm2),
960 INGENIC_PIN_GROUP("pwm3", jz4770_pwm_pwm3),
961 INGENIC_PIN_GROUP("pwm4", jz4770_pwm_pwm4),
962 INGENIC_PIN_GROUP("pwm5", jz4770_pwm_pwm5),
963 INGENIC_PIN_GROUP("pwm6", jz4770_pwm_pwm6),
964 INGENIC_PIN_GROUP("pwm7", jz4770_pwm_pwm7),
965};
966
967static const char *jz4780_uart2_groups[] = { "uart2-data", "uart2-hwflow", };
968static const char *jz4780_uart4_groups[] = { "uart4-data", };
969static const char *jz4780_mmc0_groups[] = {
970 "mmc0-1bit-a", "mmc0-4bit-a", "mmc0-8bit-a",
971 "mmc0-1bit-e", "mmc0-4bit-e",
972};
973static const char *jz4780_mmc1_groups[] = {
974 "mmc1-1bit-d", "mmc1-4bit-d", "mmc1-1bit-e", "mmc1-4bit-e",
975};
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800976static const char *jz4780_mmc2_groups[] = {
977 "mmc2-1bit-b", "mmc2-4bit-b", "mmc2-1bit-e", "mmc2-4bit-e",
978};
Zhou Yanjieff656e42019-01-28 23:19:57 +0800979static const char *jz4780_nemc_groups[] = {
980 "nemc-data", "nemc-cle-ale", "nemc-addr",
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800981 "nemc-rd-we", "nemc-frd-fwe", "nemc-wait",
Zhou Yanjieff656e42019-01-28 23:19:57 +0800982};
983static const char *jz4780_i2c3_groups[] = { "i2c3-data", };
984static const char *jz4780_i2c4_groups[] = { "i2c4-data-e", "i2c4-data-f", };
985static const char *jz4780_cim_groups[] = { "cim-data", };
986
987static const struct function_desc jz4780_functions[] = {
988 { "uart0", jz4770_uart0_groups, ARRAY_SIZE(jz4770_uart0_groups), },
989 { "uart1", jz4770_uart1_groups, ARRAY_SIZE(jz4770_uart1_groups), },
990 { "uart2", jz4780_uart2_groups, ARRAY_SIZE(jz4780_uart2_groups), },
991 { "uart3", jz4770_uart3_groups, ARRAY_SIZE(jz4770_uart3_groups), },
992 { "uart4", jz4780_uart4_groups, ARRAY_SIZE(jz4780_uart4_groups), },
993 { "mmc0", jz4780_mmc0_groups, ARRAY_SIZE(jz4780_mmc0_groups), },
994 { "mmc1", jz4780_mmc1_groups, ARRAY_SIZE(jz4780_mmc1_groups), },
Zhou Yanjie5de1a732019-01-28 23:19:58 +0800995 { "mmc2", jz4780_mmc2_groups, ARRAY_SIZE(jz4780_mmc2_groups), },
Zhou Yanjieff656e42019-01-28 23:19:57 +0800996 { "nemc", jz4780_nemc_groups, ARRAY_SIZE(jz4780_nemc_groups), },
997 { "nemc-cs1", jz4770_cs1_groups, ARRAY_SIZE(jz4770_cs1_groups), },
998 { "nemc-cs2", jz4770_cs2_groups, ARRAY_SIZE(jz4770_cs2_groups), },
999 { "nemc-cs3", jz4770_cs3_groups, ARRAY_SIZE(jz4770_cs3_groups), },
1000 { "nemc-cs4", jz4770_cs4_groups, ARRAY_SIZE(jz4770_cs4_groups), },
1001 { "nemc-cs5", jz4770_cs5_groups, ARRAY_SIZE(jz4770_cs5_groups), },
1002 { "nemc-cs6", jz4770_cs6_groups, ARRAY_SIZE(jz4770_cs6_groups), },
1003 { "i2c0", jz4770_i2c0_groups, ARRAY_SIZE(jz4770_i2c0_groups), },
1004 { "i2c1", jz4770_i2c1_groups, ARRAY_SIZE(jz4770_i2c1_groups), },
1005 { "i2c2", jz4770_i2c2_groups, ARRAY_SIZE(jz4770_i2c2_groups), },
1006 { "i2c3", jz4780_i2c3_groups, ARRAY_SIZE(jz4780_i2c3_groups), },
1007 { "i2c4", jz4780_i2c4_groups, ARRAY_SIZE(jz4780_i2c4_groups), },
1008 { "cim", jz4780_cim_groups, ARRAY_SIZE(jz4780_cim_groups), },
1009 { "lcd", jz4770_lcd_groups, ARRAY_SIZE(jz4770_lcd_groups), },
1010 { "pwm0", jz4770_pwm0_groups, ARRAY_SIZE(jz4770_pwm0_groups), },
1011 { "pwm1", jz4770_pwm1_groups, ARRAY_SIZE(jz4770_pwm1_groups), },
1012 { "pwm2", jz4770_pwm2_groups, ARRAY_SIZE(jz4770_pwm2_groups), },
1013 { "pwm3", jz4770_pwm3_groups, ARRAY_SIZE(jz4770_pwm3_groups), },
1014 { "pwm4", jz4770_pwm4_groups, ARRAY_SIZE(jz4770_pwm4_groups), },
1015 { "pwm5", jz4770_pwm5_groups, ARRAY_SIZE(jz4770_pwm5_groups), },
1016 { "pwm6", jz4770_pwm6_groups, ARRAY_SIZE(jz4770_pwm6_groups), },
1017 { "pwm7", jz4770_pwm7_groups, ARRAY_SIZE(jz4770_pwm7_groups), },
1018};
1019
1020static const struct ingenic_chip_info jz4780_chip_info = {
1021 .num_chips = 6,
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +08001022 .reg_offset = 0x100,
Zhou Yanjieff656e42019-01-28 23:19:57 +08001023 .groups = jz4780_groups,
1024 .num_groups = ARRAY_SIZE(jz4780_groups),
1025 .functions = jz4780_functions,
1026 .num_functions = ARRAY_SIZE(jz4780_functions),
1027 .pull_ups = jz4770_pull_ups,
1028 .pull_downs = jz4770_pull_downs,
1029};
1030
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001031static const u32 x1000_pull_ups[4] = {
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001032 0xffffffff, 0xfdffffff, 0x0dffffff, 0x0000003f,
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001033};
1034
1035static const u32 x1000_pull_downs[4] = {
1036 0x00000000, 0x02000000, 0x02000000, 0x00000000,
1037};
1038
1039static int x1000_uart0_data_pins[] = { 0x4a, 0x4b, };
1040static int x1000_uart0_hwflow_pins[] = { 0x4c, 0x4d, };
1041static int x1000_uart1_data_a_pins[] = { 0x04, 0x05, };
1042static int x1000_uart1_data_d_pins[] = { 0x62, 0x63, };
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001043static int x1000_uart1_hwflow_pins[] = { 0x64, 0x65, };
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001044static int x1000_uart2_data_a_pins[] = { 0x02, 0x03, };
1045static int x1000_uart2_data_d_pins[] = { 0x65, 0x64, };
周琰杰 (Zhou Yanjie)3b31e9b2019-12-16 00:21:01 +08001046static int x1000_sfc_pins[] = { 0x1d, 0x1c, 0x1e, 0x1f, 0x1a, 0x1b, };
1047static int x1000_ssi_dt_a_22_pins[] = { 0x16, };
1048static int x1000_ssi_dt_a_29_pins[] = { 0x1d, };
1049static int x1000_ssi_dt_d_pins[] = { 0x62, };
1050static int x1000_ssi_dr_a_23_pins[] = { 0x17, };
1051static int x1000_ssi_dr_a_28_pins[] = { 0x1c, };
1052static int x1000_ssi_dr_d_pins[] = { 0x63, };
1053static int x1000_ssi_clk_a_24_pins[] = { 0x18, };
1054static int x1000_ssi_clk_a_26_pins[] = { 0x1a, };
1055static int x1000_ssi_clk_d_pins[] = { 0x60, };
1056static int x1000_ssi_gpc_a_20_pins[] = { 0x14, };
1057static int x1000_ssi_gpc_a_31_pins[] = { 0x1f, };
1058static int x1000_ssi_ce0_a_25_pins[] = { 0x19, };
1059static int x1000_ssi_ce0_a_27_pins[] = { 0x1b, };
1060static int x1000_ssi_ce0_d_pins[] = { 0x61, };
1061static int x1000_ssi_ce1_a_21_pins[] = { 0x15, };
1062static int x1000_ssi_ce1_a_30_pins[] = { 0x1e, };
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001063static int x1000_mmc0_1bit_pins[] = { 0x18, 0x19, 0x17, };
1064static int x1000_mmc0_4bit_pins[] = { 0x16, 0x15, 0x14, };
1065static int x1000_mmc0_8bit_pins[] = { 0x13, 0x12, 0x11, 0x10, };
1066static int x1000_mmc1_1bit_pins[] = { 0x40, 0x41, 0x42, };
1067static int x1000_mmc1_4bit_pins[] = { 0x43, 0x44, 0x45, };
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001068static int x1000_emc_8bit_data_pins[] = {
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001069 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1070};
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001071static int x1000_emc_16bit_data_pins[] = {
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001072 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1073};
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001074static int x1000_emc_addr_pins[] = {
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001075 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
1076 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
1077};
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001078static int x1000_emc_rd_we_pins[] = { 0x30, 0x31, };
1079static int x1000_emc_wait_pins[] = { 0x34, };
1080static int x1000_emc_cs1_pins[] = { 0x32, };
1081static int x1000_emc_cs2_pins[] = { 0x33, };
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001082static int x1000_i2c0_pins[] = { 0x38, 0x37, };
1083static int x1000_i2c1_a_pins[] = { 0x01, 0x00, };
1084static int x1000_i2c1_c_pins[] = { 0x5b, 0x5a, };
1085static int x1000_i2c2_pins[] = { 0x61, 0x60, };
1086static int x1000_cim_pins[] = {
1087 0x08, 0x09, 0x0a, 0x0b,
1088 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0c,
1089};
1090static int x1000_lcd_8bit_pins[] = {
1091 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1092 0x30, 0x31, 0x32, 0x33, 0x34,
1093};
1094static int x1000_lcd_16bit_pins[] = {
1095 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1096};
1097static int x1000_pwm_pwm0_pins[] = { 0x59, };
1098static int x1000_pwm_pwm1_pins[] = { 0x5a, };
1099static int x1000_pwm_pwm2_pins[] = { 0x5b, };
1100static int x1000_pwm_pwm3_pins[] = { 0x26, };
1101static int x1000_pwm_pwm4_pins[] = { 0x58, };
1102static int x1000_mac_pins[] = {
1103 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x26,
1104};
1105
1106static int x1000_uart0_data_funcs[] = { 0, 0, };
1107static int x1000_uart0_hwflow_funcs[] = { 0, 0, };
1108static int x1000_uart1_data_a_funcs[] = { 2, 2, };
1109static int x1000_uart1_data_d_funcs[] = { 1, 1, };
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001110static int x1000_uart1_hwflow_funcs[] = { 1, 1, };
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001111static int x1000_uart2_data_a_funcs[] = { 2, 2, };
1112static int x1000_uart2_data_d_funcs[] = { 0, 0, };
周琰杰 (Zhou Yanjie)3b31e9b2019-12-16 00:21:01 +08001113static int x1000_sfc_funcs[] = { 1, 1, 1, 1, 1, 1, };
1114static int x1000_ssi_dt_a_22_funcs[] = { 2, };
1115static int x1000_ssi_dt_a_29_funcs[] = { 2, };
1116static int x1000_ssi_dt_d_funcs[] = { 0, };
1117static int x1000_ssi_dr_a_23_funcs[] = { 2, };
1118static int x1000_ssi_dr_a_28_funcs[] = { 2, };
1119static int x1000_ssi_dr_d_funcs[] = { 0, };
1120static int x1000_ssi_clk_a_24_funcs[] = { 2, };
1121static int x1000_ssi_clk_a_26_funcs[] = { 2, };
1122static int x1000_ssi_clk_d_funcs[] = { 0, };
1123static int x1000_ssi_gpc_a_20_funcs[] = { 2, };
1124static int x1000_ssi_gpc_a_31_funcs[] = { 2, };
1125static int x1000_ssi_ce0_a_25_funcs[] = { 2, };
1126static int x1000_ssi_ce0_a_27_funcs[] = { 2, };
1127static int x1000_ssi_ce0_d_funcs[] = { 0, };
1128static int x1000_ssi_ce1_a_21_funcs[] = { 2, };
1129static int x1000_ssi_ce1_a_30_funcs[] = { 2, };
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001130static int x1000_mmc0_1bit_funcs[] = { 1, 1, 1, };
1131static int x1000_mmc0_4bit_funcs[] = { 1, 1, 1, };
1132static int x1000_mmc0_8bit_funcs[] = { 1, 1, 1, 1, 1, };
1133static int x1000_mmc1_1bit_funcs[] = { 0, 0, 0, };
1134static int x1000_mmc1_4bit_funcs[] = { 0, 0, 0, };
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001135static int x1000_emc_8bit_data_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, };
1136static int x1000_emc_16bit_data_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, };
1137static int x1000_emc_addr_funcs[] = {
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001138 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1139};
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001140static int x1000_emc_rd_we_funcs[] = { 0, 0, };
1141static int x1000_emc_wait_funcs[] = { 0, };
1142static int x1000_emc_cs1_funcs[] = { 0, };
1143static int x1000_emc_cs2_funcs[] = { 0, };
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001144static int x1000_i2c0_funcs[] = { 0, 0, };
1145static int x1000_i2c1_a_funcs[] = { 2, 2, };
1146static int x1000_i2c1_c_funcs[] = { 0, 0, };
1147static int x1000_i2c2_funcs[] = { 1, 1, };
1148static int x1000_cim_funcs[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, };
1149static int x1000_lcd_8bit_funcs[] = {
1150 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1151};
1152static int x1000_lcd_16bit_funcs[] = { 1, 1, 1, 1, 1, 1, 1, 1, };
1153static int x1000_pwm_pwm0_funcs[] = { 0, };
1154static int x1000_pwm_pwm1_funcs[] = { 1, };
1155static int x1000_pwm_pwm2_funcs[] = { 1, };
1156static int x1000_pwm_pwm3_funcs[] = { 2, };
1157static int x1000_pwm_pwm4_funcs[] = { 0, };
1158static int x1000_mac_funcs[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, };
1159
1160static const struct group_desc x1000_groups[] = {
1161 INGENIC_PIN_GROUP("uart0-data", x1000_uart0_data),
1162 INGENIC_PIN_GROUP("uart0-hwflow", x1000_uart0_hwflow),
1163 INGENIC_PIN_GROUP("uart1-data-a", x1000_uart1_data_a),
1164 INGENIC_PIN_GROUP("uart1-data-d", x1000_uart1_data_d),
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001165 INGENIC_PIN_GROUP("uart1-hwflow", x1000_uart1_hwflow),
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001166 INGENIC_PIN_GROUP("uart2-data-a", x1000_uart2_data_a),
1167 INGENIC_PIN_GROUP("uart2-data-d", x1000_uart2_data_d),
周琰杰 (Zhou Yanjie)3b31e9b2019-12-16 00:21:01 +08001168 INGENIC_PIN_GROUP("sfc", x1000_sfc),
1169 INGENIC_PIN_GROUP("ssi-dt-a-22", x1000_ssi_dt_a_22),
1170 INGENIC_PIN_GROUP("ssi-dt-a-29", x1000_ssi_dt_a_29),
1171 INGENIC_PIN_GROUP("ssi-dt-d", x1000_ssi_dt_d),
1172 INGENIC_PIN_GROUP("ssi-dr-a-23", x1000_ssi_dr_a_23),
1173 INGENIC_PIN_GROUP("ssi-dr-a-28", x1000_ssi_dr_a_28),
1174 INGENIC_PIN_GROUP("ssi-dr-d", x1000_ssi_dr_d),
1175 INGENIC_PIN_GROUP("ssi-clk-a-24", x1000_ssi_clk_a_24),
1176 INGENIC_PIN_GROUP("ssi-clk-a-26", x1000_ssi_clk_a_26),
1177 INGENIC_PIN_GROUP("ssi-clk-d", x1000_ssi_clk_d),
1178 INGENIC_PIN_GROUP("ssi-gpc-a-20", x1000_ssi_gpc_a_20),
1179 INGENIC_PIN_GROUP("ssi-gpc-a-31", x1000_ssi_gpc_a_31),
1180 INGENIC_PIN_GROUP("ssi-ce0-a-25", x1000_ssi_ce0_a_25),
1181 INGENIC_PIN_GROUP("ssi-ce0-a-27", x1000_ssi_ce0_a_27),
1182 INGENIC_PIN_GROUP("ssi-ce0-d", x1000_ssi_ce0_d),
1183 INGENIC_PIN_GROUP("ssi-ce1-a-21", x1000_ssi_ce1_a_21),
1184 INGENIC_PIN_GROUP("ssi-ce1-a-30", x1000_ssi_ce1_a_30),
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001185 INGENIC_PIN_GROUP("mmc0-1bit", x1000_mmc0_1bit),
1186 INGENIC_PIN_GROUP("mmc0-4bit", x1000_mmc0_4bit),
1187 INGENIC_PIN_GROUP("mmc0-8bit", x1000_mmc0_8bit),
1188 INGENIC_PIN_GROUP("mmc1-1bit", x1000_mmc1_1bit),
1189 INGENIC_PIN_GROUP("mmc1-4bit", x1000_mmc1_4bit),
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001190 INGENIC_PIN_GROUP("emc-8bit-data", x1000_emc_8bit_data),
1191 INGENIC_PIN_GROUP("emc-16bit-data", x1000_emc_16bit_data),
1192 INGENIC_PIN_GROUP("emc-addr", x1000_emc_addr),
1193 INGENIC_PIN_GROUP("emc-rd-we", x1000_emc_rd_we),
1194 INGENIC_PIN_GROUP("emc-wait", x1000_emc_wait),
1195 INGENIC_PIN_GROUP("emc-cs1", x1000_emc_cs1),
1196 INGENIC_PIN_GROUP("emc-cs2", x1000_emc_cs2),
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001197 INGENIC_PIN_GROUP("i2c0-data", x1000_i2c0),
1198 INGENIC_PIN_GROUP("i2c1-data-a", x1000_i2c1_a),
1199 INGENIC_PIN_GROUP("i2c1-data-c", x1000_i2c1_c),
1200 INGENIC_PIN_GROUP("i2c2-data", x1000_i2c2),
1201 INGENIC_PIN_GROUP("cim-data", x1000_cim),
1202 INGENIC_PIN_GROUP("lcd-8bit", x1000_lcd_8bit),
1203 INGENIC_PIN_GROUP("lcd-16bit", x1000_lcd_16bit),
1204 { "lcd-no-pins", },
1205 INGENIC_PIN_GROUP("pwm0", x1000_pwm_pwm0),
1206 INGENIC_PIN_GROUP("pwm1", x1000_pwm_pwm1),
1207 INGENIC_PIN_GROUP("pwm2", x1000_pwm_pwm2),
1208 INGENIC_PIN_GROUP("pwm3", x1000_pwm_pwm3),
1209 INGENIC_PIN_GROUP("pwm4", x1000_pwm_pwm4),
1210 INGENIC_PIN_GROUP("mac", x1000_mac),
1211};
1212
1213static const char *x1000_uart0_groups[] = { "uart0-data", "uart0-hwflow", };
1214static const char *x1000_uart1_groups[] = {
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001215 "uart1-data-a", "uart1-data-d", "uart1-hwflow",
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001216};
1217static const char *x1000_uart2_groups[] = { "uart2-data-a", "uart2-data-d", };
周琰杰 (Zhou Yanjie)3b31e9b2019-12-16 00:21:01 +08001218static const char *x1000_sfc_groups[] = { "sfc", };
1219static const char *x1000_ssi_groups[] = {
1220 "ssi-dt-a-22", "ssi-dt-a-29", "ssi-dt-d",
1221 "ssi-dr-a-23", "ssi-dr-a-28", "ssi-dr-d",
1222 "ssi-clk-a-24", "ssi-clk-a-26", "ssi-clk-d",
1223 "ssi-gpc-a-20", "ssi-gpc-a-31",
1224 "ssi-ce0-a-25", "ssi-ce0-a-27", "ssi-ce0-d",
1225 "ssi-ce1-a-21", "ssi-ce1-a-30",
1226};
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001227static const char *x1000_mmc0_groups[] = {
1228 "mmc0-1bit", "mmc0-4bit", "mmc0-8bit",
1229};
1230static const char *x1000_mmc1_groups[] = {
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001231 "mmc1-1bit", "mmc1-4bit",
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001232};
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001233static const char *x1000_emc_groups[] = {
1234 "emc-8bit-data", "emc-16bit-data",
1235 "emc-addr", "emc-rd-we", "emc-wait",
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001236};
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001237static const char *x1000_cs1_groups[] = { "emc-cs1", };
1238static const char *x1000_cs2_groups[] = { "emc-cs2", };
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001239static const char *x1000_i2c0_groups[] = { "i2c0-data", };
1240static const char *x1000_i2c1_groups[] = { "i2c1-data-a", "i2c1-data-c", };
1241static const char *x1000_i2c2_groups[] = { "i2c2-data", };
1242static const char *x1000_cim_groups[] = { "cim-data", };
1243static const char *x1000_lcd_groups[] = {
1244 "lcd-8bit", "lcd-16bit", "lcd-no-pins",
1245};
1246static const char *x1000_pwm0_groups[] = { "pwm0", };
1247static const char *x1000_pwm1_groups[] = { "pwm1", };
1248static const char *x1000_pwm2_groups[] = { "pwm2", };
1249static const char *x1000_pwm3_groups[] = { "pwm3", };
1250static const char *x1000_pwm4_groups[] = { "pwm4", };
1251static const char *x1000_mac_groups[] = { "mac", };
1252
1253static const struct function_desc x1000_functions[] = {
1254 { "uart0", x1000_uart0_groups, ARRAY_SIZE(x1000_uart0_groups), },
1255 { "uart1", x1000_uart1_groups, ARRAY_SIZE(x1000_uart1_groups), },
1256 { "uart2", x1000_uart2_groups, ARRAY_SIZE(x1000_uart2_groups), },
周琰杰 (Zhou Yanjie)3b31e9b2019-12-16 00:21:01 +08001257 { "sfc", x1000_sfc_groups, ARRAY_SIZE(x1000_sfc_groups), },
1258 { "ssi", x1000_ssi_groups, ARRAY_SIZE(x1000_ssi_groups), },
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001259 { "mmc0", x1000_mmc0_groups, ARRAY_SIZE(x1000_mmc0_groups), },
1260 { "mmc1", x1000_mmc1_groups, ARRAY_SIZE(x1000_mmc1_groups), },
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001261 { "emc", x1000_emc_groups, ARRAY_SIZE(x1000_emc_groups), },
1262 { "emc-cs1", x1000_cs1_groups, ARRAY_SIZE(x1000_cs1_groups), },
1263 { "emc-cs2", x1000_cs2_groups, ARRAY_SIZE(x1000_cs2_groups), },
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001264 { "i2c0", x1000_i2c0_groups, ARRAY_SIZE(x1000_i2c0_groups), },
1265 { "i2c1", x1000_i2c1_groups, ARRAY_SIZE(x1000_i2c1_groups), },
1266 { "i2c2", x1000_i2c2_groups, ARRAY_SIZE(x1000_i2c2_groups), },
1267 { "cim", x1000_cim_groups, ARRAY_SIZE(x1000_cim_groups), },
1268 { "lcd", x1000_lcd_groups, ARRAY_SIZE(x1000_lcd_groups), },
1269 { "pwm0", x1000_pwm0_groups, ARRAY_SIZE(x1000_pwm0_groups), },
1270 { "pwm1", x1000_pwm1_groups, ARRAY_SIZE(x1000_pwm1_groups), },
1271 { "pwm2", x1000_pwm2_groups, ARRAY_SIZE(x1000_pwm2_groups), },
1272 { "pwm3", x1000_pwm3_groups, ARRAY_SIZE(x1000_pwm3_groups), },
1273 { "pwm4", x1000_pwm4_groups, ARRAY_SIZE(x1000_pwm4_groups), },
1274 { "mac", x1000_mac_groups, ARRAY_SIZE(x1000_mac_groups), },
1275};
1276
1277static const struct ingenic_chip_info x1000_chip_info = {
1278 .num_chips = 4,
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +08001279 .reg_offset = 0x100,
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001280 .groups = x1000_groups,
1281 .num_groups = ARRAY_SIZE(x1000_groups),
1282 .functions = x1000_functions,
1283 .num_functions = ARRAY_SIZE(x1000_functions),
1284 .pull_ups = x1000_pull_ups,
1285 .pull_downs = x1000_pull_downs,
1286};
1287
1288static const struct ingenic_chip_info x1000e_chip_info = {
1289 .num_chips = 4,
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +08001290 .reg_offset = 0x100,
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001291 .groups = x1000_groups,
1292 .num_groups = ARRAY_SIZE(x1000_groups),
1293 .functions = x1000_functions,
1294 .num_functions = ARRAY_SIZE(x1000_functions),
1295 .pull_ups = x1000_pull_ups,
1296 .pull_downs = x1000_pull_downs,
1297};
1298
Zhou Yanjie5d215952019-07-14 11:53:56 +08001299static int x1500_uart0_data_pins[] = { 0x4a, 0x4b, };
1300static int x1500_uart0_hwflow_pins[] = { 0x4c, 0x4d, };
1301static int x1500_uart1_data_a_pins[] = { 0x04, 0x05, };
1302static int x1500_uart1_data_d_pins[] = { 0x62, 0x63, };
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001303static int x1500_uart1_hwflow_pins[] = { 0x64, 0x65, };
Zhou Yanjie5d215952019-07-14 11:53:56 +08001304static int x1500_uart2_data_a_pins[] = { 0x02, 0x03, };
1305static int x1500_uart2_data_d_pins[] = { 0x65, 0x64, };
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001306static int x1500_mmc_1bit_pins[] = { 0x18, 0x19, 0x17, };
1307static int x1500_mmc_4bit_pins[] = { 0x16, 0x15, 0x14, };
Zhou Yanjie5d215952019-07-14 11:53:56 +08001308static int x1500_i2c0_pins[] = { 0x38, 0x37, };
1309static int x1500_i2c1_a_pins[] = { 0x01, 0x00, };
1310static int x1500_i2c1_c_pins[] = { 0x5b, 0x5a, };
1311static int x1500_i2c2_pins[] = { 0x61, 0x60, };
1312static int x1500_cim_pins[] = {
1313 0x08, 0x09, 0x0a, 0x0b,
1314 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0c,
1315};
1316static int x1500_pwm_pwm0_pins[] = { 0x59, };
1317static int x1500_pwm_pwm1_pins[] = { 0x5a, };
1318static int x1500_pwm_pwm2_pins[] = { 0x5b, };
1319static int x1500_pwm_pwm3_pins[] = { 0x26, };
1320static int x1500_pwm_pwm4_pins[] = { 0x58, };
1321
1322static int x1500_uart0_data_funcs[] = { 0, 0, };
1323static int x1500_uart0_hwflow_funcs[] = { 0, 0, };
1324static int x1500_uart1_data_a_funcs[] = { 2, 2, };
1325static int x1500_uart1_data_d_funcs[] = { 1, 1, };
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001326static int x1500_uart1_hwflow_funcs[] = { 1, 1, };
Zhou Yanjie5d215952019-07-14 11:53:56 +08001327static int x1500_uart2_data_a_funcs[] = { 2, 2, };
1328static int x1500_uart2_data_d_funcs[] = { 0, 0, };
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001329static int x1500_mmc_1bit_funcs[] = { 1, 1, 1, };
1330static int x1500_mmc_4bit_funcs[] = { 1, 1, 1, };
Zhou Yanjie5d215952019-07-14 11:53:56 +08001331static int x1500_i2c0_funcs[] = { 0, 0, };
1332static int x1500_i2c1_a_funcs[] = { 2, 2, };
1333static int x1500_i2c1_c_funcs[] = { 0, 0, };
1334static int x1500_i2c2_funcs[] = { 1, 1, };
1335static int x1500_cim_funcs[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, };
1336static int x1500_pwm_pwm0_funcs[] = { 0, };
1337static int x1500_pwm_pwm1_funcs[] = { 1, };
1338static int x1500_pwm_pwm2_funcs[] = { 1, };
1339static int x1500_pwm_pwm3_funcs[] = { 2, };
1340static int x1500_pwm_pwm4_funcs[] = { 0, };
1341
1342static const struct group_desc x1500_groups[] = {
1343 INGENIC_PIN_GROUP("uart0-data", x1500_uart0_data),
1344 INGENIC_PIN_GROUP("uart0-hwflow", x1500_uart0_hwflow),
1345 INGENIC_PIN_GROUP("uart1-data-a", x1500_uart1_data_a),
1346 INGENIC_PIN_GROUP("uart1-data-d", x1500_uart1_data_d),
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001347 INGENIC_PIN_GROUP("uart1-hwflow", x1500_uart1_hwflow),
Zhou Yanjie5d215952019-07-14 11:53:56 +08001348 INGENIC_PIN_GROUP("uart2-data-a", x1500_uart2_data_a),
1349 INGENIC_PIN_GROUP("uart2-data-d", x1500_uart2_data_d),
周琰杰 (Zhou Yanjie)3b31e9b2019-12-16 00:21:01 +08001350 INGENIC_PIN_GROUP("sfc", x1000_sfc),
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001351 INGENIC_PIN_GROUP("mmc-1bit", x1500_mmc_1bit),
1352 INGENIC_PIN_GROUP("mmc-4bit", x1500_mmc_4bit),
Zhou Yanjie5d215952019-07-14 11:53:56 +08001353 INGENIC_PIN_GROUP("i2c0-data", x1500_i2c0),
1354 INGENIC_PIN_GROUP("i2c1-data-a", x1500_i2c1_a),
1355 INGENIC_PIN_GROUP("i2c1-data-c", x1500_i2c1_c),
1356 INGENIC_PIN_GROUP("i2c2-data", x1500_i2c2),
1357 INGENIC_PIN_GROUP("cim-data", x1500_cim),
1358 { "lcd-no-pins", },
1359 INGENIC_PIN_GROUP("pwm0", x1500_pwm_pwm0),
1360 INGENIC_PIN_GROUP("pwm1", x1500_pwm_pwm1),
1361 INGENIC_PIN_GROUP("pwm2", x1500_pwm_pwm2),
1362 INGENIC_PIN_GROUP("pwm3", x1500_pwm_pwm3),
1363 INGENIC_PIN_GROUP("pwm4", x1500_pwm_pwm4),
1364};
1365
1366static const char *x1500_uart0_groups[] = { "uart0-data", "uart0-hwflow", };
1367static const char *x1500_uart1_groups[] = {
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001368 "uart1-data-a", "uart1-data-d", "uart1-hwflow",
Zhou Yanjie5d215952019-07-14 11:53:56 +08001369};
1370static const char *x1500_uart2_groups[] = { "uart2-data-a", "uart2-data-d", };
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001371static const char *x1500_mmc_groups[] = { "mmc-1bit", "mmc-4bit", };
Zhou Yanjie5d215952019-07-14 11:53:56 +08001372static const char *x1500_i2c0_groups[] = { "i2c0-data", };
1373static const char *x1500_i2c1_groups[] = { "i2c1-data-a", "i2c1-data-c", };
1374static const char *x1500_i2c2_groups[] = { "i2c2-data", };
1375static const char *x1500_cim_groups[] = { "cim-data", };
1376static const char *x1500_lcd_groups[] = { "lcd-no-pins", };
1377static const char *x1500_pwm0_groups[] = { "pwm0", };
1378static const char *x1500_pwm1_groups[] = { "pwm1", };
1379static const char *x1500_pwm2_groups[] = { "pwm2", };
1380static const char *x1500_pwm3_groups[] = { "pwm3", };
1381static const char *x1500_pwm4_groups[] = { "pwm4", };
1382
1383static const struct function_desc x1500_functions[] = {
1384 { "uart0", x1500_uart0_groups, ARRAY_SIZE(x1500_uart0_groups), },
1385 { "uart1", x1500_uart1_groups, ARRAY_SIZE(x1500_uart1_groups), },
1386 { "uart2", x1500_uart2_groups, ARRAY_SIZE(x1500_uart2_groups), },
周琰杰 (Zhou Yanjie)3b31e9b2019-12-16 00:21:01 +08001387 { "sfc", x1000_sfc_groups, ARRAY_SIZE(x1000_sfc_groups), },
周琰杰 (Zhou Yanjie)b4a93722019-12-16 00:21:00 +08001388 { "mmc", x1500_mmc_groups, ARRAY_SIZE(x1500_mmc_groups), },
Zhou Yanjie5d215952019-07-14 11:53:56 +08001389 { "i2c0", x1500_i2c0_groups, ARRAY_SIZE(x1500_i2c0_groups), },
1390 { "i2c1", x1500_i2c1_groups, ARRAY_SIZE(x1500_i2c1_groups), },
1391 { "i2c2", x1500_i2c2_groups, ARRAY_SIZE(x1500_i2c2_groups), },
1392 { "cim", x1500_cim_groups, ARRAY_SIZE(x1500_cim_groups), },
1393 { "lcd", x1500_lcd_groups, ARRAY_SIZE(x1500_lcd_groups), },
1394 { "pwm0", x1500_pwm0_groups, ARRAY_SIZE(x1500_pwm0_groups), },
1395 { "pwm1", x1500_pwm1_groups, ARRAY_SIZE(x1500_pwm1_groups), },
1396 { "pwm2", x1500_pwm2_groups, ARRAY_SIZE(x1500_pwm2_groups), },
1397 { "pwm3", x1500_pwm3_groups, ARRAY_SIZE(x1500_pwm3_groups), },
1398 { "pwm4", x1500_pwm4_groups, ARRAY_SIZE(x1500_pwm4_groups), },
1399};
1400
1401static const struct ingenic_chip_info x1500_chip_info = {
1402 .num_chips = 4,
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +08001403 .reg_offset = 0x100,
Zhou Yanjie5d215952019-07-14 11:53:56 +08001404 .groups = x1500_groups,
1405 .num_groups = ARRAY_SIZE(x1500_groups),
1406 .functions = x1500_functions,
1407 .num_functions = ARRAY_SIZE(x1500_functions),
1408 .pull_ups = x1000_pull_ups,
1409 .pull_downs = x1000_pull_downs,
1410};
1411
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001412static u32 ingenic_gpio_read_reg(struct ingenic_gpio_chip *jzgc, u8 reg)
Paul Cercueile72394e2018-08-21 18:42:32 +02001413{
1414 unsigned int val;
1415
1416 regmap_read(jzgc->jzpc->map, jzgc->reg_base + reg, &val);
1417
1418 return (u32) val;
1419}
1420
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001421static void ingenic_gpio_set_bit(struct ingenic_gpio_chip *jzgc,
Paul Cercueile72394e2018-08-21 18:42:32 +02001422 u8 reg, u8 offset, bool set)
1423{
1424 if (set)
1425 reg = REG_SET(reg);
1426 else
1427 reg = REG_CLEAR(reg);
1428
1429 regmap_write(jzgc->jzpc->map, jzgc->reg_base + reg, BIT(offset));
1430}
1431
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001432static void ingenic_gpio_shadow_set_bit(struct ingenic_gpio_chip *jzgc,
1433 u8 reg, u8 offset, bool set)
1434{
1435 if (set)
1436 reg = REG_SET(reg);
1437 else
1438 reg = REG_CLEAR(reg);
1439
1440 regmap_write(jzgc->jzpc->map, X1000_GPIO_PZ_BASE + reg, BIT(offset));
1441}
1442
1443static void ingenic_gpio_shadow_set_bit_load(struct ingenic_gpio_chip *jzgc)
1444{
1445 regmap_write(jzgc->jzpc->map, X1000_GPIO_PZ_GID2LD,
1446 jzgc->gc.base / PINS_PER_GPIO_CHIP);
1447}
1448
Paul Cercueile72394e2018-08-21 18:42:32 +02001449static inline bool ingenic_gpio_get_value(struct ingenic_gpio_chip *jzgc,
1450 u8 offset)
1451{
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001452 unsigned int val = ingenic_gpio_read_reg(jzgc, GPIO_PIN);
Paul Cercueile72394e2018-08-21 18:42:32 +02001453
1454 return !!(val & BIT(offset));
1455}
1456
1457static void ingenic_gpio_set_value(struct ingenic_gpio_chip *jzgc,
1458 u8 offset, int value)
1459{
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001460 if (jzgc->jzpc->version >= ID_JZ4760)
1461 ingenic_gpio_set_bit(jzgc, JZ4760_GPIO_PAT0, offset, !!value);
Paul Cercueile72394e2018-08-21 18:42:32 +02001462 else
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001463 ingenic_gpio_set_bit(jzgc, JZ4740_GPIO_DATA, offset, !!value);
Paul Cercueile72394e2018-08-21 18:42:32 +02001464}
1465
1466static void irq_set_type(struct ingenic_gpio_chip *jzgc,
1467 u8 offset, unsigned int type)
1468{
1469 u8 reg1, reg2;
1470
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001471 if (jzgc->jzpc->version >= ID_JZ4760) {
1472 reg1 = JZ4760_GPIO_PAT1;
1473 reg2 = JZ4760_GPIO_PAT0;
Paul Cercueile72394e2018-08-21 18:42:32 +02001474 } else {
1475 reg1 = JZ4740_GPIO_TRIG;
1476 reg2 = JZ4740_GPIO_DIR;
1477 }
1478
1479 switch (type) {
1480 case IRQ_TYPE_EDGE_RISING:
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001481 if (jzgc->jzpc->version >= ID_X1000) {
1482 ingenic_gpio_shadow_set_bit(jzgc, reg2, offset, true);
1483 ingenic_gpio_shadow_set_bit(jzgc, reg1, offset, true);
1484 ingenic_gpio_shadow_set_bit_load(jzgc);
1485 } else {
1486 ingenic_gpio_set_bit(jzgc, reg2, offset, true);
1487 ingenic_gpio_set_bit(jzgc, reg1, offset, true);
1488 }
Paul Cercueile72394e2018-08-21 18:42:32 +02001489 break;
1490 case IRQ_TYPE_EDGE_FALLING:
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001491 if (jzgc->jzpc->version >= ID_X1000) {
1492 ingenic_gpio_shadow_set_bit(jzgc, reg2, offset, false);
1493 ingenic_gpio_shadow_set_bit(jzgc, reg1, offset, true);
1494 ingenic_gpio_shadow_set_bit_load(jzgc);
1495 } else {
1496 ingenic_gpio_set_bit(jzgc, reg2, offset, false);
1497 ingenic_gpio_set_bit(jzgc, reg1, offset, true);
1498 }
Paul Cercueile72394e2018-08-21 18:42:32 +02001499 break;
1500 case IRQ_TYPE_LEVEL_HIGH:
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001501 if (jzgc->jzpc->version >= ID_X1000) {
1502 ingenic_gpio_shadow_set_bit(jzgc, reg2, offset, true);
1503 ingenic_gpio_shadow_set_bit(jzgc, reg1, offset, false);
1504 ingenic_gpio_shadow_set_bit_load(jzgc);
1505 } else {
1506 ingenic_gpio_set_bit(jzgc, reg2, offset, true);
1507 ingenic_gpio_set_bit(jzgc, reg1, offset, false);
1508 }
Paul Cercueile72394e2018-08-21 18:42:32 +02001509 break;
1510 case IRQ_TYPE_LEVEL_LOW:
1511 default:
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001512 if (jzgc->jzpc->version >= ID_X1000) {
1513 ingenic_gpio_shadow_set_bit(jzgc, reg2, offset, false);
1514 ingenic_gpio_shadow_set_bit(jzgc, reg1, offset, false);
1515 ingenic_gpio_shadow_set_bit_load(jzgc);
1516 } else {
1517 ingenic_gpio_set_bit(jzgc, reg2, offset, false);
1518 ingenic_gpio_set_bit(jzgc, reg1, offset, false);
1519 }
Paul Cercueile72394e2018-08-21 18:42:32 +02001520 break;
1521 }
1522}
1523
1524static void ingenic_gpio_irq_mask(struct irq_data *irqd)
1525{
1526 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
1527 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1528
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001529 ingenic_gpio_set_bit(jzgc, GPIO_MSK, irqd->hwirq, true);
Paul Cercueile72394e2018-08-21 18:42:32 +02001530}
1531
1532static void ingenic_gpio_irq_unmask(struct irq_data *irqd)
1533{
1534 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
1535 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1536
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001537 ingenic_gpio_set_bit(jzgc, GPIO_MSK, irqd->hwirq, false);
Paul Cercueile72394e2018-08-21 18:42:32 +02001538}
1539
1540static void ingenic_gpio_irq_enable(struct irq_data *irqd)
1541{
1542 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
1543 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1544 int irq = irqd->hwirq;
1545
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001546 if (jzgc->jzpc->version >= ID_JZ4760)
1547 ingenic_gpio_set_bit(jzgc, JZ4760_GPIO_INT, irq, true);
Paul Cercueile72394e2018-08-21 18:42:32 +02001548 else
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001549 ingenic_gpio_set_bit(jzgc, JZ4740_GPIO_SELECT, irq, true);
Paul Cercueile72394e2018-08-21 18:42:32 +02001550
1551 ingenic_gpio_irq_unmask(irqd);
1552}
1553
1554static void ingenic_gpio_irq_disable(struct irq_data *irqd)
1555{
1556 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
1557 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1558 int irq = irqd->hwirq;
1559
1560 ingenic_gpio_irq_mask(irqd);
1561
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001562 if (jzgc->jzpc->version >= ID_JZ4760)
1563 ingenic_gpio_set_bit(jzgc, JZ4760_GPIO_INT, irq, false);
Paul Cercueile72394e2018-08-21 18:42:32 +02001564 else
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001565 ingenic_gpio_set_bit(jzgc, JZ4740_GPIO_SELECT, irq, false);
Paul Cercueile72394e2018-08-21 18:42:32 +02001566}
1567
1568static void ingenic_gpio_irq_ack(struct irq_data *irqd)
1569{
1570 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
1571 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1572 int irq = irqd->hwirq;
1573 bool high;
1574
1575 if (irqd_get_trigger_type(irqd) == IRQ_TYPE_EDGE_BOTH) {
1576 /*
1577 * Switch to an interrupt for the opposite edge to the one that
1578 * triggered the interrupt being ACKed.
1579 */
1580 high = ingenic_gpio_get_value(jzgc, irq);
1581 if (high)
1582 irq_set_type(jzgc, irq, IRQ_TYPE_EDGE_FALLING);
1583 else
1584 irq_set_type(jzgc, irq, IRQ_TYPE_EDGE_RISING);
1585 }
1586
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001587 if (jzgc->jzpc->version >= ID_JZ4760)
1588 ingenic_gpio_set_bit(jzgc, JZ4760_GPIO_FLAG, irq, false);
Paul Cercueile72394e2018-08-21 18:42:32 +02001589 else
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001590 ingenic_gpio_set_bit(jzgc, JZ4740_GPIO_DATA, irq, true);
Paul Cercueile72394e2018-08-21 18:42:32 +02001591}
1592
1593static int ingenic_gpio_irq_set_type(struct irq_data *irqd, unsigned int type)
1594{
1595 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
1596 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1597
1598 switch (type) {
1599 case IRQ_TYPE_EDGE_BOTH:
1600 case IRQ_TYPE_EDGE_RISING:
1601 case IRQ_TYPE_EDGE_FALLING:
1602 irq_set_handler_locked(irqd, handle_edge_irq);
1603 break;
1604 case IRQ_TYPE_LEVEL_HIGH:
1605 case IRQ_TYPE_LEVEL_LOW:
1606 irq_set_handler_locked(irqd, handle_level_irq);
1607 break;
1608 default:
1609 irq_set_handler_locked(irqd, handle_bad_irq);
1610 }
1611
1612 if (type == IRQ_TYPE_EDGE_BOTH) {
1613 /*
1614 * The hardware does not support interrupts on both edges. The
1615 * best we can do is to set up a single-edge interrupt and then
1616 * switch to the opposing edge when ACKing the interrupt.
1617 */
1618 bool high = ingenic_gpio_get_value(jzgc, irqd->hwirq);
1619
1620 type = high ? IRQ_TYPE_EDGE_FALLING : IRQ_TYPE_EDGE_RISING;
1621 }
1622
1623 irq_set_type(jzgc, irqd->hwirq, type);
1624 return 0;
1625}
1626
1627static int ingenic_gpio_irq_set_wake(struct irq_data *irqd, unsigned int on)
1628{
1629 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
1630 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1631
1632 return irq_set_irq_wake(jzgc->irq, on);
1633}
1634
1635static void ingenic_gpio_irq_handler(struct irq_desc *desc)
1636{
1637 struct gpio_chip *gc = irq_desc_get_handler_data(desc);
1638 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1639 struct irq_chip *irq_chip = irq_data_get_irq_chip(&desc->irq_data);
1640 unsigned long flag, i;
1641
1642 chained_irq_enter(irq_chip, desc);
1643
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001644 if (jzgc->jzpc->version >= ID_JZ4760)
1645 flag = ingenic_gpio_read_reg(jzgc, JZ4760_GPIO_FLAG);
Paul Cercueile72394e2018-08-21 18:42:32 +02001646 else
Zhou Yanjieb71c1842019-01-28 23:19:59 +08001647 flag = ingenic_gpio_read_reg(jzgc, JZ4740_GPIO_FLAG);
Paul Cercueile72394e2018-08-21 18:42:32 +02001648
1649 for_each_set_bit(i, &flag, 32)
1650 generic_handle_irq(irq_linear_revmap(gc->irq.domain, i));
1651 chained_irq_exit(irq_chip, desc);
1652}
1653
1654static void ingenic_gpio_set(struct gpio_chip *gc,
1655 unsigned int offset, int value)
1656{
1657 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1658
1659 ingenic_gpio_set_value(jzgc, offset, value);
1660}
1661
1662static int ingenic_gpio_get(struct gpio_chip *gc, unsigned int offset)
1663{
1664 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1665
1666 return (int) ingenic_gpio_get_value(jzgc, offset);
1667}
1668
1669static int ingenic_gpio_direction_input(struct gpio_chip *gc,
1670 unsigned int offset)
1671{
1672 return pinctrl_gpio_direction_input(gc->base + offset);
1673}
1674
1675static int ingenic_gpio_direction_output(struct gpio_chip *gc,
1676 unsigned int offset, int value)
1677{
1678 ingenic_gpio_set(gc, offset, value);
1679 return pinctrl_gpio_direction_output(gc->base + offset);
1680}
1681
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001682static inline void ingenic_config_pin(struct ingenic_pinctrl *jzpc,
1683 unsigned int pin, u8 reg, bool set)
1684{
1685 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
1686 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
1687
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +08001688 regmap_write(jzpc->map, offt * jzpc->info->reg_offset +
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001689 (set ? REG_SET(reg) : REG_CLEAR(reg)), BIT(idx));
1690}
1691
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001692static inline void ingenic_shadow_config_pin(struct ingenic_pinctrl *jzpc,
1693 unsigned int pin, u8 reg, bool set)
1694{
1695 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
1696
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +08001697 regmap_write(jzpc->map, REG_PZ_BASE(jzpc->info->reg_offset) +
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001698 (set ? REG_SET(reg) : REG_CLEAR(reg)), BIT(idx));
1699}
1700
1701static inline void ingenic_shadow_config_pin_load(struct ingenic_pinctrl *jzpc,
1702 unsigned int pin)
1703{
1704 regmap_write(jzpc->map, X1000_GPIO_PZ_GID2LD, pin / PINS_PER_GPIO_CHIP);
1705}
1706
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001707static inline bool ingenic_get_pin_config(struct ingenic_pinctrl *jzpc,
1708 unsigned int pin, u8 reg)
1709{
1710 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
1711 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
1712 unsigned int val;
1713
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +08001714 regmap_read(jzpc->map, offt * jzpc->info->reg_offset + reg, &val);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001715
1716 return val & BIT(idx);
1717}
1718
Paul Cercueilebd66512018-08-21 18:42:33 +02001719static int ingenic_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
1720{
1721 struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
1722 struct ingenic_pinctrl *jzpc = jzgc->jzpc;
1723 unsigned int pin = gc->base + offset;
1724
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001725 if (jzpc->version >= ID_JZ4760)
1726 return ingenic_get_pin_config(jzpc, pin, JZ4760_GPIO_PAT1);
Paul Cercueilebd66512018-08-21 18:42:33 +02001727
1728 if (ingenic_get_pin_config(jzpc, pin, JZ4740_GPIO_SELECT))
1729 return true;
1730
1731 return !ingenic_get_pin_config(jzpc, pin, JZ4740_GPIO_DIR);
1732}
1733
Julia Lawall5bf7b842017-08-10 12:06:23 +02001734static const struct pinctrl_ops ingenic_pctlops = {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001735 .get_groups_count = pinctrl_generic_get_group_count,
1736 .get_group_name = pinctrl_generic_get_group_name,
1737 .get_group_pins = pinctrl_generic_get_group_pins,
1738 .dt_node_to_map = pinconf_generic_dt_node_to_map_all,
1739 .dt_free_map = pinconf_generic_dt_free_map,
1740};
1741
1742static int ingenic_pinmux_set_pin_fn(struct ingenic_pinctrl *jzpc,
1743 int pin, int func)
1744{
1745 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
1746 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
1747
1748 dev_dbg(jzpc->dev, "set pin P%c%u to function %u\n",
1749 'A' + offt, idx, func);
1750
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001751 if (jzpc->version >= ID_X1000) {
1752 ingenic_shadow_config_pin(jzpc, pin, JZ4760_GPIO_INT, false);
1753 ingenic_shadow_config_pin(jzpc, pin, GPIO_MSK, false);
1754 ingenic_shadow_config_pin(jzpc, pin, JZ4760_GPIO_PAT1, func & 0x2);
1755 ingenic_shadow_config_pin(jzpc, pin, JZ4760_GPIO_PAT0, func & 0x1);
1756 ingenic_shadow_config_pin_load(jzpc, pin);
1757 } else if (jzpc->version >= ID_JZ4760) {
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001758 ingenic_config_pin(jzpc, pin, JZ4760_GPIO_INT, false);
Paul Cercueile72394e2018-08-21 18:42:32 +02001759 ingenic_config_pin(jzpc, pin, GPIO_MSK, false);
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001760 ingenic_config_pin(jzpc, pin, JZ4760_GPIO_PAT1, func & 0x2);
1761 ingenic_config_pin(jzpc, pin, JZ4760_GPIO_PAT0, func & 0x1);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001762 } else {
1763 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_FUNC, true);
1764 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_TRIG, func & 0x2);
1765 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_SELECT, func > 0);
1766 }
1767
1768 return 0;
1769}
1770
1771static int ingenic_pinmux_set_mux(struct pinctrl_dev *pctldev,
1772 unsigned int selector, unsigned int group)
1773{
1774 struct ingenic_pinctrl *jzpc = pinctrl_dev_get_drvdata(pctldev);
1775 struct function_desc *func;
1776 struct group_desc *grp;
1777 unsigned int i;
1778
1779 func = pinmux_generic_get_function(pctldev, selector);
1780 if (!func)
1781 return -EINVAL;
1782
1783 grp = pinctrl_generic_get_group(pctldev, group);
1784 if (!grp)
1785 return -EINVAL;
1786
1787 dev_dbg(pctldev->dev, "enable function %s group %s\n",
1788 func->name, grp->name);
1789
1790 for (i = 0; i < grp->num_pins; i++) {
1791 int *pin_modes = grp->data;
1792
1793 ingenic_pinmux_set_pin_fn(jzpc, grp->pins[i], pin_modes[i]);
1794 }
1795
1796 return 0;
1797}
1798
1799static int ingenic_pinmux_gpio_set_direction(struct pinctrl_dev *pctldev,
1800 struct pinctrl_gpio_range *range,
1801 unsigned int pin, bool input)
1802{
1803 struct ingenic_pinctrl *jzpc = pinctrl_dev_get_drvdata(pctldev);
1804 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
1805 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
1806
1807 dev_dbg(pctldev->dev, "set pin P%c%u to %sput\n",
1808 'A' + offt, idx, input ? "in" : "out");
1809
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08001810 if (jzpc->version >= ID_X1000) {
1811 ingenic_shadow_config_pin(jzpc, pin, JZ4760_GPIO_INT, false);
1812 ingenic_shadow_config_pin(jzpc, pin, GPIO_MSK, true);
1813 ingenic_shadow_config_pin(jzpc, pin, JZ4760_GPIO_PAT1, input);
1814 ingenic_shadow_config_pin_load(jzpc, pin);
1815 } else if (jzpc->version >= ID_JZ4760) {
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001816 ingenic_config_pin(jzpc, pin, JZ4760_GPIO_INT, false);
Paul Cercueile72394e2018-08-21 18:42:32 +02001817 ingenic_config_pin(jzpc, pin, GPIO_MSK, true);
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001818 ingenic_config_pin(jzpc, pin, JZ4760_GPIO_PAT1, input);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001819 } else {
1820 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_SELECT, false);
Paul Cercueil0084a782018-06-27 13:49:02 +02001821 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_DIR, !input);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001822 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_FUNC, false);
1823 }
1824
1825 return 0;
1826}
1827
Julia Lawall5bf7b842017-08-10 12:06:23 +02001828static const struct pinmux_ops ingenic_pmxops = {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001829 .get_functions_count = pinmux_generic_get_function_count,
1830 .get_function_name = pinmux_generic_get_function_name,
1831 .get_function_groups = pinmux_generic_get_function_groups,
1832 .set_mux = ingenic_pinmux_set_mux,
1833 .gpio_set_direction = ingenic_pinmux_gpio_set_direction,
1834};
1835
1836static int ingenic_pinconf_get(struct pinctrl_dev *pctldev,
1837 unsigned int pin, unsigned long *config)
1838{
1839 struct ingenic_pinctrl *jzpc = pinctrl_dev_get_drvdata(pctldev);
1840 enum pin_config_param param = pinconf_to_config_param(*config);
1841 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
1842 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
1843 bool pull;
1844
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001845 if (jzpc->version >= ID_JZ4760)
1846 pull = !ingenic_get_pin_config(jzpc, pin, JZ4760_GPIO_PEN);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001847 else
1848 pull = !ingenic_get_pin_config(jzpc, pin, JZ4740_GPIO_PULL_DIS);
1849
1850 switch (param) {
1851 case PIN_CONFIG_BIAS_DISABLE:
1852 if (pull)
1853 return -EINVAL;
1854 break;
1855
1856 case PIN_CONFIG_BIAS_PULL_UP:
1857 if (!pull || !(jzpc->info->pull_ups[offt] & BIT(idx)))
1858 return -EINVAL;
1859 break;
1860
1861 case PIN_CONFIG_BIAS_PULL_DOWN:
1862 if (!pull || !(jzpc->info->pull_downs[offt] & BIT(idx)))
1863 return -EINVAL;
1864 break;
1865
1866 default:
1867 return -ENOTSUPP;
1868 }
1869
1870 *config = pinconf_to_config_packed(param, 1);
1871 return 0;
1872}
1873
1874static void ingenic_set_bias(struct ingenic_pinctrl *jzpc,
1875 unsigned int pin, bool enabled)
1876{
Zhou Yanjie0257595a2019-07-14 11:53:52 +08001877 if (jzpc->version >= ID_JZ4760)
1878 ingenic_config_pin(jzpc, pin, JZ4760_GPIO_PEN, !enabled);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001879 else
1880 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_PULL_DIS, !enabled);
1881}
1882
Paul Cercueil7009d042019-11-19 16:52:10 +01001883static void ingenic_set_output_level(struct ingenic_pinctrl *jzpc,
1884 unsigned int pin, bool high)
1885{
Paul Cercueil9e655272019-12-10 17:44:46 +01001886 if (jzpc->version >= ID_JZ4760)
Paul Cercueil7009d042019-11-19 16:52:10 +01001887 ingenic_config_pin(jzpc, pin, JZ4760_GPIO_PAT0, high);
1888 else
1889 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_DATA, high);
1890}
1891
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001892static int ingenic_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
1893 unsigned long *configs, unsigned int num_configs)
1894{
1895 struct ingenic_pinctrl *jzpc = pinctrl_dev_get_drvdata(pctldev);
1896 unsigned int idx = pin % PINS_PER_GPIO_CHIP;
1897 unsigned int offt = pin / PINS_PER_GPIO_CHIP;
Paul Cercueil7009d042019-11-19 16:52:10 +01001898 unsigned int cfg, arg;
1899 int ret;
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001900
1901 for (cfg = 0; cfg < num_configs; cfg++) {
1902 switch (pinconf_to_config_param(configs[cfg])) {
1903 case PIN_CONFIG_BIAS_DISABLE:
1904 case PIN_CONFIG_BIAS_PULL_UP:
1905 case PIN_CONFIG_BIAS_PULL_DOWN:
Paul Cercueil7009d042019-11-19 16:52:10 +01001906 case PIN_CONFIG_OUTPUT:
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001907 continue;
1908 default:
1909 return -ENOTSUPP;
1910 }
1911 }
1912
1913 for (cfg = 0; cfg < num_configs; cfg++) {
Paul Cercueil7009d042019-11-19 16:52:10 +01001914 arg = pinconf_to_config_argument(configs[cfg]);
1915
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001916 switch (pinconf_to_config_param(configs[cfg])) {
1917 case PIN_CONFIG_BIAS_DISABLE:
1918 dev_dbg(jzpc->dev, "disable pull-over for pin P%c%u\n",
1919 'A' + offt, idx);
1920 ingenic_set_bias(jzpc, pin, false);
1921 break;
1922
1923 case PIN_CONFIG_BIAS_PULL_UP:
1924 if (!(jzpc->info->pull_ups[offt] & BIT(idx)))
1925 return -EINVAL;
1926 dev_dbg(jzpc->dev, "set pull-up for pin P%c%u\n",
1927 'A' + offt, idx);
1928 ingenic_set_bias(jzpc, pin, true);
1929 break;
1930
1931 case PIN_CONFIG_BIAS_PULL_DOWN:
1932 if (!(jzpc->info->pull_downs[offt] & BIT(idx)))
1933 return -EINVAL;
1934 dev_dbg(jzpc->dev, "set pull-down for pin P%c%u\n",
1935 'A' + offt, idx);
1936 ingenic_set_bias(jzpc, pin, true);
1937 break;
1938
Paul Cercueil7009d042019-11-19 16:52:10 +01001939 case PIN_CONFIG_OUTPUT:
1940 ret = pinctrl_gpio_direction_output(pin);
1941 if (ret)
1942 return ret;
1943
1944 ingenic_set_output_level(jzpc, pin, arg);
1945 break;
1946
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02001947 default:
1948 unreachable();
1949 }
1950 }
1951
1952 return 0;
1953}
1954
1955static int ingenic_pinconf_group_get(struct pinctrl_dev *pctldev,
1956 unsigned int group, unsigned long *config)
1957{
1958 const unsigned int *pins;
1959 unsigned int i, npins, old = 0;
1960 int ret;
1961
1962 ret = pinctrl_generic_get_group_pins(pctldev, group, &pins, &npins);
1963 if (ret)
1964 return ret;
1965
1966 for (i = 0; i < npins; i++) {
1967 if (ingenic_pinconf_get(pctldev, pins[i], config))
1968 return -ENOTSUPP;
1969
1970 /* configs do not match between two pins */
1971 if (i && (old != *config))
1972 return -ENOTSUPP;
1973
1974 old = *config;
1975 }
1976
1977 return 0;
1978}
1979
1980static int ingenic_pinconf_group_set(struct pinctrl_dev *pctldev,
1981 unsigned int group, unsigned long *configs,
1982 unsigned int num_configs)
1983{
1984 const unsigned int *pins;
1985 unsigned int i, npins;
1986 int ret;
1987
1988 ret = pinctrl_generic_get_group_pins(pctldev, group, &pins, &npins);
1989 if (ret)
1990 return ret;
1991
1992 for (i = 0; i < npins; i++) {
1993 ret = ingenic_pinconf_set(pctldev,
1994 pins[i], configs, num_configs);
1995 if (ret)
1996 return ret;
1997 }
1998
1999 return 0;
2000}
2001
Julia Lawall5bf7b842017-08-10 12:06:23 +02002002static const struct pinconf_ops ingenic_confops = {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002003 .is_generic = true,
2004 .pin_config_get = ingenic_pinconf_get,
2005 .pin_config_set = ingenic_pinconf_set,
2006 .pin_config_group_get = ingenic_pinconf_group_get,
2007 .pin_config_group_set = ingenic_pinconf_group_set,
2008};
2009
2010static const struct regmap_config ingenic_pinctrl_regmap_config = {
2011 .reg_bits = 32,
2012 .val_bits = 32,
2013 .reg_stride = 4,
2014};
2015
2016static const struct of_device_id ingenic_pinctrl_of_match[] = {
2017 { .compatible = "ingenic,jz4740-pinctrl", .data = (void *) ID_JZ4740 },
Paul Cercueilf2a96762018-08-21 18:42:34 +02002018 { .compatible = "ingenic,jz4725b-pinctrl", .data = (void *)ID_JZ4725B },
Zhou Yanjie0257595a2019-07-14 11:53:52 +08002019 { .compatible = "ingenic,jz4760-pinctrl", .data = (void *) ID_JZ4760 },
2020 { .compatible = "ingenic,jz4760b-pinctrl", .data = (void *) ID_JZ4760B },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002021 { .compatible = "ingenic,jz4770-pinctrl", .data = (void *) ID_JZ4770 },
2022 { .compatible = "ingenic,jz4780-pinctrl", .data = (void *) ID_JZ4780 },
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08002023 { .compatible = "ingenic,x1000-pinctrl", .data = (void *) ID_X1000 },
2024 { .compatible = "ingenic,x1000e-pinctrl", .data = (void *) ID_X1000E },
Zhou Yanjie5d215952019-07-14 11:53:56 +08002025 { .compatible = "ingenic,x1500-pinctrl", .data = (void *) ID_X1500 },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002026 {},
2027};
2028
Paul Cercueile72394e2018-08-21 18:42:32 +02002029static const struct of_device_id ingenic_gpio_of_match[] __initconst = {
2030 { .compatible = "ingenic,jz4740-gpio", },
Zhou Yanjie0257595a2019-07-14 11:53:52 +08002031 { .compatible = "ingenic,jz4760-gpio", },
Paul Cercueile72394e2018-08-21 18:42:32 +02002032 { .compatible = "ingenic,jz4770-gpio", },
2033 { .compatible = "ingenic,jz4780-gpio", },
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08002034 { .compatible = "ingenic,x1000-gpio", },
Paul Cercueile72394e2018-08-21 18:42:32 +02002035 {},
2036};
2037
2038static int __init ingenic_gpio_probe(struct ingenic_pinctrl *jzpc,
2039 struct device_node *node)
2040{
2041 struct ingenic_gpio_chip *jzgc;
2042 struct device *dev = jzpc->dev;
Linus Walleij142b8762019-10-01 15:32:09 +02002043 struct gpio_irq_chip *girq;
Paul Cercueile72394e2018-08-21 18:42:32 +02002044 unsigned int bank;
2045 int err;
2046
2047 err = of_property_read_u32(node, "reg", &bank);
2048 if (err) {
2049 dev_err(dev, "Cannot read \"reg\" property: %i\n", err);
2050 return err;
2051 }
2052
2053 jzgc = devm_kzalloc(dev, sizeof(*jzgc), GFP_KERNEL);
2054 if (!jzgc)
2055 return -ENOMEM;
2056
2057 jzgc->jzpc = jzpc;
周琰杰 (Zhou Yanjie)f742e5e2019-12-16 00:21:02 +08002058 jzgc->reg_base = bank * jzpc->info->reg_offset;
Paul Cercueile72394e2018-08-21 18:42:32 +02002059
2060 jzgc->gc.label = devm_kasprintf(dev, GFP_KERNEL, "GPIO%c", 'A' + bank);
2061 if (!jzgc->gc.label)
2062 return -ENOMEM;
2063
2064 /* DO NOT EXPAND THIS: FOR BACKWARD GPIO NUMBERSPACE COMPATIBIBILITY
2065 * ONLY: WORK TO TRANSITION CONSUMERS TO USE THE GPIO DESCRIPTOR API IN
2066 * <linux/gpio/consumer.h> INSTEAD.
2067 */
2068 jzgc->gc.base = bank * 32;
2069
2070 jzgc->gc.ngpio = 32;
2071 jzgc->gc.parent = dev;
2072 jzgc->gc.of_node = node;
2073 jzgc->gc.owner = THIS_MODULE;
2074
2075 jzgc->gc.set = ingenic_gpio_set;
2076 jzgc->gc.get = ingenic_gpio_get;
2077 jzgc->gc.direction_input = ingenic_gpio_direction_input;
2078 jzgc->gc.direction_output = ingenic_gpio_direction_output;
Paul Cercueilebd66512018-08-21 18:42:33 +02002079 jzgc->gc.get_direction = ingenic_gpio_get_direction;
Paul Cercueile72394e2018-08-21 18:42:32 +02002080
2081 if (of_property_read_bool(node, "gpio-ranges")) {
2082 jzgc->gc.request = gpiochip_generic_request;
2083 jzgc->gc.free = gpiochip_generic_free;
2084 }
2085
Paul Cercueile72394e2018-08-21 18:42:32 +02002086 jzgc->irq = irq_of_parse_and_map(node, 0);
2087 if (!jzgc->irq)
2088 return -EINVAL;
2089
2090 jzgc->irq_chip.name = jzgc->gc.label;
2091 jzgc->irq_chip.irq_enable = ingenic_gpio_irq_enable;
2092 jzgc->irq_chip.irq_disable = ingenic_gpio_irq_disable;
2093 jzgc->irq_chip.irq_unmask = ingenic_gpio_irq_unmask;
2094 jzgc->irq_chip.irq_mask = ingenic_gpio_irq_mask;
2095 jzgc->irq_chip.irq_ack = ingenic_gpio_irq_ack;
2096 jzgc->irq_chip.irq_set_type = ingenic_gpio_irq_set_type;
2097 jzgc->irq_chip.irq_set_wake = ingenic_gpio_irq_set_wake;
2098 jzgc->irq_chip.flags = IRQCHIP_MASK_ON_SUSPEND;
2099
Linus Walleij142b8762019-10-01 15:32:09 +02002100 girq = &jzgc->gc.irq;
2101 girq->chip = &jzgc->irq_chip;
2102 girq->parent_handler = ingenic_gpio_irq_handler;
2103 girq->num_parents = 1;
2104 girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents),
2105 GFP_KERNEL);
2106 if (!girq->parents)
2107 return -ENOMEM;
2108 girq->parents[0] = jzgc->irq;
2109 girq->default_type = IRQ_TYPE_NONE;
2110 girq->handler = handle_level_irq;
2111
2112 err = devm_gpiochip_add_data(dev, &jzgc->gc, jzgc);
Paul Cercueile72394e2018-08-21 18:42:32 +02002113 if (err)
2114 return err;
2115
Paul Cercueile72394e2018-08-21 18:42:32 +02002116 return 0;
2117}
2118
Paul Cercueil4717b112018-08-21 18:42:31 +02002119static int __init ingenic_pinctrl_probe(struct platform_device *pdev)
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002120{
2121 struct device *dev = &pdev->dev;
2122 struct ingenic_pinctrl *jzpc;
2123 struct pinctrl_desc *pctl_desc;
2124 void __iomem *base;
2125 const struct platform_device_id *id = platform_get_device_id(pdev);
2126 const struct of_device_id *of_id = of_match_device(
2127 ingenic_pinctrl_of_match, dev);
2128 const struct ingenic_chip_info *chip_info;
Paul Cercueile72394e2018-08-21 18:42:32 +02002129 struct device_node *node;
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002130 unsigned int i;
2131 int err;
2132
2133 jzpc = devm_kzalloc(dev, sizeof(*jzpc), GFP_KERNEL);
2134 if (!jzpc)
2135 return -ENOMEM;
2136
2137 base = devm_ioremap_resource(dev,
2138 platform_get_resource(pdev, IORESOURCE_MEM, 0));
Wei Yongjun119fcf42018-01-17 11:29:17 +00002139 if (IS_ERR(base))
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002140 return PTR_ERR(base);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002141
2142 jzpc->map = devm_regmap_init_mmio(dev, base,
2143 &ingenic_pinctrl_regmap_config);
2144 if (IS_ERR(jzpc->map)) {
2145 dev_err(dev, "Failed to create regmap\n");
2146 return PTR_ERR(jzpc->map);
2147 }
2148
2149 jzpc->dev = dev;
2150
2151 if (of_id)
2152 jzpc->version = (enum jz_version)of_id->data;
2153 else
2154 jzpc->version = (enum jz_version)id->driver_data;
2155
Zhou Yanjie5d215952019-07-14 11:53:56 +08002156 if (jzpc->version >= ID_X1500)
2157 chip_info = &x1500_chip_info;
2158 else if (jzpc->version >= ID_X1000E)
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08002159 chip_info = &x1000e_chip_info;
2160 else if (jzpc->version >= ID_X1000)
2161 chip_info = &x1000_chip_info;
2162 else if (jzpc->version >= ID_JZ4780)
Zhou Yanjieff656e42019-01-28 23:19:57 +08002163 chip_info = &jz4780_chip_info;
2164 else if (jzpc->version >= ID_JZ4770)
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002165 chip_info = &jz4770_chip_info;
Zhou Yanjie0257595a2019-07-14 11:53:52 +08002166 else if (jzpc->version >= ID_JZ4760B)
2167 chip_info = &jz4760b_chip_info;
2168 else if (jzpc->version >= ID_JZ4760)
2169 chip_info = &jz4760_chip_info;
Paul Cercueilf2a96762018-08-21 18:42:34 +02002170 else if (jzpc->version >= ID_JZ4725B)
2171 chip_info = &jz4725b_chip_info;
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002172 else
2173 chip_info = &jz4740_chip_info;
2174 jzpc->info = chip_info;
2175
2176 pctl_desc = devm_kzalloc(&pdev->dev, sizeof(*pctl_desc), GFP_KERNEL);
2177 if (!pctl_desc)
2178 return -ENOMEM;
2179
2180 /* fill in pinctrl_desc structure */
2181 pctl_desc->name = dev_name(dev);
2182 pctl_desc->owner = THIS_MODULE;
2183 pctl_desc->pctlops = &ingenic_pctlops;
2184 pctl_desc->pmxops = &ingenic_pmxops;
2185 pctl_desc->confops = &ingenic_confops;
2186 pctl_desc->npins = chip_info->num_chips * PINS_PER_GPIO_CHIP;
Kees Cooka86854d2018-06-12 14:07:58 -07002187 pctl_desc->pins = jzpc->pdesc = devm_kcalloc(&pdev->dev,
2188 pctl_desc->npins, sizeof(*jzpc->pdesc), GFP_KERNEL);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002189 if (!jzpc->pdesc)
2190 return -ENOMEM;
2191
2192 for (i = 0; i < pctl_desc->npins; i++) {
2193 jzpc->pdesc[i].number = i;
2194 jzpc->pdesc[i].name = kasprintf(GFP_KERNEL, "P%c%d",
2195 'A' + (i / PINS_PER_GPIO_CHIP),
2196 i % PINS_PER_GPIO_CHIP);
2197 }
2198
2199 jzpc->pctl = devm_pinctrl_register(dev, pctl_desc, jzpc);
Dan Carpentere7f4c4b2017-06-14 12:12:09 +03002200 if (IS_ERR(jzpc->pctl)) {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002201 dev_err(dev, "Failed to register pinctrl\n");
Dan Carpentere7f4c4b2017-06-14 12:12:09 +03002202 return PTR_ERR(jzpc->pctl);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002203 }
2204
2205 for (i = 0; i < chip_info->num_groups; i++) {
2206 const struct group_desc *group = &chip_info->groups[i];
2207
2208 err = pinctrl_generic_add_group(jzpc->pctl, group->name,
2209 group->pins, group->num_pins, group->data);
Paul Burton823dd712018-08-25 10:53:28 -07002210 if (err < 0) {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002211 dev_err(dev, "Failed to register group %s\n",
2212 group->name);
2213 return err;
2214 }
2215 }
2216
2217 for (i = 0; i < chip_info->num_functions; i++) {
2218 const struct function_desc *func = &chip_info->functions[i];
2219
2220 err = pinmux_generic_add_function(jzpc->pctl, func->name,
2221 func->group_names, func->num_group_names,
2222 func->data);
Paul Burton823dd712018-08-25 10:53:28 -07002223 if (err < 0) {
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002224 dev_err(dev, "Failed to register function %s\n",
2225 func->name);
2226 return err;
2227 }
2228 }
2229
2230 dev_set_drvdata(dev, jzpc->map);
2231
Paul Cercueile72394e2018-08-21 18:42:32 +02002232 for_each_child_of_node(dev->of_node, node) {
2233 if (of_match_node(ingenic_gpio_of_match, node)) {
2234 err = ingenic_gpio_probe(jzpc, node);
2235 if (err)
2236 return err;
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002237 }
2238 }
2239
2240 return 0;
2241}
2242
2243static const struct platform_device_id ingenic_pinctrl_ids[] = {
2244 { "jz4740-pinctrl", ID_JZ4740 },
Paul Cercueilf2a96762018-08-21 18:42:34 +02002245 { "jz4725b-pinctrl", ID_JZ4725B },
Zhou Yanjie0257595a2019-07-14 11:53:52 +08002246 { "jz4760-pinctrl", ID_JZ4760 },
2247 { "jz4760b-pinctrl", ID_JZ4760B },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002248 { "jz4770-pinctrl", ID_JZ4770 },
2249 { "jz4780-pinctrl", ID_JZ4780 },
Zhou Yanjiefe1ad5e2019-07-14 11:53:54 +08002250 { "x1000-pinctrl", ID_X1000 },
2251 { "x1000e-pinctrl", ID_X1000E },
Zhou Yanjie5d215952019-07-14 11:53:56 +08002252 { "x1500-pinctrl", ID_X1500 },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002253 {},
2254};
2255
2256static struct platform_driver ingenic_pinctrl_driver = {
2257 .driver = {
2258 .name = "pinctrl-ingenic",
2259 .of_match_table = of_match_ptr(ingenic_pinctrl_of_match),
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002260 },
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002261 .id_table = ingenic_pinctrl_ids,
2262};
2263
2264static int __init ingenic_pinctrl_drv_register(void)
2265{
Paul Cercueil4717b112018-08-21 18:42:31 +02002266 return platform_driver_probe(&ingenic_pinctrl_driver,
2267 ingenic_pinctrl_probe);
Paul Cercueilb5c23aa2017-05-12 18:52:56 +02002268}
Paul Cercueil556a36a2018-08-21 18:42:30 +02002269subsys_initcall(ingenic_pinctrl_drv_register);