pinctrl: sirf: fix spinlock deadlock in sirfsoc_gpio_set_input
[linux-2.6/libata-dev.git] / drivers / pinctrl / pinctrl-sirf.c
blob0f4f833e3c933c3ac2b0eaa956aca1fab1ddbb56
1 /*
2 * pinmux driver for CSR SiRFprimaII
4 * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
6 * Licensed under GPLv2 or later.
7 */
9 #include <linux/init.h>
10 #include <linux/module.h>
11 #include <linux/irq.h>
12 #include <linux/platform_device.h>
13 #include <linux/io.h>
14 #include <linux/slab.h>
15 #include <linux/err.h>
16 #include <linux/irqdomain.h>
17 #include <linux/pinctrl/pinctrl.h>
18 #include <linux/pinctrl/pinmux.h>
19 #include <linux/pinctrl/consumer.h>
20 #include <linux/of.h>
21 #include <linux/of_address.h>
22 #include <linux/of_device.h>
23 #include <linux/of_platform.h>
24 #include <linux/bitops.h>
25 #include <linux/gpio.h>
26 #include <linux/of_gpio.h>
28 #define DRIVER_NAME "pinmux-sirf"
30 #define SIRFSOC_NUM_PADS 622
31 #define SIRFSOC_RSC_PIN_MUX 0x4
33 #define SIRFSOC_GPIO_PAD_EN(g) ((g)*0x100 + 0x84)
34 #define SIRFSOC_GPIO_CTRL(g, i) ((g)*0x100 + (i)*4)
35 #define SIRFSOC_GPIO_DSP_EN0 (0x80)
36 #define SIRFSOC_GPIO_PAD_EN(g) ((g)*0x100 + 0x84)
37 #define SIRFSOC_GPIO_INT_STATUS(g) ((g)*0x100 + 0x8C)
39 #define SIRFSOC_GPIO_CTL_INTR_LOW_MASK 0x1
40 #define SIRFSOC_GPIO_CTL_INTR_HIGH_MASK 0x2
41 #define SIRFSOC_GPIO_CTL_INTR_TYPE_MASK 0x4
42 #define SIRFSOC_GPIO_CTL_INTR_EN_MASK 0x8
43 #define SIRFSOC_GPIO_CTL_INTR_STS_MASK 0x10
44 #define SIRFSOC_GPIO_CTL_OUT_EN_MASK 0x20
45 #define SIRFSOC_GPIO_CTL_DATAOUT_MASK 0x40
46 #define SIRFSOC_GPIO_CTL_DATAIN_MASK 0x80
47 #define SIRFSOC_GPIO_CTL_PULL_MASK 0x100
48 #define SIRFSOC_GPIO_CTL_PULL_HIGH 0x200
49 #define SIRFSOC_GPIO_CTL_DSP_INT 0x400
51 #define SIRFSOC_GPIO_NO_OF_BANKS 5
52 #define SIRFSOC_GPIO_BANK_SIZE 32
53 #define SIRFSOC_GPIO_NUM(bank, index) (((bank)*(32)) + (index))
55 struct sirfsoc_gpio_bank {
56 struct of_mm_gpio_chip chip;
57 struct irq_domain *domain;
58 int id;
59 int parent_irq;
60 spinlock_t lock;
63 static struct sirfsoc_gpio_bank sgpio_bank[SIRFSOC_GPIO_NO_OF_BANKS];
64 static DEFINE_SPINLOCK(sgpio_lock);
67 * pad list for the pinmux subsystem
68 * refer to CS-131858-DC-6A.xls
70 static const struct pinctrl_pin_desc sirfsoc_pads[] = {
71 PINCTRL_PIN(0, "gpio0-0"),
72 PINCTRL_PIN(1, "gpio0-1"),
73 PINCTRL_PIN(2, "gpio0-2"),
74 PINCTRL_PIN(3, "gpio0-3"),
75 PINCTRL_PIN(4, "pwm0"),
76 PINCTRL_PIN(5, "pwm1"),
77 PINCTRL_PIN(6, "pwm2"),
78 PINCTRL_PIN(7, "pwm3"),
79 PINCTRL_PIN(8, "warm_rst_b"),
80 PINCTRL_PIN(9, "odo_0"),
81 PINCTRL_PIN(10, "odo_1"),
82 PINCTRL_PIN(11, "dr_dir"),
83 PINCTRL_PIN(12, "viprom_fa"),
84 PINCTRL_PIN(13, "scl_1"),
85 PINCTRL_PIN(14, "ntrst"),
86 PINCTRL_PIN(15, "sda_1"),
87 PINCTRL_PIN(16, "x_ldd[16]"),
88 PINCTRL_PIN(17, "x_ldd[17]"),
89 PINCTRL_PIN(18, "x_ldd[18]"),
90 PINCTRL_PIN(19, "x_ldd[19]"),
91 PINCTRL_PIN(20, "x_ldd[20]"),
92 PINCTRL_PIN(21, "x_ldd[21]"),
93 PINCTRL_PIN(22, "x_ldd[22]"),
94 PINCTRL_PIN(23, "x_ldd[23], lcdrom_frdy"),
95 PINCTRL_PIN(24, "gps_sgn"),
96 PINCTRL_PIN(25, "gps_mag"),
97 PINCTRL_PIN(26, "gps_clk"),
98 PINCTRL_PIN(27, "sd_cd_b_1"),
99 PINCTRL_PIN(28, "sd_vcc_on_1"),
100 PINCTRL_PIN(29, "sd_wp_b_1"),
101 PINCTRL_PIN(30, "sd_clk_3"),
102 PINCTRL_PIN(31, "sd_cmd_3"),
104 PINCTRL_PIN(32, "x_sd_dat_3[0]"),
105 PINCTRL_PIN(33, "x_sd_dat_3[1]"),
106 PINCTRL_PIN(34, "x_sd_dat_3[2]"),
107 PINCTRL_PIN(35, "x_sd_dat_3[3]"),
108 PINCTRL_PIN(36, "x_sd_clk_4"),
109 PINCTRL_PIN(37, "x_sd_cmd_4"),
110 PINCTRL_PIN(38, "x_sd_dat_4[0]"),
111 PINCTRL_PIN(39, "x_sd_dat_4[1]"),
112 PINCTRL_PIN(40, "x_sd_dat_4[2]"),
113 PINCTRL_PIN(41, "x_sd_dat_4[3]"),
114 PINCTRL_PIN(42, "x_cko_1"),
115 PINCTRL_PIN(43, "x_ac97_bit_clk"),
116 PINCTRL_PIN(44, "x_ac97_dout"),
117 PINCTRL_PIN(45, "x_ac97_din"),
118 PINCTRL_PIN(46, "x_ac97_sync"),
119 PINCTRL_PIN(47, "x_txd_1"),
120 PINCTRL_PIN(48, "x_txd_2"),
121 PINCTRL_PIN(49, "x_rxd_1"),
122 PINCTRL_PIN(50, "x_rxd_2"),
123 PINCTRL_PIN(51, "x_usclk_0"),
124 PINCTRL_PIN(52, "x_utxd_0"),
125 PINCTRL_PIN(53, "x_urxd_0"),
126 PINCTRL_PIN(54, "x_utfs_0"),
127 PINCTRL_PIN(55, "x_urfs_0"),
128 PINCTRL_PIN(56, "x_usclk_1"),
129 PINCTRL_PIN(57, "x_utxd_1"),
130 PINCTRL_PIN(58, "x_urxd_1"),
131 PINCTRL_PIN(59, "x_utfs_1"),
132 PINCTRL_PIN(60, "x_urfs_1"),
133 PINCTRL_PIN(61, "x_usclk_2"),
134 PINCTRL_PIN(62, "x_utxd_2"),
135 PINCTRL_PIN(63, "x_urxd_2"),
137 PINCTRL_PIN(64, "x_utfs_2"),
138 PINCTRL_PIN(65, "x_urfs_2"),
139 PINCTRL_PIN(66, "x_df_we_b"),
140 PINCTRL_PIN(67, "x_df_re_b"),
141 PINCTRL_PIN(68, "x_txd_0"),
142 PINCTRL_PIN(69, "x_rxd_0"),
143 PINCTRL_PIN(78, "x_cko_0"),
144 PINCTRL_PIN(79, "x_vip_pxd[7]"),
145 PINCTRL_PIN(80, "x_vip_pxd[6]"),
146 PINCTRL_PIN(81, "x_vip_pxd[5]"),
147 PINCTRL_PIN(82, "x_vip_pxd[4]"),
148 PINCTRL_PIN(83, "x_vip_pxd[3]"),
149 PINCTRL_PIN(84, "x_vip_pxd[2]"),
150 PINCTRL_PIN(85, "x_vip_pxd[1]"),
151 PINCTRL_PIN(86, "x_vip_pxd[0]"),
152 PINCTRL_PIN(87, "x_vip_vsync"),
153 PINCTRL_PIN(88, "x_vip_hsync"),
154 PINCTRL_PIN(89, "x_vip_pxclk"),
155 PINCTRL_PIN(90, "x_sda_0"),
156 PINCTRL_PIN(91, "x_scl_0"),
157 PINCTRL_PIN(92, "x_df_ry_by"),
158 PINCTRL_PIN(93, "x_df_cs_b[1]"),
159 PINCTRL_PIN(94, "x_df_cs_b[0]"),
160 PINCTRL_PIN(95, "x_l_pclk"),
162 PINCTRL_PIN(96, "x_l_lck"),
163 PINCTRL_PIN(97, "x_l_fck"),
164 PINCTRL_PIN(98, "x_l_de"),
165 PINCTRL_PIN(99, "x_ldd[0]"),
166 PINCTRL_PIN(100, "x_ldd[1]"),
167 PINCTRL_PIN(101, "x_ldd[2]"),
168 PINCTRL_PIN(102, "x_ldd[3]"),
169 PINCTRL_PIN(103, "x_ldd[4]"),
170 PINCTRL_PIN(104, "x_ldd[5]"),
171 PINCTRL_PIN(105, "x_ldd[6]"),
172 PINCTRL_PIN(106, "x_ldd[7]"),
173 PINCTRL_PIN(107, "x_ldd[8]"),
174 PINCTRL_PIN(108, "x_ldd[9]"),
175 PINCTRL_PIN(109, "x_ldd[10]"),
176 PINCTRL_PIN(110, "x_ldd[11]"),
177 PINCTRL_PIN(111, "x_ldd[12]"),
178 PINCTRL_PIN(112, "x_ldd[13]"),
179 PINCTRL_PIN(113, "x_ldd[14]"),
180 PINCTRL_PIN(114, "x_ldd[15]"),
184 * @dev: a pointer back to containing device
185 * @virtbase: the offset to the controller in virtual memory
187 struct sirfsoc_pmx {
188 struct device *dev;
189 struct pinctrl_dev *pmx;
190 void __iomem *gpio_virtbase;
191 void __iomem *rsc_virtbase;
194 /* SIRFSOC_GPIO_PAD_EN set */
195 struct sirfsoc_muxmask {
196 unsigned long group;
197 unsigned long mask;
200 struct sirfsoc_padmux {
201 unsigned long muxmask_counts;
202 const struct sirfsoc_muxmask *muxmask;
203 /* RSC_PIN_MUX set */
204 unsigned long funcmask;
205 unsigned long funcval;
209 * struct sirfsoc_pin_group - describes a SiRFprimaII pin group
210 * @name: the name of this specific pin group
211 * @pins: an array of discrete physical pins used in this group, taken
212 * from the driver-local pin enumeration space
213 * @num_pins: the number of pins in this group array, i.e. the number of
214 * elements in .pins so we can iterate over that array
216 struct sirfsoc_pin_group {
217 const char *name;
218 const unsigned int *pins;
219 const unsigned num_pins;
222 static const struct sirfsoc_muxmask lcd_16bits_sirfsoc_muxmask[] = {
224 .group = 3,
225 .mask = BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7) | BIT(8) |
226 BIT(9) | BIT(10) | BIT(11) | BIT(12) | BIT(13) | BIT(14) | BIT(15) | BIT(16) |
227 BIT(17) | BIT(18),
228 }, {
229 .group = 2,
230 .mask = BIT(31),
234 static const struct sirfsoc_padmux lcd_16bits_padmux = {
235 .muxmask_counts = ARRAY_SIZE(lcd_16bits_sirfsoc_muxmask),
236 .muxmask = lcd_16bits_sirfsoc_muxmask,
237 .funcmask = BIT(4),
238 .funcval = 0,
241 static const unsigned lcd_16bits_pins[] = { 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
242 105, 106, 107, 108, 109, 110, 111, 112, 113, 114 };
244 static const struct sirfsoc_muxmask lcd_18bits_muxmask[] = {
246 .group = 3,
247 .mask = BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7) | BIT(8) |
248 BIT(9) | BIT(10) | BIT(11) | BIT(12) | BIT(13) | BIT(14) | BIT(15) | BIT(16) |
249 BIT(17) | BIT(18),
250 }, {
251 .group = 2,
252 .mask = BIT(31),
253 }, {
254 .group = 0,
255 .mask = BIT(16) | BIT(17),
259 static const struct sirfsoc_padmux lcd_18bits_padmux = {
260 .muxmask_counts = ARRAY_SIZE(lcd_18bits_muxmask),
261 .muxmask = lcd_18bits_muxmask,
262 .funcmask = BIT(4),
263 .funcval = 0,
266 static const unsigned lcd_18bits_pins[] = { 16, 17, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
267 105, 106, 107, 108, 109, 110, 111, 112, 113, 114};
269 static const struct sirfsoc_muxmask lcd_24bits_muxmask[] = {
271 .group = 3,
272 .mask = BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7) | BIT(8) |
273 BIT(9) | BIT(10) | BIT(11) | BIT(12) | BIT(13) | BIT(14) | BIT(15) | BIT(16) |
274 BIT(17) | BIT(18),
275 }, {
276 .group = 2,
277 .mask = BIT(31),
278 }, {
279 .group = 0,
280 .mask = BIT(16) | BIT(17) | BIT(18) | BIT(19) | BIT(20) | BIT(21) | BIT(22) | BIT(23),
284 static const struct sirfsoc_padmux lcd_24bits_padmux = {
285 .muxmask_counts = ARRAY_SIZE(lcd_24bits_muxmask),
286 .muxmask = lcd_24bits_muxmask,
287 .funcmask = BIT(4),
288 .funcval = 0,
291 static const unsigned lcd_24bits_pins[] = { 16, 17, 18, 19, 20, 21, 22, 23, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
292 105, 106, 107, 108, 109, 110, 111, 112, 113, 114 };
294 static const struct sirfsoc_muxmask lcdrom_muxmask[] = {
296 .group = 3,
297 .mask = BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7) | BIT(8) |
298 BIT(9) | BIT(10) | BIT(11) | BIT(12) | BIT(13) | BIT(14) | BIT(15) | BIT(16) |
299 BIT(17) | BIT(18),
300 }, {
301 .group = 2,
302 .mask = BIT(31),
303 }, {
304 .group = 0,
305 .mask = BIT(23),
309 static const struct sirfsoc_padmux lcdrom_padmux = {
310 .muxmask_counts = ARRAY_SIZE(lcdrom_muxmask),
311 .muxmask = lcdrom_muxmask,
312 .funcmask = BIT(4),
313 .funcval = BIT(4),
316 static const unsigned lcdrom_pins[] = { 23, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
317 105, 106, 107, 108, 109, 110, 111, 112, 113, 114 };
319 static const struct sirfsoc_muxmask uart0_muxmask[] = {
321 .group = 2,
322 .mask = BIT(4) | BIT(5),
323 }, {
324 .group = 1,
325 .mask = BIT(23) | BIT(28),
329 static const struct sirfsoc_padmux uart0_padmux = {
330 .muxmask_counts = ARRAY_SIZE(uart0_muxmask),
331 .muxmask = uart0_muxmask,
332 .funcmask = BIT(9),
333 .funcval = BIT(9),
336 static const unsigned uart0_pins[] = { 55, 60, 68, 69 };
338 static const struct sirfsoc_muxmask uart0_nostreamctrl_muxmask[] = {
340 .group = 2,
341 .mask = BIT(4) | BIT(5),
345 static const struct sirfsoc_padmux uart0_nostreamctrl_padmux = {
346 .muxmask_counts = ARRAY_SIZE(uart0_nostreamctrl_muxmask),
347 .muxmask = uart0_nostreamctrl_muxmask,
350 static const unsigned uart0_nostreamctrl_pins[] = { 68, 39 };
352 static const struct sirfsoc_muxmask uart1_muxmask[] = {
354 .group = 1,
355 .mask = BIT(15) | BIT(17),
359 static const struct sirfsoc_padmux uart1_padmux = {
360 .muxmask_counts = ARRAY_SIZE(uart1_muxmask),
361 .muxmask = uart1_muxmask,
364 static const unsigned uart1_pins[] = { 47, 49 };
366 static const struct sirfsoc_muxmask uart2_muxmask[] = {
368 .group = 1,
369 .mask = BIT(16) | BIT(18) | BIT(24) | BIT(27),
373 static const struct sirfsoc_padmux uart2_padmux = {
374 .muxmask_counts = ARRAY_SIZE(uart2_muxmask),
375 .muxmask = uart2_muxmask,
376 .funcmask = BIT(10),
377 .funcval = BIT(10),
380 static const unsigned uart2_pins[] = { 48, 50, 56, 59 };
382 static const struct sirfsoc_muxmask uart2_nostreamctrl_muxmask[] = {
384 .group = 1,
385 .mask = BIT(16) | BIT(18),
389 static const struct sirfsoc_padmux uart2_nostreamctrl_padmux = {
390 .muxmask_counts = ARRAY_SIZE(uart2_nostreamctrl_muxmask),
391 .muxmask = uart2_nostreamctrl_muxmask,
394 static const unsigned uart2_nostreamctrl_pins[] = { 48, 50 };
396 static const struct sirfsoc_muxmask sdmmc3_muxmask[] = {
398 .group = 0,
399 .mask = BIT(30) | BIT(31),
400 }, {
401 .group = 1,
402 .mask = BIT(0) | BIT(1) | BIT(2) | BIT(3),
406 static const struct sirfsoc_padmux sdmmc3_padmux = {
407 .muxmask_counts = ARRAY_SIZE(sdmmc3_muxmask),
408 .muxmask = sdmmc3_muxmask,
409 .funcmask = BIT(7),
410 .funcval = 0,
413 static const unsigned sdmmc3_pins[] = { 30, 31, 32, 33, 34, 35 };
415 static const struct sirfsoc_muxmask spi0_muxmask[] = {
417 .group = 1,
418 .mask = BIT(0) | BIT(1) | BIT(2) | BIT(3),
422 static const struct sirfsoc_padmux spi0_padmux = {
423 .muxmask_counts = ARRAY_SIZE(spi0_muxmask),
424 .muxmask = spi0_muxmask,
425 .funcmask = BIT(7),
426 .funcval = BIT(7),
429 static const unsigned spi0_pins[] = { 32, 33, 34, 35 };
431 static const struct sirfsoc_muxmask sdmmc4_muxmask[] = {
433 .group = 1,
434 .mask = BIT(4) | BIT(5) | BIT(6) | BIT(7) | BIT(8) | BIT(9),
438 static const struct sirfsoc_padmux sdmmc4_padmux = {
439 .muxmask_counts = ARRAY_SIZE(sdmmc4_muxmask),
440 .muxmask = sdmmc4_muxmask,
443 static const unsigned sdmmc4_pins[] = { 36, 37, 38, 39, 40, 41 };
445 static const struct sirfsoc_muxmask cko1_muxmask[] = {
447 .group = 1,
448 .mask = BIT(10),
452 static const struct sirfsoc_padmux cko1_padmux = {
453 .muxmask_counts = ARRAY_SIZE(cko1_muxmask),
454 .muxmask = cko1_muxmask,
455 .funcmask = BIT(3),
456 .funcval = 0,
459 static const unsigned cko1_pins[] = { 42 };
461 static const struct sirfsoc_muxmask i2s_muxmask[] = {
463 .group = 1,
464 .mask =
465 BIT(10) | BIT(11) | BIT(12) | BIT(13) | BIT(14) | BIT(19)
466 | BIT(23) | BIT(28),
470 static const struct sirfsoc_padmux i2s_padmux = {
471 .muxmask_counts = ARRAY_SIZE(i2s_muxmask),
472 .muxmask = i2s_muxmask,
473 .funcmask = BIT(3) | BIT(9),
474 .funcval = BIT(3),
477 static const unsigned i2s_pins[] = { 42, 43, 44, 45, 46, 51, 55, 60 };
479 static const struct sirfsoc_muxmask ac97_muxmask[] = {
481 .group = 1,
482 .mask = BIT(11) | BIT(12) | BIT(13) | BIT(14),
486 static const struct sirfsoc_padmux ac97_padmux = {
487 .muxmask_counts = ARRAY_SIZE(ac97_muxmask),
488 .muxmask = ac97_muxmask,
489 .funcmask = BIT(8),
490 .funcval = 0,
493 static const unsigned ac97_pins[] = { 33, 34, 35, 36 };
495 static const struct sirfsoc_muxmask spi1_muxmask[] = {
497 .group = 1,
498 .mask = BIT(11) | BIT(12) | BIT(13) | BIT(14),
502 static const struct sirfsoc_padmux spi1_padmux = {
503 .muxmask_counts = ARRAY_SIZE(spi1_muxmask),
504 .muxmask = spi1_muxmask,
505 .funcmask = BIT(8),
506 .funcval = BIT(8),
509 static const unsigned spi1_pins[] = { 43, 44, 45, 46 };
511 static const struct sirfsoc_muxmask sdmmc1_muxmask[] = {
513 .group = 0,
514 .mask = BIT(27) | BIT(28) | BIT(29),
518 static const struct sirfsoc_padmux sdmmc1_padmux = {
519 .muxmask_counts = ARRAY_SIZE(sdmmc1_muxmask),
520 .muxmask = sdmmc1_muxmask,
523 static const unsigned sdmmc1_pins[] = { 27, 28, 29 };
525 static const struct sirfsoc_muxmask gps_muxmask[] = {
527 .group = 0,
528 .mask = BIT(24) | BIT(25) | BIT(26),
532 static const struct sirfsoc_padmux gps_padmux = {
533 .muxmask_counts = ARRAY_SIZE(gps_muxmask),
534 .muxmask = gps_muxmask,
535 .funcmask = BIT(12) | BIT(13) | BIT(14),
536 .funcval = BIT(12),
539 static const unsigned gps_pins[] = { 24, 25, 26 };
541 static const struct sirfsoc_muxmask sdmmc5_muxmask[] = {
543 .group = 0,
544 .mask = BIT(24) | BIT(25) | BIT(26),
545 }, {
546 .group = 1,
547 .mask = BIT(29),
548 }, {
549 .group = 2,
550 .mask = BIT(0) | BIT(1),
554 static const struct sirfsoc_padmux sdmmc5_padmux = {
555 .muxmask_counts = ARRAY_SIZE(sdmmc5_muxmask),
556 .muxmask = sdmmc5_muxmask,
557 .funcmask = BIT(13) | BIT(14),
558 .funcval = BIT(13) | BIT(14),
561 static const unsigned sdmmc5_pins[] = { 24, 25, 26, 61, 64, 65 };
563 static const struct sirfsoc_muxmask usp0_muxmask[] = {
565 .group = 1,
566 .mask = BIT(19) | BIT(20) | BIT(21) | BIT(22) | BIT(23),
570 static const struct sirfsoc_padmux usp0_padmux = {
571 .muxmask_counts = ARRAY_SIZE(usp0_muxmask),
572 .muxmask = usp0_muxmask,
573 .funcmask = BIT(1) | BIT(2) | BIT(6) | BIT(9),
574 .funcval = 0,
577 static const unsigned usp0_pins[] = { 51, 52, 53, 54, 55 };
579 static const struct sirfsoc_muxmask usp1_muxmask[] = {
581 .group = 1,
582 .mask = BIT(24) | BIT(25) | BIT(26) | BIT(27) | BIT(28),
586 static const struct sirfsoc_padmux usp1_padmux = {
587 .muxmask_counts = ARRAY_SIZE(usp1_muxmask),
588 .muxmask = usp1_muxmask,
589 .funcmask = BIT(1) | BIT(9) | BIT(10) | BIT(11),
590 .funcval = 0,
593 static const unsigned usp1_pins[] = { 56, 57, 58, 59, 60 };
595 static const struct sirfsoc_muxmask usp2_muxmask[] = {
597 .group = 1,
598 .mask = BIT(29) | BIT(30) | BIT(31),
599 }, {
600 .group = 2,
601 .mask = BIT(0) | BIT(1),
605 static const struct sirfsoc_padmux usp2_padmux = {
606 .muxmask_counts = ARRAY_SIZE(usp2_muxmask),
607 .muxmask = usp2_muxmask,
608 .funcmask = BIT(13) | BIT(14),
609 .funcval = 0,
612 static const unsigned usp2_pins[] = { 61, 62, 63, 64, 65 };
614 static const struct sirfsoc_muxmask nand_muxmask[] = {
616 .group = 2,
617 .mask = BIT(2) | BIT(3) | BIT(28) | BIT(29) | BIT(30),
621 static const struct sirfsoc_padmux nand_padmux = {
622 .muxmask_counts = ARRAY_SIZE(nand_muxmask),
623 .muxmask = nand_muxmask,
624 .funcmask = BIT(5),
625 .funcval = 0,
628 static const unsigned nand_pins[] = { 64, 65, 92, 93, 94 };
630 static const struct sirfsoc_padmux sdmmc0_padmux = {
631 .muxmask_counts = 0,
632 .funcmask = BIT(5),
633 .funcval = 0,
636 static const unsigned sdmmc0_pins[] = { };
638 static const struct sirfsoc_muxmask sdmmc2_muxmask[] = {
640 .group = 2,
641 .mask = BIT(2) | BIT(3),
645 static const struct sirfsoc_padmux sdmmc2_padmux = {
646 .muxmask_counts = ARRAY_SIZE(sdmmc2_muxmask),
647 .muxmask = sdmmc2_muxmask,
648 .funcmask = BIT(5),
649 .funcval = BIT(5),
652 static const unsigned sdmmc2_pins[] = { 66, 67 };
654 static const struct sirfsoc_muxmask cko0_muxmask[] = {
656 .group = 2,
657 .mask = BIT(14),
661 static const struct sirfsoc_padmux cko0_padmux = {
662 .muxmask_counts = ARRAY_SIZE(cko0_muxmask),
663 .muxmask = cko0_muxmask,
666 static const unsigned cko0_pins[] = { 78 };
668 static const struct sirfsoc_muxmask vip_muxmask[] = {
670 .group = 2,
671 .mask = BIT(15) | BIT(16) | BIT(17) | BIT(18) | BIT(19)
672 | BIT(20) | BIT(21) | BIT(22) | BIT(23) | BIT(24) |
673 BIT(25),
677 static const struct sirfsoc_padmux vip_padmux = {
678 .muxmask_counts = ARRAY_SIZE(vip_muxmask),
679 .muxmask = vip_muxmask,
680 .funcmask = BIT(0),
681 .funcval = 0,
684 static const unsigned vip_pins[] = { 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89 };
686 static const struct sirfsoc_muxmask i2c0_muxmask[] = {
688 .group = 2,
689 .mask = BIT(26) | BIT(27),
693 static const struct sirfsoc_padmux i2c0_padmux = {
694 .muxmask_counts = ARRAY_SIZE(i2c0_muxmask),
695 .muxmask = i2c0_muxmask,
698 static const unsigned i2c0_pins[] = { 90, 91 };
700 static const struct sirfsoc_muxmask i2c1_muxmask[] = {
702 .group = 0,
703 .mask = BIT(13) | BIT(15),
707 static const struct sirfsoc_padmux i2c1_padmux = {
708 .muxmask_counts = ARRAY_SIZE(i2c1_muxmask),
709 .muxmask = i2c1_muxmask,
712 static const unsigned i2c1_pins[] = { 13, 15 };
714 static const struct sirfsoc_muxmask viprom_muxmask[] = {
716 .group = 2,
717 .mask = BIT(15) | BIT(16) | BIT(17) | BIT(18) | BIT(19)
718 | BIT(20) | BIT(21) | BIT(22) | BIT(23) | BIT(24) |
719 BIT(25),
720 }, {
721 .group = 0,
722 .mask = BIT(12),
726 static const struct sirfsoc_padmux viprom_padmux = {
727 .muxmask_counts = ARRAY_SIZE(viprom_muxmask),
728 .muxmask = viprom_muxmask,
729 .funcmask = BIT(0),
730 .funcval = BIT(0),
733 static const unsigned viprom_pins[] = { 12, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89 };
735 static const struct sirfsoc_muxmask pwm0_muxmask[] = {
737 .group = 0,
738 .mask = BIT(4),
742 static const struct sirfsoc_padmux pwm0_padmux = {
743 .muxmask_counts = ARRAY_SIZE(pwm0_muxmask),
744 .muxmask = pwm0_muxmask,
745 .funcmask = BIT(12),
746 .funcval = 0,
749 static const unsigned pwm0_pins[] = { 4 };
751 static const struct sirfsoc_muxmask pwm1_muxmask[] = {
753 .group = 0,
754 .mask = BIT(5),
758 static const struct sirfsoc_padmux pwm1_padmux = {
759 .muxmask_counts = ARRAY_SIZE(pwm1_muxmask),
760 .muxmask = pwm1_muxmask,
763 static const unsigned pwm1_pins[] = { 5 };
765 static const struct sirfsoc_muxmask pwm2_muxmask[] = {
767 .group = 0,
768 .mask = BIT(6),
772 static const struct sirfsoc_padmux pwm2_padmux = {
773 .muxmask_counts = ARRAY_SIZE(pwm2_muxmask),
774 .muxmask = pwm2_muxmask,
777 static const unsigned pwm2_pins[] = { 6 };
779 static const struct sirfsoc_muxmask pwm3_muxmask[] = {
781 .group = 0,
782 .mask = BIT(7),
786 static const struct sirfsoc_padmux pwm3_padmux = {
787 .muxmask_counts = ARRAY_SIZE(pwm3_muxmask),
788 .muxmask = pwm3_muxmask,
791 static const unsigned pwm3_pins[] = { 7 };
793 static const struct sirfsoc_muxmask warm_rst_muxmask[] = {
795 .group = 0,
796 .mask = BIT(8),
800 static const struct sirfsoc_padmux warm_rst_padmux = {
801 .muxmask_counts = ARRAY_SIZE(warm_rst_muxmask),
802 .muxmask = warm_rst_muxmask,
805 static const unsigned warm_rst_pins[] = { 8 };
807 static const struct sirfsoc_muxmask usb0_utmi_drvbus_muxmask[] = {
809 .group = 1,
810 .mask = BIT(22),
813 static const struct sirfsoc_padmux usb0_utmi_drvbus_padmux = {
814 .muxmask_counts = ARRAY_SIZE(usb0_utmi_drvbus_muxmask),
815 .muxmask = usb0_utmi_drvbus_muxmask,
816 .funcmask = BIT(6),
817 .funcval = BIT(6), /* refer to PAD_UTMI_DRVVBUS0_ENABLE */
820 static const unsigned usb0_utmi_drvbus_pins[] = { 54 };
822 static const struct sirfsoc_muxmask usb1_utmi_drvbus_muxmask[] = {
824 .group = 1,
825 .mask = BIT(27),
829 static const struct sirfsoc_padmux usb1_utmi_drvbus_padmux = {
830 .muxmask_counts = ARRAY_SIZE(usb1_utmi_drvbus_muxmask),
831 .muxmask = usb1_utmi_drvbus_muxmask,
832 .funcmask = BIT(11),
833 .funcval = BIT(11), /* refer to PAD_UTMI_DRVVBUS1_ENABLE */
836 static const unsigned usb1_utmi_drvbus_pins[] = { 59 };
838 static const struct sirfsoc_muxmask pulse_count_muxmask[] = {
840 .group = 0,
841 .mask = BIT(9) | BIT(10) | BIT(11),
845 static const struct sirfsoc_padmux pulse_count_padmux = {
846 .muxmask_counts = ARRAY_SIZE(pulse_count_muxmask),
847 .muxmask = pulse_count_muxmask,
850 static const unsigned pulse_count_pins[] = { 9, 10, 11 };
852 #define SIRFSOC_PIN_GROUP(n, p) \
854 .name = n, \
855 .pins = p, \
856 .num_pins = ARRAY_SIZE(p), \
859 static const struct sirfsoc_pin_group sirfsoc_pin_groups[] = {
860 SIRFSOC_PIN_GROUP("lcd_16bitsgrp", lcd_16bits_pins),
861 SIRFSOC_PIN_GROUP("lcd_18bitsgrp", lcd_18bits_pins),
862 SIRFSOC_PIN_GROUP("lcd_24bitsgrp", lcd_24bits_pins),
863 SIRFSOC_PIN_GROUP("lcdrom_grp", lcdrom_pins),
864 SIRFSOC_PIN_GROUP("uart0grp", uart0_pins),
865 SIRFSOC_PIN_GROUP("uart1grp", uart1_pins),
866 SIRFSOC_PIN_GROUP("uart2grp", uart2_pins),
867 SIRFSOC_PIN_GROUP("uart2_nostreamctrlgrp", uart2_nostreamctrl_pins),
868 SIRFSOC_PIN_GROUP("usp0grp", usp0_pins),
869 SIRFSOC_PIN_GROUP("usp1grp", usp1_pins),
870 SIRFSOC_PIN_GROUP("usp2grp", usp2_pins),
871 SIRFSOC_PIN_GROUP("i2c0grp", i2c0_pins),
872 SIRFSOC_PIN_GROUP("i2c1grp", i2c1_pins),
873 SIRFSOC_PIN_GROUP("pwm0grp", pwm0_pins),
874 SIRFSOC_PIN_GROUP("pwm1grp", pwm1_pins),
875 SIRFSOC_PIN_GROUP("pwm2grp", pwm2_pins),
876 SIRFSOC_PIN_GROUP("pwm3grp", pwm3_pins),
877 SIRFSOC_PIN_GROUP("vipgrp", vip_pins),
878 SIRFSOC_PIN_GROUP("vipromgrp", viprom_pins),
879 SIRFSOC_PIN_GROUP("warm_rstgrp", warm_rst_pins),
880 SIRFSOC_PIN_GROUP("cko0_rstgrp", cko0_pins),
881 SIRFSOC_PIN_GROUP("cko1_rstgrp", cko1_pins),
882 SIRFSOC_PIN_GROUP("sdmmc0grp", sdmmc0_pins),
883 SIRFSOC_PIN_GROUP("sdmmc1grp", sdmmc1_pins),
884 SIRFSOC_PIN_GROUP("sdmmc2grp", sdmmc2_pins),
885 SIRFSOC_PIN_GROUP("sdmmc3grp", sdmmc3_pins),
886 SIRFSOC_PIN_GROUP("sdmmc4grp", sdmmc4_pins),
887 SIRFSOC_PIN_GROUP("sdmmc5grp", sdmmc5_pins),
888 SIRFSOC_PIN_GROUP("usb0_utmi_drvbusgrp", usb0_utmi_drvbus_pins),
889 SIRFSOC_PIN_GROUP("usb1_utmi_drvbusgrp", usb1_utmi_drvbus_pins),
890 SIRFSOC_PIN_GROUP("pulse_countgrp", pulse_count_pins),
891 SIRFSOC_PIN_GROUP("i2sgrp", i2s_pins),
892 SIRFSOC_PIN_GROUP("ac97grp", ac97_pins),
893 SIRFSOC_PIN_GROUP("nandgrp", nand_pins),
894 SIRFSOC_PIN_GROUP("spi0grp", spi0_pins),
895 SIRFSOC_PIN_GROUP("spi1grp", spi1_pins),
896 SIRFSOC_PIN_GROUP("gpsgrp", gps_pins),
899 static int sirfsoc_get_groups_count(struct pinctrl_dev *pctldev)
901 return ARRAY_SIZE(sirfsoc_pin_groups);
904 static const char *sirfsoc_get_group_name(struct pinctrl_dev *pctldev,
905 unsigned selector)
907 return sirfsoc_pin_groups[selector].name;
910 static int sirfsoc_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector,
911 const unsigned **pins,
912 unsigned *num_pins)
914 *pins = sirfsoc_pin_groups[selector].pins;
915 *num_pins = sirfsoc_pin_groups[selector].num_pins;
916 return 0;
919 static void sirfsoc_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
920 unsigned offset)
922 seq_printf(s, " " DRIVER_NAME);
925 static struct pinctrl_ops sirfsoc_pctrl_ops = {
926 .get_groups_count = sirfsoc_get_groups_count,
927 .get_group_name = sirfsoc_get_group_name,
928 .get_group_pins = sirfsoc_get_group_pins,
929 .pin_dbg_show = sirfsoc_pin_dbg_show,
932 struct sirfsoc_pmx_func {
933 const char *name;
934 const char * const *groups;
935 const unsigned num_groups;
936 const struct sirfsoc_padmux *padmux;
939 static const char * const lcd_16bitsgrp[] = { "lcd_16bitsgrp" };
940 static const char * const lcd_18bitsgrp[] = { "lcd_18bitsgrp" };
941 static const char * const lcd_24bitsgrp[] = { "lcd_24bitsgrp" };
942 static const char * const lcdromgrp[] = { "lcdromgrp" };
943 static const char * const uart0grp[] = { "uart0grp" };
944 static const char * const uart1grp[] = { "uart1grp" };
945 static const char * const uart2grp[] = { "uart2grp" };
946 static const char * const uart2_nostreamctrlgrp[] = { "uart2_nostreamctrlgrp" };
947 static const char * const usp0grp[] = { "usp0grp" };
948 static const char * const usp1grp[] = { "usp1grp" };
949 static const char * const usp2grp[] = { "usp2grp" };
950 static const char * const i2c0grp[] = { "i2c0grp" };
951 static const char * const i2c1grp[] = { "i2c1grp" };
952 static const char * const pwm0grp[] = { "pwm0grp" };
953 static const char * const pwm1grp[] = { "pwm1grp" };
954 static const char * const pwm2grp[] = { "pwm2grp" };
955 static const char * const pwm3grp[] = { "pwm3grp" };
956 static const char * const vipgrp[] = { "vipgrp" };
957 static const char * const vipromgrp[] = { "vipromgrp" };
958 static const char * const warm_rstgrp[] = { "warm_rstgrp" };
959 static const char * const cko0grp[] = { "cko0grp" };
960 static const char * const cko1grp[] = { "cko1grp" };
961 static const char * const sdmmc0grp[] = { "sdmmc0grp" };
962 static const char * const sdmmc1grp[] = { "sdmmc1grp" };
963 static const char * const sdmmc2grp[] = { "sdmmc2grp" };
964 static const char * const sdmmc3grp[] = { "sdmmc3grp" };
965 static const char * const sdmmc4grp[] = { "sdmmc4grp" };
966 static const char * const sdmmc5grp[] = { "sdmmc5grp" };
967 static const char * const usb0_utmi_drvbusgrp[] = { "usb0_utmi_drvbusgrp" };
968 static const char * const usb1_utmi_drvbusgrp[] = { "usb1_utmi_drvbusgrp" };
969 static const char * const pulse_countgrp[] = { "pulse_countgrp" };
970 static const char * const i2sgrp[] = { "i2sgrp" };
971 static const char * const ac97grp[] = { "ac97grp" };
972 static const char * const nandgrp[] = { "nandgrp" };
973 static const char * const spi0grp[] = { "spi0grp" };
974 static const char * const spi1grp[] = { "spi1grp" };
975 static const char * const gpsgrp[] = { "gpsgrp" };
977 #define SIRFSOC_PMX_FUNCTION(n, g, m) \
979 .name = n, \
980 .groups = g, \
981 .num_groups = ARRAY_SIZE(g), \
982 .padmux = &m, \
985 static const struct sirfsoc_pmx_func sirfsoc_pmx_functions[] = {
986 SIRFSOC_PMX_FUNCTION("lcd_16bits", lcd_16bitsgrp, lcd_16bits_padmux),
987 SIRFSOC_PMX_FUNCTION("lcd_18bits", lcd_18bitsgrp, lcd_18bits_padmux),
988 SIRFSOC_PMX_FUNCTION("lcd_24bits", lcd_24bitsgrp, lcd_24bits_padmux),
989 SIRFSOC_PMX_FUNCTION("lcdrom", lcdromgrp, lcdrom_padmux),
990 SIRFSOC_PMX_FUNCTION("uart0", uart0grp, uart0_padmux),
991 SIRFSOC_PMX_FUNCTION("uart1", uart1grp, uart1_padmux),
992 SIRFSOC_PMX_FUNCTION("uart2", uart2grp, uart2_padmux),
993 SIRFSOC_PMX_FUNCTION("uart2_nostreamctrl", uart2_nostreamctrlgrp, uart2_nostreamctrl_padmux),
994 SIRFSOC_PMX_FUNCTION("usp0", usp0grp, usp0_padmux),
995 SIRFSOC_PMX_FUNCTION("usp1", usp1grp, usp1_padmux),
996 SIRFSOC_PMX_FUNCTION("usp2", usp2grp, usp2_padmux),
997 SIRFSOC_PMX_FUNCTION("i2c0", i2c0grp, i2c0_padmux),
998 SIRFSOC_PMX_FUNCTION("i2c1", i2c1grp, i2c1_padmux),
999 SIRFSOC_PMX_FUNCTION("pwm0", pwm0grp, pwm0_padmux),
1000 SIRFSOC_PMX_FUNCTION("pwm1", pwm1grp, pwm1_padmux),
1001 SIRFSOC_PMX_FUNCTION("pwm2", pwm2grp, pwm2_padmux),
1002 SIRFSOC_PMX_FUNCTION("pwm3", pwm3grp, pwm3_padmux),
1003 SIRFSOC_PMX_FUNCTION("vip", vipgrp, vip_padmux),
1004 SIRFSOC_PMX_FUNCTION("viprom", vipromgrp, viprom_padmux),
1005 SIRFSOC_PMX_FUNCTION("warm_rst", warm_rstgrp, warm_rst_padmux),
1006 SIRFSOC_PMX_FUNCTION("cko0", cko0grp, cko0_padmux),
1007 SIRFSOC_PMX_FUNCTION("cko1", cko1grp, cko1_padmux),
1008 SIRFSOC_PMX_FUNCTION("sdmmc0", sdmmc0grp, sdmmc0_padmux),
1009 SIRFSOC_PMX_FUNCTION("sdmmc1", sdmmc1grp, sdmmc1_padmux),
1010 SIRFSOC_PMX_FUNCTION("sdmmc2", sdmmc2grp, sdmmc2_padmux),
1011 SIRFSOC_PMX_FUNCTION("sdmmc3", sdmmc3grp, sdmmc3_padmux),
1012 SIRFSOC_PMX_FUNCTION("sdmmc4", sdmmc4grp, sdmmc4_padmux),
1013 SIRFSOC_PMX_FUNCTION("sdmmc5", sdmmc5grp, sdmmc5_padmux),
1014 SIRFSOC_PMX_FUNCTION("usb0_utmi_drvbus", usb0_utmi_drvbusgrp, usb0_utmi_drvbus_padmux),
1015 SIRFSOC_PMX_FUNCTION("usb1_utmi_drvbus", usb1_utmi_drvbusgrp, usb1_utmi_drvbus_padmux),
1016 SIRFSOC_PMX_FUNCTION("pulse_count", pulse_countgrp, pulse_count_padmux),
1017 SIRFSOC_PMX_FUNCTION("i2s", i2sgrp, i2s_padmux),
1018 SIRFSOC_PMX_FUNCTION("ac97", ac97grp, ac97_padmux),
1019 SIRFSOC_PMX_FUNCTION("nand", nandgrp, nand_padmux),
1020 SIRFSOC_PMX_FUNCTION("spi0", spi0grp, spi0_padmux),
1021 SIRFSOC_PMX_FUNCTION("spi1", spi1grp, spi1_padmux),
1022 SIRFSOC_PMX_FUNCTION("gps", gpsgrp, gps_padmux),
1025 static void sirfsoc_pinmux_endisable(struct sirfsoc_pmx *spmx, unsigned selector,
1026 bool enable)
1028 int i;
1029 const struct sirfsoc_padmux *mux = sirfsoc_pmx_functions[selector].padmux;
1030 const struct sirfsoc_muxmask *mask = mux->muxmask;
1032 for (i = 0; i < mux->muxmask_counts; i++) {
1033 u32 muxval;
1034 muxval = readl(spmx->gpio_virtbase + SIRFSOC_GPIO_PAD_EN(mask[i].group));
1035 if (enable)
1036 muxval = muxval & ~mask[i].mask;
1037 else
1038 muxval = muxval | mask[i].mask;
1039 writel(muxval, spmx->gpio_virtbase + SIRFSOC_GPIO_PAD_EN(mask[i].group));
1042 if (mux->funcmask && enable) {
1043 u32 func_en_val;
1044 func_en_val =
1045 readl(spmx->rsc_virtbase + SIRFSOC_RSC_PIN_MUX);
1046 func_en_val =
1047 (func_en_val & ~mux->funcmask) | (mux->
1048 funcval);
1049 writel(func_en_val, spmx->rsc_virtbase + SIRFSOC_RSC_PIN_MUX);
1053 static int sirfsoc_pinmux_enable(struct pinctrl_dev *pmxdev, unsigned selector,
1054 unsigned group)
1056 struct sirfsoc_pmx *spmx;
1058 spmx = pinctrl_dev_get_drvdata(pmxdev);
1059 sirfsoc_pinmux_endisable(spmx, selector, true);
1061 return 0;
1064 static void sirfsoc_pinmux_disable(struct pinctrl_dev *pmxdev, unsigned selector,
1065 unsigned group)
1067 struct sirfsoc_pmx *spmx;
1069 spmx = pinctrl_dev_get_drvdata(pmxdev);
1070 sirfsoc_pinmux_endisable(spmx, selector, false);
1073 static int sirfsoc_pinmux_get_funcs_count(struct pinctrl_dev *pmxdev)
1075 return ARRAY_SIZE(sirfsoc_pmx_functions);
1078 static const char *sirfsoc_pinmux_get_func_name(struct pinctrl_dev *pctldev,
1079 unsigned selector)
1081 return sirfsoc_pmx_functions[selector].name;
1084 static int sirfsoc_pinmux_get_groups(struct pinctrl_dev *pctldev, unsigned selector,
1085 const char * const **groups,
1086 unsigned * const num_groups)
1088 *groups = sirfsoc_pmx_functions[selector].groups;
1089 *num_groups = sirfsoc_pmx_functions[selector].num_groups;
1090 return 0;
1093 static int sirfsoc_pinmux_request_gpio(struct pinctrl_dev *pmxdev,
1094 struct pinctrl_gpio_range *range, unsigned offset)
1096 struct sirfsoc_pmx *spmx;
1098 int group = range->id;
1100 u32 muxval;
1102 spmx = pinctrl_dev_get_drvdata(pmxdev);
1104 muxval = readl(spmx->gpio_virtbase + SIRFSOC_GPIO_PAD_EN(group));
1105 muxval = muxval | (1 << (offset - range->pin_base));
1106 writel(muxval, spmx->gpio_virtbase + SIRFSOC_GPIO_PAD_EN(group));
1108 return 0;
1111 static struct pinmux_ops sirfsoc_pinmux_ops = {
1112 .enable = sirfsoc_pinmux_enable,
1113 .disable = sirfsoc_pinmux_disable,
1114 .get_functions_count = sirfsoc_pinmux_get_funcs_count,
1115 .get_function_name = sirfsoc_pinmux_get_func_name,
1116 .get_function_groups = sirfsoc_pinmux_get_groups,
1117 .gpio_request_enable = sirfsoc_pinmux_request_gpio,
1120 static struct pinctrl_desc sirfsoc_pinmux_desc = {
1121 .name = DRIVER_NAME,
1122 .pins = sirfsoc_pads,
1123 .npins = ARRAY_SIZE(sirfsoc_pads),
1124 .pctlops = &sirfsoc_pctrl_ops,
1125 .pmxops = &sirfsoc_pinmux_ops,
1126 .owner = THIS_MODULE,
1130 * Todo: bind irq_chip to every pinctrl_gpio_range
1132 static struct pinctrl_gpio_range sirfsoc_gpio_ranges[] = {
1134 .name = "sirfsoc-gpio*",
1135 .id = 0,
1136 .base = 0,
1137 .pin_base = 0,
1138 .npins = 32,
1139 }, {
1140 .name = "sirfsoc-gpio*",
1141 .id = 1,
1142 .base = 32,
1143 .pin_base = 32,
1144 .npins = 32,
1145 }, {
1146 .name = "sirfsoc-gpio*",
1147 .id = 2,
1148 .base = 64,
1149 .pin_base = 64,
1150 .npins = 32,
1151 }, {
1152 .name = "sirfsoc-gpio*",
1153 .id = 3,
1154 .base = 96,
1155 .pin_base = 96,
1156 .npins = 19,
1160 static void __iomem *sirfsoc_rsc_of_iomap(void)
1162 const struct of_device_id rsc_ids[] = {
1163 { .compatible = "sirf,prima2-rsc" },
1166 struct device_node *np;
1168 np = of_find_matching_node(NULL, rsc_ids);
1169 if (!np)
1170 panic("unable to find compatible rsc node in dtb\n");
1172 return of_iomap(np, 0);
1175 static int __devinit sirfsoc_pinmux_probe(struct platform_device *pdev)
1177 int ret;
1178 struct sirfsoc_pmx *spmx;
1179 struct device_node *np = pdev->dev.of_node;
1180 int i;
1182 /* Create state holders etc for this driver */
1183 spmx = devm_kzalloc(&pdev->dev, sizeof(*spmx), GFP_KERNEL);
1184 if (!spmx)
1185 return -ENOMEM;
1187 spmx->dev = &pdev->dev;
1189 platform_set_drvdata(pdev, spmx);
1191 spmx->gpio_virtbase = of_iomap(np, 0);
1192 if (!spmx->gpio_virtbase) {
1193 ret = -ENOMEM;
1194 dev_err(&pdev->dev, "can't map gpio registers\n");
1195 goto out_no_gpio_remap;
1198 spmx->rsc_virtbase = sirfsoc_rsc_of_iomap();
1199 if (!spmx->rsc_virtbase) {
1200 ret = -ENOMEM;
1201 dev_err(&pdev->dev, "can't map rsc registers\n");
1202 goto out_no_rsc_remap;
1205 /* Now register the pin controller and all pins it handles */
1206 spmx->pmx = pinctrl_register(&sirfsoc_pinmux_desc, &pdev->dev, spmx);
1207 if (!spmx->pmx) {
1208 dev_err(&pdev->dev, "could not register SIRFSOC pinmux driver\n");
1209 ret = -EINVAL;
1210 goto out_no_pmx;
1213 for (i = 0; i < ARRAY_SIZE(sirfsoc_gpio_ranges); i++)
1214 pinctrl_add_gpio_range(spmx->pmx, &sirfsoc_gpio_ranges[i]);
1216 dev_info(&pdev->dev, "initialized SIRFSOC pinmux driver\n");
1218 return 0;
1220 out_no_pmx:
1221 iounmap(spmx->rsc_virtbase);
1222 out_no_rsc_remap:
1223 iounmap(spmx->gpio_virtbase);
1224 out_no_gpio_remap:
1225 platform_set_drvdata(pdev, NULL);
1226 return ret;
1229 static const struct of_device_id pinmux_ids[] __devinitconst = {
1230 { .compatible = "sirf,prima2-gpio-pinmux" },
1234 static struct platform_driver sirfsoc_pinmux_driver = {
1235 .driver = {
1236 .name = DRIVER_NAME,
1237 .owner = THIS_MODULE,
1238 .of_match_table = pinmux_ids,
1240 .probe = sirfsoc_pinmux_probe,
1243 static int __init sirfsoc_pinmux_init(void)
1245 return platform_driver_register(&sirfsoc_pinmux_driver);
1247 arch_initcall(sirfsoc_pinmux_init);
1249 static inline int sirfsoc_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
1251 struct sirfsoc_gpio_bank *bank = container_of(to_of_mm_gpio_chip(chip),
1252 struct sirfsoc_gpio_bank, chip);
1254 return irq_find_mapping(bank->domain, offset);
1257 static inline int sirfsoc_gpio_to_offset(unsigned int gpio)
1259 return gpio % SIRFSOC_GPIO_BANK_SIZE;
1262 static inline struct sirfsoc_gpio_bank *sirfsoc_gpio_to_bank(unsigned int gpio)
1264 return &sgpio_bank[gpio / SIRFSOC_GPIO_BANK_SIZE];
1267 void sirfsoc_gpio_set_pull(unsigned gpio, unsigned mode)
1269 struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(gpio);
1270 int idx = sirfsoc_gpio_to_offset(gpio);
1271 u32 val, offset;
1272 unsigned long flags;
1274 offset = SIRFSOC_GPIO_CTRL(bank->id, idx);
1276 spin_lock_irqsave(&sgpio_lock, flags);
1278 val = readl(bank->chip.regs + offset);
1280 switch (mode) {
1281 case SIRFSOC_GPIO_PULL_NONE:
1282 val &= ~SIRFSOC_GPIO_CTL_PULL_MASK;
1283 break;
1284 case SIRFSOC_GPIO_PULL_UP:
1285 val |= SIRFSOC_GPIO_CTL_PULL_MASK;
1286 val |= SIRFSOC_GPIO_CTL_PULL_HIGH;
1287 break;
1288 case SIRFSOC_GPIO_PULL_DOWN:
1289 val |= SIRFSOC_GPIO_CTL_PULL_MASK;
1290 val &= ~SIRFSOC_GPIO_CTL_PULL_HIGH;
1291 break;
1292 default:
1293 break;
1296 writel(val, bank->chip.regs + offset);
1298 spin_unlock_irqrestore(&sgpio_lock, flags);
1300 EXPORT_SYMBOL(sirfsoc_gpio_set_pull);
1302 static inline struct sirfsoc_gpio_bank *sirfsoc_irqchip_to_bank(struct gpio_chip *chip)
1304 return container_of(to_of_mm_gpio_chip(chip), struct sirfsoc_gpio_bank, chip);
1307 static void sirfsoc_gpio_irq_ack(struct irq_data *d)
1309 struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d);
1310 int idx = d->hwirq % SIRFSOC_GPIO_BANK_SIZE;
1311 u32 val, offset;
1312 unsigned long flags;
1314 offset = SIRFSOC_GPIO_CTRL(bank->id, idx);
1316 spin_lock_irqsave(&sgpio_lock, flags);
1318 val = readl(bank->chip.regs + offset);
1320 writel(val, bank->chip.regs + offset);
1322 spin_unlock_irqrestore(&sgpio_lock, flags);
1325 static void __sirfsoc_gpio_irq_mask(struct sirfsoc_gpio_bank *bank, int idx)
1327 u32 val, offset;
1328 unsigned long flags;
1330 offset = SIRFSOC_GPIO_CTRL(bank->id, idx);
1332 spin_lock_irqsave(&sgpio_lock, flags);
1334 val = readl(bank->chip.regs + offset);
1335 val &= ~SIRFSOC_GPIO_CTL_INTR_EN_MASK;
1336 val &= ~SIRFSOC_GPIO_CTL_INTR_STS_MASK;
1337 writel(val, bank->chip.regs + offset);
1339 spin_unlock_irqrestore(&sgpio_lock, flags);
1342 static void sirfsoc_gpio_irq_mask(struct irq_data *d)
1344 struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d);
1346 __sirfsoc_gpio_irq_mask(bank, d->hwirq % SIRFSOC_GPIO_BANK_SIZE);
1349 static void sirfsoc_gpio_irq_unmask(struct irq_data *d)
1351 struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d);
1352 int idx = d->hwirq % SIRFSOC_GPIO_BANK_SIZE;
1353 u32 val, offset;
1354 unsigned long flags;
1356 offset = SIRFSOC_GPIO_CTRL(bank->id, idx);
1358 spin_lock_irqsave(&sgpio_lock, flags);
1360 val = readl(bank->chip.regs + offset);
1361 val &= ~SIRFSOC_GPIO_CTL_INTR_STS_MASK;
1362 val |= SIRFSOC_GPIO_CTL_INTR_EN_MASK;
1363 writel(val, bank->chip.regs + offset);
1365 spin_unlock_irqrestore(&sgpio_lock, flags);
1368 static int sirfsoc_gpio_irq_type(struct irq_data *d, unsigned type)
1370 struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d);
1371 int idx = d->hwirq % SIRFSOC_GPIO_BANK_SIZE;
1372 u32 val, offset;
1373 unsigned long flags;
1375 offset = SIRFSOC_GPIO_CTRL(bank->id, idx);
1377 spin_lock_irqsave(&sgpio_lock, flags);
1379 val = readl(bank->chip.regs + offset);
1380 val &= ~SIRFSOC_GPIO_CTL_INTR_STS_MASK;
1382 switch (type) {
1383 case IRQ_TYPE_NONE:
1384 break;
1385 case IRQ_TYPE_EDGE_RISING:
1386 val |= SIRFSOC_GPIO_CTL_INTR_HIGH_MASK | SIRFSOC_GPIO_CTL_INTR_TYPE_MASK;
1387 val &= ~SIRFSOC_GPIO_CTL_INTR_LOW_MASK;
1388 break;
1389 case IRQ_TYPE_EDGE_FALLING:
1390 val &= ~SIRFSOC_GPIO_CTL_INTR_HIGH_MASK;
1391 val |= SIRFSOC_GPIO_CTL_INTR_LOW_MASK | SIRFSOC_GPIO_CTL_INTR_TYPE_MASK;
1392 break;
1393 case IRQ_TYPE_EDGE_BOTH:
1394 val |= SIRFSOC_GPIO_CTL_INTR_HIGH_MASK | SIRFSOC_GPIO_CTL_INTR_LOW_MASK |
1395 SIRFSOC_GPIO_CTL_INTR_TYPE_MASK;
1396 break;
1397 case IRQ_TYPE_LEVEL_LOW:
1398 val &= ~(SIRFSOC_GPIO_CTL_INTR_HIGH_MASK | SIRFSOC_GPIO_CTL_INTR_TYPE_MASK);
1399 val |= SIRFSOC_GPIO_CTL_INTR_LOW_MASK;
1400 break;
1401 case IRQ_TYPE_LEVEL_HIGH:
1402 val |= SIRFSOC_GPIO_CTL_INTR_HIGH_MASK;
1403 val &= ~(SIRFSOC_GPIO_CTL_INTR_LOW_MASK | SIRFSOC_GPIO_CTL_INTR_TYPE_MASK);
1404 break;
1407 writel(val, bank->chip.regs + offset);
1409 spin_unlock_irqrestore(&sgpio_lock, flags);
1411 return 0;
1414 static struct irq_chip sirfsoc_irq_chip = {
1415 .name = "sirf-gpio-irq",
1416 .irq_ack = sirfsoc_gpio_irq_ack,
1417 .irq_mask = sirfsoc_gpio_irq_mask,
1418 .irq_unmask = sirfsoc_gpio_irq_unmask,
1419 .irq_set_type = sirfsoc_gpio_irq_type,
1422 static void sirfsoc_gpio_handle_irq(unsigned int irq, struct irq_desc *desc)
1424 struct sirfsoc_gpio_bank *bank = irq_get_handler_data(irq);
1425 u32 status, ctrl;
1426 int idx = 0;
1427 unsigned int first_irq;
1429 status = readl(bank->chip.regs + SIRFSOC_GPIO_INT_STATUS(bank->id));
1430 if (!status) {
1431 printk(KERN_WARNING
1432 "%s: gpio id %d status %#x no interrupt is flaged\n",
1433 __func__, bank->id, status);
1434 handle_bad_irq(irq, desc);
1435 return;
1438 first_irq = bank->domain->revmap_data.legacy.first_irq;
1440 while (status) {
1441 ctrl = readl(bank->chip.regs + SIRFSOC_GPIO_CTRL(bank->id, idx));
1444 * Here we must check whether the corresponding GPIO's interrupt
1445 * has been enabled, otherwise just skip it
1447 if ((status & 0x1) && (ctrl & SIRFSOC_GPIO_CTL_INTR_EN_MASK)) {
1448 pr_debug("%s: gpio id %d idx %d happens\n",
1449 __func__, bank->id, idx);
1450 generic_handle_irq(first_irq + idx);
1453 idx++;
1454 status = status >> 1;
1458 static inline void sirfsoc_gpio_set_input(struct sirfsoc_gpio_bank *bank, unsigned ctrl_offset)
1460 u32 val;
1462 val = readl(bank->chip.regs + ctrl_offset);
1463 val &= ~SIRFSOC_GPIO_CTL_OUT_EN_MASK;
1464 writel(val, bank->chip.regs + ctrl_offset);
1467 static int sirfsoc_gpio_request(struct gpio_chip *chip, unsigned offset)
1469 struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip);
1470 unsigned long flags;
1472 if (pinctrl_request_gpio(chip->base + offset))
1473 return -ENODEV;
1475 spin_lock_irqsave(&bank->lock, flags);
1478 * default status:
1479 * set direction as input and mask irq
1481 sirfsoc_gpio_set_input(bank, SIRFSOC_GPIO_CTRL(bank->id, offset));
1482 __sirfsoc_gpio_irq_mask(bank, offset);
1484 spin_unlock_irqrestore(&bank->lock, flags);
1486 return 0;
1489 static void sirfsoc_gpio_free(struct gpio_chip *chip, unsigned offset)
1491 struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip);
1492 unsigned long flags;
1494 spin_lock_irqsave(&bank->lock, flags);
1496 __sirfsoc_gpio_irq_mask(bank, offset);
1497 sirfsoc_gpio_set_input(bank, SIRFSOC_GPIO_CTRL(bank->id, offset));
1499 spin_unlock_irqrestore(&bank->lock, flags);
1501 pinctrl_free_gpio(chip->base + offset);
1504 static int sirfsoc_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
1506 struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip);
1507 int idx = sirfsoc_gpio_to_offset(gpio);
1508 unsigned long flags;
1509 unsigned offset;
1511 offset = SIRFSOC_GPIO_CTRL(bank->id, idx);
1513 spin_lock_irqsave(&bank->lock, flags);
1515 sirfsoc_gpio_set_input(bank, offset);
1517 spin_unlock_irqrestore(&bank->lock, flags);
1519 return 0;
1522 static inline void sirfsoc_gpio_set_output(struct sirfsoc_gpio_bank *bank, unsigned offset,
1523 int value)
1525 u32 out_ctrl;
1526 unsigned long flags;
1528 spin_lock_irqsave(&bank->lock, flags);
1530 out_ctrl = readl(bank->chip.regs + offset);
1531 if (value)
1532 out_ctrl |= SIRFSOC_GPIO_CTL_DATAOUT_MASK;
1533 else
1534 out_ctrl &= ~SIRFSOC_GPIO_CTL_DATAOUT_MASK;
1536 out_ctrl &= ~SIRFSOC_GPIO_CTL_INTR_EN_MASK;
1537 out_ctrl |= SIRFSOC_GPIO_CTL_OUT_EN_MASK;
1538 writel(out_ctrl, bank->chip.regs + offset);
1540 spin_unlock_irqrestore(&bank->lock, flags);
1543 static int sirfsoc_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int value)
1545 struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip);
1546 int idx = sirfsoc_gpio_to_offset(gpio);
1547 u32 offset;
1548 unsigned long flags;
1550 offset = SIRFSOC_GPIO_CTRL(bank->id, idx);
1552 spin_lock_irqsave(&sgpio_lock, flags);
1554 sirfsoc_gpio_set_output(bank, offset, value);
1556 spin_unlock_irqrestore(&sgpio_lock, flags);
1558 return 0;
1561 static int sirfsoc_gpio_get_value(struct gpio_chip *chip, unsigned offset)
1563 struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip);
1564 u32 val;
1565 unsigned long flags;
1567 spin_lock_irqsave(&bank->lock, flags);
1569 val = readl(bank->chip.regs + SIRFSOC_GPIO_CTRL(bank->id, offset));
1571 spin_unlock_irqrestore(&bank->lock, flags);
1573 return !!(val & SIRFSOC_GPIO_CTL_DATAIN_MASK);
1576 static void sirfsoc_gpio_set_value(struct gpio_chip *chip, unsigned offset,
1577 int value)
1579 struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip);
1580 u32 ctrl;
1581 unsigned long flags;
1583 spin_lock_irqsave(&bank->lock, flags);
1585 ctrl = readl(bank->chip.regs + SIRFSOC_GPIO_CTRL(bank->id, offset));
1586 if (value)
1587 ctrl |= SIRFSOC_GPIO_CTL_DATAOUT_MASK;
1588 else
1589 ctrl &= ~SIRFSOC_GPIO_CTL_DATAOUT_MASK;
1590 writel(ctrl, bank->chip.regs + SIRFSOC_GPIO_CTRL(bank->id, offset));
1592 spin_unlock_irqrestore(&bank->lock, flags);
1595 int sirfsoc_gpio_irq_map(struct irq_domain *d, unsigned int irq,
1596 irq_hw_number_t hwirq)
1598 struct sirfsoc_gpio_bank *bank = d->host_data;
1600 if (!bank)
1601 return -EINVAL;
1603 irq_set_chip(irq, &sirfsoc_irq_chip);
1604 irq_set_handler(irq, handle_level_irq);
1605 irq_set_chip_data(irq, bank);
1606 set_irq_flags(irq, IRQF_VALID);
1608 return 0;
1611 const struct irq_domain_ops sirfsoc_gpio_irq_simple_ops = {
1612 .map = sirfsoc_gpio_irq_map,
1613 .xlate = irq_domain_xlate_twocell,
1616 static int __devinit sirfsoc_gpio_probe(struct device_node *np)
1618 int i, err = 0;
1619 struct sirfsoc_gpio_bank *bank;
1620 void *regs;
1621 struct platform_device *pdev;
1623 pdev = of_find_device_by_node(np);
1624 if (!pdev)
1625 return -ENODEV;
1627 regs = of_iomap(np, 0);
1628 if (!regs)
1629 return -ENOMEM;
1631 for (i = 0; i < SIRFSOC_GPIO_NO_OF_BANKS; i++) {
1632 bank = &sgpio_bank[i];
1633 spin_lock_init(&bank->lock);
1634 bank->chip.gc.request = sirfsoc_gpio_request;
1635 bank->chip.gc.free = sirfsoc_gpio_free;
1636 bank->chip.gc.direction_input = sirfsoc_gpio_direction_input;
1637 bank->chip.gc.get = sirfsoc_gpio_get_value;
1638 bank->chip.gc.direction_output = sirfsoc_gpio_direction_output;
1639 bank->chip.gc.set = sirfsoc_gpio_set_value;
1640 bank->chip.gc.to_irq = sirfsoc_gpio_to_irq;
1641 bank->chip.gc.base = i * SIRFSOC_GPIO_BANK_SIZE;
1642 bank->chip.gc.ngpio = SIRFSOC_GPIO_BANK_SIZE;
1643 bank->chip.gc.label = kstrdup(np->full_name, GFP_KERNEL);
1644 bank->chip.gc.of_node = np;
1645 bank->chip.regs = regs;
1646 bank->id = i;
1647 bank->parent_irq = platform_get_irq(pdev, i);
1648 if (bank->parent_irq < 0) {
1649 err = bank->parent_irq;
1650 goto out;
1653 err = gpiochip_add(&bank->chip.gc);
1654 if (err) {
1655 pr_err("%s: error in probe function with status %d\n",
1656 np->full_name, err);
1657 goto out;
1660 bank->domain = irq_domain_add_legacy(np, SIRFSOC_GPIO_BANK_SIZE,
1661 SIRFSOC_GPIO_IRQ_START + i * SIRFSOC_GPIO_BANK_SIZE, 0,
1662 &sirfsoc_gpio_irq_simple_ops, bank);
1664 if (!bank->domain) {
1665 pr_err("%s: Failed to create irqdomain\n", np->full_name);
1666 err = -ENOSYS;
1667 goto out;
1670 irq_set_chained_handler(bank->parent_irq, sirfsoc_gpio_handle_irq);
1671 irq_set_handler_data(bank->parent_irq, bank);
1674 return 0;
1676 out:
1677 iounmap(regs);
1678 return err;
1681 static int __init sirfsoc_gpio_init(void)
1684 struct device_node *np;
1686 np = of_find_matching_node(NULL, pinmux_ids);
1688 if (!np)
1689 return -ENODEV;
1691 return sirfsoc_gpio_probe(np);
1693 subsys_initcall(sirfsoc_gpio_init);
1695 MODULE_AUTHOR("Rongjun Ying <rongjun.ying@csr.com>, "
1696 "Yuping Luo <yuping.luo@csr.com>, "
1697 "Barry Song <baohua.song@csr.com>");
1698 MODULE_DESCRIPTION("SIRFSOC pin control driver");
1699 MODULE_LICENSE("GPL");