]> rtime.felk.cvut.cz Git - vajnamar/linux-xlnx.git/blob - arch/arm/mach-zynq/slcr.c
Merge tag 'v3.10' into master-next
[vajnamar/linux-xlnx.git] / arch / arm / mach-zynq / slcr.c
1 /*
2  * Xilinx SLCR driver
3  *
4  * Copyright (c) 2011-2013 Xilinx Inc.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  *
11  * You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free
13  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
14  * 02139, USA.
15  */
16
17 #include <linux/export.h>
18 #include <linux/io.h>
19 #include <linux/fs.h>
20 #include <linux/interrupt.h>
21 #include <linux/init.h>
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/of_address.h>
25 #include <linux/uaccess.h>
26 #include <linux/platform_device.h>
27 #include <linux/slab.h>
28 #include <linux/string.h>
29 #include <linux/clk/zynq.h>
30 #include "common.h"
31
32 #define SLCR_UNLOCK_MAGIC               0xDF0D
33 #define SLCR_UNLOCK                     0x8   /* SCLR unlock register */
34
35 #define DRIVER_NAME "xslcr"
36
37 #define XSLCR_LOCK                      0x4   /* SLCR lock register */
38 #define XSLCR_UNLOCK                    0x8   /* SCLR unlock register */
39 #define XSLCR_PSS_RST_CTRL_OFFSET       0x200 /* PSS Software Reset Control */
40 #define XSLCR_DDR_RST_CTRL_OFFSET       0x204 /* DDR Software Reset Control */
41 #define XSLCR_AMBA_RST_CTRL_OFFSET      0x208 /* AMBA Software Reset Control */
42 #define XSLCR_DMAC_RST_CTRL_OFFSET      0x20C /* DMAC Software Reset Control */
43 #define XSLCR_USB_RST_CTRL_OFFSET       0x210 /* USB Software Reset Control */
44 #define XSLCR_EMAC_RST_CTRL_OFFSET      0x214 /* EMAC Software Reset Control */
45 #define XSLCR_SDIO_RST_CTRL_OFFSET      0x218 /* SDIO Software Reset Control */
46 #define XSLCR_SPI_RST_CTRL_OFFSET       0x21C /* SPI Software Reset Control */
47 #define XSLCR_CAN_RST_CTRL_OFFSET       0x220 /* CAN Software Reset Control */
48 #define XSLCR_I2C_RST_CTRL_OFFSET       0x224 /* I2C Software Reset Control */
49 #define XSLCR_UART_RST_CTRL_OFFSET      0x228 /* UART Software Reset Control */
50 #define XSLCR_GPIO_RST_CTRL_OFFSET      0x22C /* GPIO Software Reset Control */
51 #define XSLCR_QSPI_RST_CTRL_OFFSET      0x230 /* QSpI Software Reset Control */
52 #define XSLCR_SMC_RST_CTRL_OFFSET       0x234 /* SMC Software Reset Control */
53 #define XSLCR_OCM_RST_CTRL_OFFSET       0x238 /* OCM Software Reset Control */
54 #define XSLCR_DEVC_RST_CTRL_OFFSET      0x23C /* Dev Cfg SW Reset Control */
55 #define XSLCR_FPGA_RST_CTRL_OFFSET      0x240 /* FPGA Software Reset Control */
56 #define XSLCR_A9_CPU_RST_CTRL           0x244 /* CPU Software Reset Control */
57 #define XSLCR_REBOOT_STATUS             0x258 /* PS Reboot Status */
58 #define XSLCR_MIO_PIN_00_OFFSET         0x700 /* MIO PIN0 control register */
59 #define XSLCR_LVL_SHFTR_EN_OFFSET       0x900 /* Level Shifters Enable */
60
61 #define XSLCR_MIO_L0_SHIFT              1
62 #define XSLCR_MIO_L1_SHIFT              2
63 #define XSLCR_MIO_L2_SHIFT              3
64 #define XSLCR_MIO_L3_SHIFT              5
65
66 #define XSLCR_MIO_LMASK                 0x000000FE
67
68 #define XSLCR_MIO_PIN_XX_TRI_ENABLE     0x00000001
69
70 /* The following constants define L0 Mux Peripheral Enables */
71 #define XSLCR_MIO_PIN_EMAC_ENABLE       (0x01 << XSLCR_MIO_L0_SHIFT)
72 #define XSLCR_MIO_PIN_QSPI_ENABLE       (0x01 << XSLCR_MIO_L0_SHIFT)
73
74 /* The following constants define L1 Mux Enables */
75 #define XSLCR_MIO_PIN_USB_ENABLE        (0x01 << XSLCR_MIO_L1_SHIFT)
76 #define XSLCR_MIO_PIN_TRACE_PORT_ENABLE (0x01 << XSLCR_MIO_L1_SHIFT)
77
78 /* The following constants define L2 Mux Peripheral Enables */
79 #define XSLCR_MIO_PIN_SRAM_NOR_ENABLE   (0x01 << XSLCR_MIO_L2_SHIFT)
80 #define XSLCR_MIO_PIN_NAND_ENABLE       (0x02 << XSLCR_MIO_L2_SHIFT)
81
82 /* The following constants define L3 Mux Peripheral Enables */
83 #define XSLCR_MIO_PIN_GPIO_ENABLE       (0x00 << XSLCR_MIO_L3_SHIFT)
84 #define XSLCR_MIO_PIN_CAN_ENABLE        (0x01 << XSLCR_MIO_L3_SHIFT)
85 #define XSLCR_MIO_PIN_IIC_ENABLE        (0x02 << XSLCR_MIO_L3_SHIFT)
86 #define XSLCR_MIO_PIN_WDT_ENABLE        (0x03 << XSLCR_MIO_L3_SHIFT)
87 #define XSLCR_MIO_PIN_JTAG_ENABLE       (0x03 << XSLCR_MIO_L3_SHIFT)
88 #define XSLCR_MIO_PIN_SDIO_ENABLE       (0x04 << XSLCR_MIO_L3_SHIFT)
89 #define XSLCR_MIO_PIN_MDIO0_ENABLE      (0x04 << XSLCR_MIO_L3_SHIFT)
90 #define XSLCR_MIO_PIN_MDIO1_ENABLE      (0x05 << XSLCR_MIO_L3_SHIFT)
91 #define XSLCR_MIO_PIN_SPI_ENABLE        (0x05 << XSLCR_MIO_L3_SHIFT)
92 #define XSLCR_MIO_PIN_TTC_ENABLE        (0x06 << XSLCR_MIO_L3_SHIFT)
93 #define XSLCR_MIO_PIN_UART_ENABLE       (0x07 << XSLCR_MIO_L3_SHIFT)
94
95 /* The following constants define the number of pins associated with each
96  * peripheral */
97 #define XSLCR_MIO_NUM_EMAC_PINS         12
98 #define XSLCR_MIO_NUM_USB_PINS          12
99 #define XSLCR_MIO_NUM_TRACE_DATA2_PINS  04
100 #define XSLCR_MIO_NUM_TRACE_DATA4_PINS  06
101 #define XSLCR_MIO_NUM_TRACE_DATA8_PINS  10
102 #define XSLCR_MIO_NUM_TRACE_DATA16_PINS 18
103 #define XSLCR_MIO_NUM_NAND_PINS         (21+1)
104 #define XSLCR_MIO_NUM_SMC_A25_PINS      01
105 #define XSLCR_MIO_NUM_SMC_CS_PINS       01
106 #define XSLCR_MIO_NUM_NAND_CS_PINS      01
107 #define XSLCR_MIO_NUM_SRAM_NOR_PINS     38
108 #define XSLCR_MIO_NUM_QSPI_PINS         05
109 #define XSLCR_MIO_NUM_QSPI_SEL_PINS     01
110 #define XSLCR_MIO_NUM_QSPI_FOC_PINS     01
111 #define XSLCR_MIO_NUM_GPIO_PINS         01
112 #define XSLCR_MIO_NUM_CAN_PINS          02
113 #define XSLCR_MIO_NUM_IIC_PINS          02
114 #define XSLCR_MIO_NUM_JTAG_PINS         04
115 #define XSLCR_MIO_NUM_WDT_PINS          02
116 #define XSLCR_MIO_NUM_MDIO_PINS         02
117 #define XSLCR_MIO_NUM_SDIO_PINS         06
118 #define XSLCR_MIO_NUM_SPI_PINS          06
119 #define XSLCR_MIO_NUM_TTC_PINS          02
120 #define XSLCR_MIO_NUM_UART_PINS         02
121
122 /* The following two constants define the indices of the MIO peripherals EMAC0/1
123  * in the array mio_periph_name */
124 #define MIO_EMAC0                       0
125 #define MIO_EMAC1                       1
126
127 #define XSLCR_MDIO_PIN_0                52
128 #define XSLCR_MIO_MAX_PIN               54
129
130 #define xslcr_writereg(offset, val)     __raw_writel(val, offset)
131 #define xslcr_readreg(offset)           __raw_readl(offset)
132
133
134 #define SLCR_PS_RST_CTRL_OFFSET         0x200 /* PS Software Reset Control */
135
136 #define SLCR_A9_CPU_CLKSTOP             0x10
137 #define SLCR_A9_CPU_RST                 0x1
138
139 #define SLCR_A9_CPU_RST_CTRL            0x244 /* CPU Software Reset Control */
140 #define SLCR_REBOOT_STATUS              0x258 /* PS Reboot Status */
141
142 void __iomem *zynq_slcr_base;
143
144 /**
145  * struct xslcr - slcr device data.
146  * @regs:       baseaddress of device.
147  * @io_lock:    spinlock used for synchronization.
148  *
149  */
150 struct xslcr {
151         void __iomem    *regs;
152         spinlock_t      io_lock;
153 };
154
155 static struct xslcr *slcr;
156
157 /**
158  * xslcr_mio - Holds information required to enable/disable a MIO peripheral.
159  *
160  * @set_pins:   Pointer to array of first pins in each pin set for this periph
161  * @max_sets:   Max pin sets for this periph
162  * @numpins:    Number of pins for this periph
163  * @enable_val: Enable value to assign a MIO pin to this periph
164  */
165 struct xslcr_mio {
166         const int *set_pins;
167         int max_sets;
168         int numpins;
169         u32 enable_val;
170 };
171
172 /**
173  * xslcr_periph_reset - Holds information required to reset a peripheral.
174  *
175  * @reg_offset: offset of the reset reg for the peripheral
176  * @reset_mask: mask to reset the peripheral
177  */
178 struct xslcr_periph_reset {
179         u32 reg_offset;
180         u32 reset_mask;
181 };
182
183 /* MIO peripheral names */
184 static const char * const mio_periph_name[] = {
185         "emac0",
186         "emac1",
187         "qspi0",
188         "qspi0_sel",
189         "qspi1",
190         "qspi1_sel",
191         "qspi_foc",
192         "trace_data2",
193         "trace_data4",
194         "trace_data8",
195         "trace_data16",
196         "usb0",
197         "usb1",
198         "smc_a25",
199         "smc_cs",
200         "sram_nor",
201         "nand",
202         "nand_cs",
203         "gpio00",
204         "gpio01",
205         "gpio02",
206         "gpio03",
207         "gpio04",
208         "gpio05",
209         "gpio06",
210         "gpio07",
211         "gpio08",
212         "gpio09",
213         "gpio10",
214         "gpio11",
215         "gpio12",
216         "gpio13",
217         "gpio14",
218         "gpio15",
219         "gpio16",
220         "gpio17",
221         "gpio18",
222         "gpio19",
223         "gpio20",
224         "gpio21",
225         "gpio22",
226         "gpio23",
227         "gpio24",
228         "gpio25",
229         "gpio26",
230         "gpio27",
231         "gpio28",
232         "gpio29",
233         "gpio30",
234         "gpio31",
235         "gpio32",
236         "gpio33",
237         "gpio34",
238         "gpio35",
239         "gpio36",
240         "gpio37",
241         "gpio38",
242         "gpio39",
243         "gpio40",
244         "gpio41",
245         "gpio42",
246         "gpio43",
247         "gpio44",
248         "gpio45",
249         "gpio46",
250         "gpio47",
251         "gpio48",
252         "gpio49",
253         "gpio50",
254         "gpio51",
255         "gpio52",
256         "gpio53",
257         "can0",
258         "can1",
259         "iic0",
260         "iic1",
261         "jtag",
262         "wdt",
263         "mdio0",
264         "sdio0",
265         "sdio1",
266         "mdio1",
267         "spi0",
268         "spi1",
269         "ttc0",
270         "ttc1",
271         "uart0",
272         "uart1",
273 };
274
275 /* Each element in the following array holds the active pinset of a MIO
276  * peripheral. The order of peripherals in this array is same as the order of
277  * peripheral names in the array mio_periph_name */
278 static u32 active_pinset[ARRAY_SIZE(mio_periph_name)];
279
280 /*
281  * The following arrays contain the first pin in each pin set of a MIO
282  * corresponding peripheral.
283  */
284 static const int emac0_pins[] = {
285         16
286 };
287
288 static const int emac1_pins[] = {
289         28, 40
290 };
291
292 static const int qspi0_pins[] = {
293         2
294 };
295
296 static const int qspi0_sel_pins[] = {
297         1
298 };
299
300 static const int qspi1_pins[] = {
301         9
302 };
303
304 static const int qspi1_sel_pins[] = {
305         0
306 };
307
308 static const int qspi_foc_pins[] = {
309         8
310 };
311
312 static const int trace_data2_pins[] = {
313         12, 24
314 };
315
316 static const int trace_data4_pins[] = {
317         10, 22
318 };
319
320 static const int trace_data8_pins[] = {
321         10
322 };
323
324 static const int trace_data16_pins[] = {
325         2
326 };
327
328 static const int usb0_pins[] = {
329         28
330 };
331
332 static const int usb1_pins[] = {
333         40
334 };
335
336 static const int smc_a25_pins[] = {
337         1
338 };
339
340 static const int smc_cs_pins[] = {
341         0, 1
342 };
343
344 static const int sram_nor_pins[] = {
345         2
346 };
347
348 static const int nand_pins[] = {
349         2
350 };
351
352 static const int nand_cs_pins[] = {
353         0
354 };
355
356 static const int gpio00_pins[] = {
357         0
358 };
359
360 static const int gpio01_pins[] = {
361         1
362 };
363
364
365 static const int gpio02_pins[] = {
366         2
367 };
368
369 static const int gpio03_pins[] = {
370         3
371 };
372
373 static const int gpio04_pins[] = {
374         4
375 };
376
377 static const int gpio05_pins[] = {
378         5
379 };
380
381 static const int gpio06_pins[] = {
382         6
383 };
384
385 static const int gpio07_pins[] = {
386         7
387 };
388
389
390 static const int gpio08_pins[] = {
391         8
392 };
393
394 static const int gpio09_pins[] = {
395         9
396 };
397
398
399 static const int gpio10_pins[] = {
400         10
401 };
402
403 static const int gpio11_pins[] = {
404         11
405 };
406
407 static const int gpio12_pins[] = {
408         12
409 };
410
411 static const int gpio13_pins[] = {
412         13
413 };
414
415 static const int gpio14_pins[] = {
416         14
417 };
418
419
420 static const int gpio15_pins[] = {
421         15
422 };
423
424 static const int gpio16_pins[] = {
425         16
426 };
427
428 static const int gpio17_pins[] = {
429         17
430 };
431
432 static const int gpio18_pins[] = {
433         18
434 };
435
436 static const int gpio19_pins[] = {
437         19
438 };
439
440 static const int gpio20_pins[] = {
441         20
442 };
443
444 static const int gpio21_pins[] = {
445         21
446 };
447
448
449 static const int gpio22_pins[] = {
450         22
451 };
452
453 static const int gpio23_pins[] = {
454         23
455 };
456
457 static const int gpio24_pins[] = {
458         24
459 };
460
461 static const int gpio25_pins[] = {
462         25
463 };
464
465 static const int gpio26_pins[] = {
466         26
467 };
468
469 static const int gpio27_pins[] = {
470         27
471 };
472
473
474 static const int gpio28_pins[] = {
475         28
476 };
477
478 static const int gpio29_pins[] = {
479         29
480 };
481
482
483 static const int gpio30_pins[] = {
484         30
485 };
486
487 static const int gpio31_pins[] = {
488         31
489 };
490
491 static const int gpio32_pins[] = {
492         32
493 };
494
495 static const int gpio33_pins[] = {
496         33
497 };
498
499 static const int gpio34_pins[] = {
500         34
501 };
502
503
504 static const int gpio35_pins[] = {
505         35
506 };
507
508 static const int gpio36_pins[] = {
509         36
510 };
511
512 static const int gpio37_pins[] = {
513         37
514 };
515
516 static const int gpio38_pins[] = {
517         38
518 };
519
520 static const int gpio39_pins[] = {
521         39
522 };
523
524 static const int gpio40_pins[] = {
525         40
526 };
527
528 static const int gpio41_pins[] = {
529         41
530 };
531
532 static const int gpio42_pins[] = {
533         42
534 };
535
536 static const int gpio43_pins[] = {
537         43
538 };
539
540 static const int gpio44_pins[] = {
541         44
542 };
543
544
545 static const int gpio45_pins[] = {
546         45
547 };
548
549 static const int gpio46_pins[] = {
550         46
551 };
552
553 static const int gpio47_pins[] = {
554         47
555 };
556
557 static const int gpio48_pins[] = {
558         48
559 };
560
561 static const int gpio49_pins[] = {
562         49
563 };
564
565 static const int gpio50_pins[] = {
566         50
567 };
568
569 static const int gpio51_pins[] = {
570         51
571 };
572
573 static const int gpio52_pins[] = {
574         52
575 };
576
577 static const int gpio53_pins[] = {
578         53
579 };
580
581 static const int can0_pins[] = {
582         10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50
583 };
584
585 static const int can1_pins[] = {
586         8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52
587 };
588
589 static const int iic0_pins[] = {
590         10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50
591 };
592
593 static const int iic1_pins[] = {
594         8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52
595 };
596
597 static const int jtag0_pins[] = {
598         10, 22, 34, 46
599 };
600
601 static const int wdt_pins[] = {
602         14, 26, 38, 50, 52
603 };
604
605 static const int mdio0_pins[] = {
606         52
607 };
608
609 static const int sdio0_pins[] = {
610         16, 28, 40
611 };
612
613 static const int sdio1_pins[] = {
614         10, 22, 34, 46
615 };
616
617 static const int mdio1_pins[] = {
618         52
619 };
620
621 static const int spi0_pins[] = {
622         16, 28, 40
623 };
624
625 static const int spi1_pins[] = {
626         10, 22, 34, 46
627 };
628
629 static const int ttc0_pins[] = {
630         18, 30, 42
631 };
632
633 static const int ttc1_pins[] = {
634         16, 28, 40
635 };
636
637 static const int uart0_pins[] = {
638         10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50
639 };
640
641 static const int uart1_pins[] = {
642         8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52
643 };
644
645 /* The following array contains required info for enabling MIO peripherals.
646  * The order of the structures in this array is same as the order
647  * of peripheral names in the array mio_periph_name */
648 static const struct xslcr_mio mio_periphs[] = {
649         {
650                 emac0_pins,
651                 ARRAY_SIZE(emac0_pins),
652                 XSLCR_MIO_NUM_EMAC_PINS,
653                 XSLCR_MIO_PIN_EMAC_ENABLE,
654         },
655         {
656                 emac1_pins,
657                 ARRAY_SIZE(emac1_pins),
658                 XSLCR_MIO_NUM_EMAC_PINS,
659                 XSLCR_MIO_PIN_EMAC_ENABLE,
660         },
661         {
662                 qspi0_pins,
663                 ARRAY_SIZE(qspi0_pins),
664                 XSLCR_MIO_NUM_QSPI_PINS,
665                 XSLCR_MIO_PIN_QSPI_ENABLE,
666         },
667         {
668                 qspi0_sel_pins,
669                 ARRAY_SIZE(qspi0_sel_pins),
670                 XSLCR_MIO_NUM_QSPI_SEL_PINS,
671                 XSLCR_MIO_PIN_QSPI_ENABLE,
672         },
673         {
674                 qspi1_pins,
675                 ARRAY_SIZE(qspi1_pins),
676                 XSLCR_MIO_NUM_QSPI_PINS,
677                 XSLCR_MIO_PIN_QSPI_ENABLE,
678         },
679         {
680                 qspi1_sel_pins,
681                 ARRAY_SIZE(qspi1_sel_pins),
682                 XSLCR_MIO_NUM_QSPI_SEL_PINS,
683                 XSLCR_MIO_PIN_QSPI_ENABLE,
684         },
685         {       qspi_foc_pins,
686                 ARRAY_SIZE(qspi_foc_pins),
687                 XSLCR_MIO_NUM_QSPI_FOC_PINS,
688                 XSLCR_MIO_PIN_QSPI_ENABLE,
689         },
690         {
691                 trace_data2_pins,
692                 ARRAY_SIZE(trace_data2_pins),
693                 XSLCR_MIO_NUM_TRACE_DATA2_PINS,
694                 XSLCR_MIO_PIN_TRACE_PORT_ENABLE,
695         },
696         {
697                 trace_data4_pins,
698                 ARRAY_SIZE(trace_data4_pins),
699                 XSLCR_MIO_NUM_TRACE_DATA4_PINS,
700                 XSLCR_MIO_PIN_TRACE_PORT_ENABLE,
701         },
702         {
703                 trace_data8_pins,
704                 ARRAY_SIZE(trace_data8_pins),
705                 XSLCR_MIO_NUM_TRACE_DATA8_PINS,
706                 XSLCR_MIO_PIN_TRACE_PORT_ENABLE,
707         },
708         {
709                 trace_data16_pins,
710                 ARRAY_SIZE(trace_data16_pins),
711                 XSLCR_MIO_NUM_TRACE_DATA4_PINS,
712                 XSLCR_MIO_PIN_TRACE_PORT_ENABLE,
713         },
714         {
715                 usb0_pins,
716                 ARRAY_SIZE(usb0_pins),
717                 XSLCR_MIO_NUM_USB_PINS,
718                 XSLCR_MIO_PIN_USB_ENABLE,
719         },
720         {
721                 usb1_pins,
722                 ARRAY_SIZE(usb1_pins),
723                 XSLCR_MIO_NUM_USB_PINS,
724                 XSLCR_MIO_PIN_USB_ENABLE,
725         },
726         {
727                 smc_a25_pins,
728                 ARRAY_SIZE(smc_a25_pins),
729                 XSLCR_MIO_NUM_SMC_A25_PINS,
730                 XSLCR_MIO_PIN_SRAM_NOR_ENABLE,
731         },
732         {
733                 smc_cs_pins,
734                 ARRAY_SIZE(smc_cs_pins),
735                 XSLCR_MIO_NUM_SMC_CS_PINS,
736                 XSLCR_MIO_PIN_SRAM_NOR_ENABLE,
737         },
738         {
739                 sram_nor_pins,
740                 ARRAY_SIZE(sram_nor_pins),
741                 XSLCR_MIO_NUM_SRAM_NOR_PINS,
742                 XSLCR_MIO_PIN_SRAM_NOR_ENABLE,
743         },
744         {
745                 nand_pins,
746                 ARRAY_SIZE(nand_pins),
747                 XSLCR_MIO_NUM_NAND_PINS,
748                 XSLCR_MIO_PIN_NAND_ENABLE,
749         },
750         {
751                 nand_cs_pins,
752                 ARRAY_SIZE(nand_cs_pins),
753                 XSLCR_MIO_NUM_NAND_CS_PINS,
754                 XSLCR_MIO_PIN_NAND_ENABLE,
755         },
756         {
757                 gpio00_pins,
758                 ARRAY_SIZE(gpio00_pins),
759                 XSLCR_MIO_NUM_GPIO_PINS,
760                 XSLCR_MIO_PIN_GPIO_ENABLE,
761         },
762         {
763                 gpio01_pins,
764                 ARRAY_SIZE(gpio01_pins),
765                 XSLCR_MIO_NUM_GPIO_PINS,
766                 XSLCR_MIO_PIN_GPIO_ENABLE,
767         },
768         {
769                 gpio02_pins,
770                 ARRAY_SIZE(gpio02_pins),
771                 XSLCR_MIO_NUM_GPIO_PINS,
772                 XSLCR_MIO_PIN_GPIO_ENABLE,
773         },
774         {
775                 gpio03_pins,
776                 ARRAY_SIZE(gpio03_pins),
777                 XSLCR_MIO_NUM_GPIO_PINS,
778                 XSLCR_MIO_PIN_GPIO_ENABLE,
779         },
780         {
781                 gpio04_pins,
782                 ARRAY_SIZE(gpio04_pins),
783                 XSLCR_MIO_NUM_GPIO_PINS,
784                 XSLCR_MIO_PIN_GPIO_ENABLE,
785         },
786         {
787                 gpio05_pins,
788                 ARRAY_SIZE(gpio05_pins),
789                 XSLCR_MIO_NUM_GPIO_PINS,
790                 XSLCR_MIO_PIN_GPIO_ENABLE,
791         },
792         {
793                 gpio06_pins,
794                 ARRAY_SIZE(gpio06_pins),
795                 XSLCR_MIO_NUM_GPIO_PINS,
796                 XSLCR_MIO_PIN_GPIO_ENABLE,
797         },
798         {
799                 gpio07_pins,
800                 ARRAY_SIZE(gpio07_pins),
801                 XSLCR_MIO_NUM_GPIO_PINS,
802                 XSLCR_MIO_PIN_GPIO_ENABLE,
803         },
804         {
805                 gpio08_pins,
806                 ARRAY_SIZE(gpio08_pins),
807                 XSLCR_MIO_NUM_GPIO_PINS,
808                 XSLCR_MIO_PIN_GPIO_ENABLE,
809         },
810         {
811                 gpio09_pins,
812                 ARRAY_SIZE(gpio09_pins),
813                 XSLCR_MIO_NUM_GPIO_PINS,
814                 XSLCR_MIO_PIN_GPIO_ENABLE,
815         },
816         {
817                 gpio10_pins,
818                 ARRAY_SIZE(gpio10_pins),
819                 XSLCR_MIO_NUM_GPIO_PINS,
820                 XSLCR_MIO_PIN_GPIO_ENABLE,
821         },
822         {
823                 gpio11_pins,
824                 ARRAY_SIZE(gpio11_pins),
825                 XSLCR_MIO_NUM_GPIO_PINS,
826                 XSLCR_MIO_PIN_GPIO_ENABLE,
827         },
828         {
829                 gpio12_pins,
830                 ARRAY_SIZE(gpio12_pins),
831                 XSLCR_MIO_NUM_GPIO_PINS,
832                 XSLCR_MIO_PIN_GPIO_ENABLE,
833         },
834         {
835                 gpio13_pins,
836                 ARRAY_SIZE(gpio13_pins),
837                 XSLCR_MIO_NUM_GPIO_PINS,
838                 XSLCR_MIO_PIN_GPIO_ENABLE,
839         },
840         {
841                 gpio14_pins,
842                 ARRAY_SIZE(gpio14_pins),
843                 XSLCR_MIO_NUM_GPIO_PINS,
844                 XSLCR_MIO_PIN_GPIO_ENABLE,
845         },
846         {
847                 gpio15_pins,
848                 ARRAY_SIZE(gpio15_pins),
849                 XSLCR_MIO_NUM_GPIO_PINS,
850                 XSLCR_MIO_PIN_GPIO_ENABLE,
851         },
852         {
853                 gpio16_pins,
854                 ARRAY_SIZE(gpio16_pins),
855                 XSLCR_MIO_NUM_GPIO_PINS,
856                 XSLCR_MIO_PIN_GPIO_ENABLE,
857         },
858         {
859                 gpio17_pins,
860                 ARRAY_SIZE(gpio17_pins),
861                 XSLCR_MIO_NUM_GPIO_PINS,
862                 XSLCR_MIO_PIN_GPIO_ENABLE,
863         },
864         {
865                 gpio18_pins,
866                 ARRAY_SIZE(gpio18_pins),
867                 XSLCR_MIO_NUM_GPIO_PINS,
868                 XSLCR_MIO_PIN_GPIO_ENABLE,
869         },
870         {
871                 gpio19_pins,
872                 ARRAY_SIZE(gpio19_pins),
873                 XSLCR_MIO_NUM_GPIO_PINS,
874                 XSLCR_MIO_PIN_GPIO_ENABLE,
875         },
876         {
877                 gpio20_pins,
878                 ARRAY_SIZE(gpio20_pins),
879                 XSLCR_MIO_NUM_GPIO_PINS,
880                 XSLCR_MIO_PIN_GPIO_ENABLE,
881         },
882         {
883                 gpio21_pins,
884                 ARRAY_SIZE(gpio21_pins),
885                 XSLCR_MIO_NUM_GPIO_PINS,
886                 XSLCR_MIO_PIN_GPIO_ENABLE,
887         },
888         {
889                 gpio22_pins,
890                 ARRAY_SIZE(gpio22_pins),
891                 XSLCR_MIO_NUM_GPIO_PINS,
892                 XSLCR_MIO_PIN_GPIO_ENABLE,
893         },
894         {
895                 gpio23_pins,
896                 ARRAY_SIZE(gpio23_pins),
897                 XSLCR_MIO_NUM_GPIO_PINS,
898                 XSLCR_MIO_PIN_GPIO_ENABLE,
899         },
900         {
901                 gpio24_pins,
902                 ARRAY_SIZE(gpio24_pins),
903                 XSLCR_MIO_NUM_GPIO_PINS,
904                 XSLCR_MIO_PIN_GPIO_ENABLE,
905         },
906         {
907                 gpio25_pins,
908                 ARRAY_SIZE(gpio25_pins),
909                 XSLCR_MIO_NUM_GPIO_PINS,
910                 XSLCR_MIO_PIN_GPIO_ENABLE,
911         },
912         {
913                 gpio26_pins,
914                 ARRAY_SIZE(gpio26_pins),
915                 XSLCR_MIO_NUM_GPIO_PINS,
916                 XSLCR_MIO_PIN_GPIO_ENABLE,
917         },
918         {
919                 gpio27_pins,
920                 ARRAY_SIZE(gpio27_pins),
921                 XSLCR_MIO_NUM_GPIO_PINS,
922                 XSLCR_MIO_PIN_GPIO_ENABLE,
923         },
924         {
925                 gpio28_pins,
926                 ARRAY_SIZE(gpio28_pins),
927                 XSLCR_MIO_NUM_GPIO_PINS,
928                 XSLCR_MIO_PIN_GPIO_ENABLE,
929         },
930         {
931                 gpio29_pins,
932                 ARRAY_SIZE(gpio29_pins),
933                 XSLCR_MIO_NUM_GPIO_PINS,
934                 XSLCR_MIO_PIN_GPIO_ENABLE,
935         },
936         {
937                 gpio30_pins,
938                 ARRAY_SIZE(gpio30_pins),
939                 XSLCR_MIO_NUM_GPIO_PINS,
940                 XSLCR_MIO_PIN_GPIO_ENABLE,
941         },
942         {
943                 gpio31_pins,
944                 ARRAY_SIZE(gpio31_pins),
945                 XSLCR_MIO_NUM_GPIO_PINS,
946                 XSLCR_MIO_PIN_GPIO_ENABLE,
947         },
948         {
949                 gpio32_pins,
950                 ARRAY_SIZE(gpio32_pins),
951                 XSLCR_MIO_NUM_GPIO_PINS,
952                 XSLCR_MIO_PIN_GPIO_ENABLE,
953         },
954         {
955                 gpio33_pins,
956                 ARRAY_SIZE(gpio33_pins),
957                 XSLCR_MIO_NUM_GPIO_PINS,
958                 XSLCR_MIO_PIN_GPIO_ENABLE,
959         },
960         {
961                 gpio34_pins,
962                 ARRAY_SIZE(gpio34_pins),
963                 XSLCR_MIO_NUM_GPIO_PINS,
964                 XSLCR_MIO_PIN_GPIO_ENABLE,
965         },
966         {
967                 gpio35_pins,
968                 ARRAY_SIZE(gpio35_pins),
969                 XSLCR_MIO_NUM_GPIO_PINS,
970                 XSLCR_MIO_PIN_GPIO_ENABLE,
971         },
972         {
973                 gpio36_pins,
974                 ARRAY_SIZE(gpio36_pins),
975                 XSLCR_MIO_NUM_GPIO_PINS,
976                 XSLCR_MIO_PIN_GPIO_ENABLE,
977         },
978         {
979                 gpio37_pins,
980                 ARRAY_SIZE(gpio37_pins),
981                 XSLCR_MIO_NUM_GPIO_PINS,
982                 XSLCR_MIO_PIN_GPIO_ENABLE,
983         },
984         {
985                 gpio38_pins,
986                 ARRAY_SIZE(gpio38_pins),
987                 XSLCR_MIO_NUM_GPIO_PINS,
988                 XSLCR_MIO_PIN_GPIO_ENABLE,
989         },
990         {
991                 gpio39_pins,
992                 ARRAY_SIZE(gpio39_pins),
993                 XSLCR_MIO_NUM_GPIO_PINS,
994                 XSLCR_MIO_PIN_GPIO_ENABLE,
995         },
996         {
997                 gpio40_pins,
998                 ARRAY_SIZE(gpio40_pins),
999                 XSLCR_MIO_NUM_GPIO_PINS,
1000                 XSLCR_MIO_PIN_GPIO_ENABLE,
1001         },
1002         {
1003                 gpio41_pins,
1004                 ARRAY_SIZE(gpio41_pins),
1005                 XSLCR_MIO_NUM_GPIO_PINS,
1006                 XSLCR_MIO_PIN_GPIO_ENABLE,
1007         },
1008         {
1009                 gpio42_pins,
1010                 ARRAY_SIZE(gpio42_pins),
1011                 XSLCR_MIO_NUM_GPIO_PINS,
1012                 XSLCR_MIO_PIN_GPIO_ENABLE,
1013         },
1014         {
1015                 gpio43_pins,
1016                 ARRAY_SIZE(gpio43_pins),
1017                 XSLCR_MIO_NUM_GPIO_PINS,
1018                 XSLCR_MIO_PIN_GPIO_ENABLE,
1019         },
1020         {
1021                 gpio44_pins,
1022                 ARRAY_SIZE(gpio44_pins),
1023                 XSLCR_MIO_NUM_GPIO_PINS,
1024                 XSLCR_MIO_PIN_GPIO_ENABLE,
1025         },
1026         {
1027                 gpio45_pins,
1028                 ARRAY_SIZE(gpio45_pins),
1029                 XSLCR_MIO_NUM_GPIO_PINS,
1030                 XSLCR_MIO_PIN_GPIO_ENABLE,
1031         },
1032         {
1033                 gpio46_pins,
1034                 ARRAY_SIZE(gpio46_pins),
1035                 XSLCR_MIO_NUM_GPIO_PINS,
1036                 XSLCR_MIO_PIN_GPIO_ENABLE,
1037         },
1038         {
1039                 gpio47_pins,
1040                 ARRAY_SIZE(gpio47_pins),
1041                 XSLCR_MIO_NUM_GPIO_PINS,
1042                 XSLCR_MIO_PIN_GPIO_ENABLE,
1043         },
1044         {
1045                 gpio48_pins,
1046                 ARRAY_SIZE(gpio48_pins),
1047                 XSLCR_MIO_NUM_GPIO_PINS,
1048                 XSLCR_MIO_PIN_GPIO_ENABLE,
1049         },
1050         {
1051                 gpio49_pins,
1052                 ARRAY_SIZE(gpio49_pins),
1053                 XSLCR_MIO_NUM_GPIO_PINS,
1054                 XSLCR_MIO_PIN_GPIO_ENABLE,
1055         },
1056         {
1057                 gpio50_pins,
1058                 ARRAY_SIZE(gpio50_pins),
1059                 XSLCR_MIO_NUM_GPIO_PINS,
1060                 XSLCR_MIO_PIN_GPIO_ENABLE,
1061         },
1062         {
1063                 gpio51_pins,
1064                 ARRAY_SIZE(gpio51_pins),
1065                 XSLCR_MIO_NUM_GPIO_PINS,
1066                 XSLCR_MIO_PIN_GPIO_ENABLE,
1067         },
1068         {
1069                 gpio52_pins,
1070                 ARRAY_SIZE(gpio52_pins),
1071                 XSLCR_MIO_NUM_GPIO_PINS,
1072                 XSLCR_MIO_PIN_GPIO_ENABLE,
1073         },
1074         {
1075                 gpio53_pins,
1076                 ARRAY_SIZE(gpio53_pins),
1077                 XSLCR_MIO_NUM_GPIO_PINS,
1078                 XSLCR_MIO_PIN_GPIO_ENABLE,
1079         },
1080         {
1081                 can0_pins,
1082                 ARRAY_SIZE(can0_pins),
1083                 XSLCR_MIO_NUM_CAN_PINS,
1084                 XSLCR_MIO_PIN_CAN_ENABLE,
1085         },
1086         {
1087                 can1_pins,
1088                 ARRAY_SIZE(can1_pins),
1089                 XSLCR_MIO_NUM_CAN_PINS,
1090                 XSLCR_MIO_PIN_CAN_ENABLE,
1091         },
1092         {
1093                 iic0_pins,
1094                 ARRAY_SIZE(iic0_pins),
1095                 XSLCR_MIO_NUM_IIC_PINS,
1096                 XSLCR_MIO_PIN_IIC_ENABLE,
1097         },
1098         {
1099                 iic1_pins,
1100                 ARRAY_SIZE(iic1_pins),
1101                 XSLCR_MIO_NUM_IIC_PINS,
1102                 XSLCR_MIO_PIN_IIC_ENABLE,
1103         },
1104         {
1105                 jtag0_pins,
1106                 ARRAY_SIZE(jtag0_pins),
1107                 XSLCR_MIO_NUM_JTAG_PINS,
1108                 XSLCR_MIO_PIN_JTAG_ENABLE,
1109         },
1110         {
1111                 wdt_pins,
1112                 ARRAY_SIZE(wdt_pins),
1113                 XSLCR_MIO_NUM_WDT_PINS,
1114                 XSLCR_MIO_PIN_WDT_ENABLE,
1115         },
1116         {
1117                 mdio0_pins,
1118                 ARRAY_SIZE(mdio0_pins),
1119                 XSLCR_MIO_NUM_MDIO_PINS,
1120                 XSLCR_MIO_PIN_MDIO0_ENABLE,
1121         },
1122         {
1123                 sdio0_pins,
1124                 ARRAY_SIZE(sdio0_pins),
1125                 XSLCR_MIO_NUM_SDIO_PINS,
1126                 XSLCR_MIO_PIN_SDIO_ENABLE,
1127         },
1128         {
1129                 sdio1_pins,
1130                 ARRAY_SIZE(sdio1_pins),
1131                 XSLCR_MIO_NUM_SDIO_PINS,
1132                 XSLCR_MIO_PIN_SDIO_ENABLE,
1133         },
1134         {
1135                 mdio1_pins,
1136                 ARRAY_SIZE(mdio1_pins),
1137                 XSLCR_MIO_NUM_MDIO_PINS,
1138                 XSLCR_MIO_PIN_MDIO1_ENABLE,
1139         },
1140         {
1141                 spi0_pins,
1142                 ARRAY_SIZE(spi0_pins),
1143                 XSLCR_MIO_NUM_SPI_PINS,
1144                 XSLCR_MIO_PIN_SPI_ENABLE,
1145         },
1146         {
1147                 spi1_pins,
1148                 ARRAY_SIZE(spi1_pins),
1149                 XSLCR_MIO_NUM_SPI_PINS,
1150                 XSLCR_MIO_PIN_SPI_ENABLE,
1151         },
1152         {
1153                 ttc0_pins,
1154                 ARRAY_SIZE(ttc0_pins),
1155                 XSLCR_MIO_NUM_TTC_PINS,
1156                 XSLCR_MIO_PIN_TTC_ENABLE,
1157         },
1158         {
1159                 ttc1_pins,
1160                 ARRAY_SIZE(ttc1_pins),
1161                 XSLCR_MIO_NUM_TTC_PINS,
1162                 XSLCR_MIO_PIN_TTC_ENABLE,
1163         },
1164         {
1165                 uart0_pins,
1166                 ARRAY_SIZE(uart0_pins),
1167                 XSLCR_MIO_NUM_UART_PINS,
1168                 XSLCR_MIO_PIN_UART_ENABLE,
1169         },
1170         {
1171                 uart1_pins,
1172                 ARRAY_SIZE(uart1_pins),
1173                 XSLCR_MIO_NUM_UART_PINS,
1174                 XSLCR_MIO_PIN_UART_ENABLE,
1175         },
1176 };
1177
1178 /*
1179  * Each bit in this array is a flag that indicates whether a mio peripheral
1180  * is assigned. The order of bits in this array is same as the order of
1181  * peripheral names in the array mio_periph_name
1182  */
1183 static u32 periph_status[DIV_ROUND_UP(ARRAY_SIZE(mio_periphs), 32)];
1184
1185 /* Peripherals that can be reset thru SLCR */
1186 static const char * const reset_periph_name[] = {
1187         "pss",
1188         "ddr",
1189         "sw_amba",
1190         "dmac",
1191         "usb0_amba",
1192         "usb1_amba",
1193         "usb0_usb",
1194         "usb1_usb",
1195         "eth0_mac",
1196         "eth1_mac",
1197         "eth0_rx",
1198         "eth1_rx",
1199         "eth0_ref",
1200         "eth1_ref",
1201         "sdio0_amba",
1202         "sdio1_amba",
1203         "sdio0_ref",
1204         "sdio1_ref",
1205         "spi0_amba",
1206         "spi1_ambs",
1207         "spi0_ref",
1208         "spi1_ref",
1209         "can0_amba",
1210         "can1_amba",
1211         "can0_ref",
1212         "can1_ref",
1213         "iic0_amba",
1214         "iic1_amba",
1215         "uart0_amba",
1216         "uart1_amba",
1217         "gpio_amba",
1218         "qspi_amba",
1219         "qspi_ref",
1220         "smc_amba",
1221         "smc_ref",
1222         "ocm_amba",
1223         "pcap2x",
1224         "devc_amba",
1225         "fpga0_out",
1226         "fpga1_out",
1227         "fpga2_out",
1228         "fpga3_out",
1229         "fpga_dma0",
1230         "fpga_dma1",
1231         "fpga_dma2",
1232         "fpga_dma3",
1233         "fpga_fmsw0",
1234         "fpga_fmsw1",
1235         "fpga_fssw0",
1236         "fpga_fssw1",
1237         "fpga_axds0",
1238         "fpga_axds1",
1239         "fpga_axds2",
1240         "fpga_axds3",
1241         "fpga_acp",
1242 };
1243
1244 /* The following array contains the reset control register offset and the reset
1245  * mask for all the peripherals. The order of the structures is same as the
1246  * order of peripheral names in the array reset_periph_name */
1247 static const struct xslcr_periph_reset reset_info[] = {
1248         { XSLCR_PSS_RST_CTRL_OFFSET,  0x00000001 },
1249         { XSLCR_DDR_RST_CTRL_OFFSET,  0x00000001 },
1250         { XSLCR_AMBA_RST_CTRL_OFFSET, 0x00000001 },
1251         { XSLCR_DMAC_RST_CTRL_OFFSET, 0x00000001 },
1252         { XSLCR_USB_RST_CTRL_OFFSET,  0x00000001 },
1253         { XSLCR_USB_RST_CTRL_OFFSET,  0x00000002 },
1254         { XSLCR_USB_RST_CTRL_OFFSET,  0x00000010 },
1255         { XSLCR_USB_RST_CTRL_OFFSET,  0x00000020 },
1256         { XSLCR_EMAC_RST_CTRL_OFFSET,  0x00000001 },
1257         { XSLCR_EMAC_RST_CTRL_OFFSET,  0x00000002 },
1258         { XSLCR_EMAC_RST_CTRL_OFFSET,  0x00000010 },
1259         { XSLCR_EMAC_RST_CTRL_OFFSET,  0x00000020 },
1260         { XSLCR_EMAC_RST_CTRL_OFFSET,  0x00000040 },
1261         { XSLCR_EMAC_RST_CTRL_OFFSET,  0x00000080 },
1262         { XSLCR_SDIO_RST_CTRL_OFFSET, 0x00000001 },
1263         { XSLCR_SDIO_RST_CTRL_OFFSET, 0x00000002 },
1264         { XSLCR_SDIO_RST_CTRL_OFFSET, 0x00000010 },
1265         { XSLCR_SDIO_RST_CTRL_OFFSET, 0x00000020 },
1266         { XSLCR_SPI_RST_CTRL_OFFSET,  0x00000001 },
1267         { XSLCR_SPI_RST_CTRL_OFFSET,  0x00000002 },
1268         { XSLCR_SPI_RST_CTRL_OFFSET,  0x00000004 },
1269         { XSLCR_SPI_RST_CTRL_OFFSET,  0x00000008 },
1270         { XSLCR_CAN_RST_CTRL_OFFSET,  0x00000001 },
1271         { XSLCR_CAN_RST_CTRL_OFFSET,  0x00000002 },
1272         { XSLCR_CAN_RST_CTRL_OFFSET,  0x00000004 },
1273         { XSLCR_CAN_RST_CTRL_OFFSET,  0x00000008 },
1274         { XSLCR_I2C_RST_CTRL_OFFSET,  0x00000001 },
1275         { XSLCR_I2C_RST_CTRL_OFFSET,  0x00000002 },
1276         { XSLCR_UART_RST_CTRL_OFFSET, 0x00000001 },
1277         { XSLCR_UART_RST_CTRL_OFFSET, 0x00000002 },
1278         { XSLCR_GPIO_RST_CTRL_OFFSET, 0x00000001 },
1279         { XSLCR_QSPI_RST_CTRL_OFFSET, 0x00000001 },
1280         { XSLCR_QSPI_RST_CTRL_OFFSET, 0x00000002 },
1281         { XSLCR_SMC_RST_CTRL_OFFSET,  0x00000001 },
1282         { XSLCR_SMC_RST_CTRL_OFFSET,  0x00000002 },
1283         { XSLCR_OCM_RST_CTRL_OFFSET,  0x00000001 },
1284         { XSLCR_DEVC_RST_CTRL_OFFSET, 0x00000001 },
1285         { XSLCR_DEVC_RST_CTRL_OFFSET, 0x00000002 },
1286         { XSLCR_FPGA_RST_CTRL_OFFSET, 0x00000001 },
1287         { XSLCR_FPGA_RST_CTRL_OFFSET, 0x00000002 },
1288         { XSLCR_FPGA_RST_CTRL_OFFSET, 0x00000004 },
1289         { XSLCR_FPGA_RST_CTRL_OFFSET, 0x00000008 },
1290         { XSLCR_FPGA_RST_CTRL_OFFSET, 0x00000100 },
1291         { XSLCR_FPGA_RST_CTRL_OFFSET, 0x00000200 },
1292         { XSLCR_FPGA_RST_CTRL_OFFSET, 0x00000400 },
1293         { XSLCR_FPGA_RST_CTRL_OFFSET, 0x00000800 },
1294         { XSLCR_FPGA_RST_CTRL_OFFSET, 0x00001000 },
1295         { XSLCR_FPGA_RST_CTRL_OFFSET, 0x00002000 },
1296         { XSLCR_FPGA_RST_CTRL_OFFSET, 0x00010000 },
1297         { XSLCR_FPGA_RST_CTRL_OFFSET, 0x00020000 },
1298         { XSLCR_FPGA_RST_CTRL_OFFSET, 0x00100000 },
1299         { XSLCR_FPGA_RST_CTRL_OFFSET, 0x00200000 },
1300         { XSLCR_FPGA_RST_CTRL_OFFSET, 0x00400000 },
1301         { XSLCR_FPGA_RST_CTRL_OFFSET, 0x00800000 },
1302         { XSLCR_FPGA_RST_CTRL_OFFSET, 0x01000000 },
1303 };
1304
1305 /**
1306  * zynq_slcr_system_reset - Reset the entire system.
1307  */
1308 void zynq_slcr_system_reset(void)
1309 {
1310         u32 reboot;
1311
1312         /*
1313          * Unlock the SLCR then reset the system.
1314          * Note that this seems to require raw i/o
1315          * functions or there's a lockup?
1316          */
1317         writel(SLCR_UNLOCK_MAGIC, zynq_slcr_base + SLCR_UNLOCK);
1318
1319         /*
1320          * Clear 0x0F000000 bits of reboot status register to workaround
1321          * the FSBL not loading the bitstream after soft-reboot
1322          * This is a temporary solution until we know more.
1323          */
1324         reboot = readl(zynq_slcr_base + SLCR_REBOOT_STATUS);
1325         writel(reboot & 0xF0FFFFFF, zynq_slcr_base + SLCR_REBOOT_STATUS);
1326         writel(1, zynq_slcr_base + SLCR_PS_RST_CTRL_OFFSET);
1327 }
1328
1329 /**
1330  * xslcr_write - Write to a register in SLCR block
1331  *
1332  * @offset:     Register offset in SLCR block
1333  * @val:        Value to write to the register
1334  **/
1335 void xslcr_write(u32 val, u32 offset)
1336 {
1337         xslcr_writereg(slcr->regs + offset, val);
1338 }
1339 EXPORT_SYMBOL(xslcr_write);
1340
1341 /**
1342  * xslcr_read - Read a register in SLCR block
1343  *
1344  * @offset:     Register offset in SLCR block
1345  *
1346  * return:      Value read from the SLCR register
1347  **/
1348 u32 xslcr_read(u32 offset)
1349 {
1350         return xslcr_readreg(slcr->regs + offset);
1351 }
1352 EXPORT_SYMBOL(xslcr_read);
1353
1354 /**
1355  * xslcr_init_preload_fpga - Disable communication from the PL to PS.
1356  */
1357 void xslcr_init_preload_fpga(void)
1358 {
1359
1360         /* Assert FPGA top level output resets */
1361         xslcr_write(0xF, XSLCR_FPGA_RST_CTRL_OFFSET);
1362
1363         /* Disable level shifters */
1364         xslcr_write(0, XSLCR_LVL_SHFTR_EN_OFFSET);
1365
1366         /* Enable output level shifters */
1367         xslcr_write(0xA, XSLCR_LVL_SHFTR_EN_OFFSET);
1368 }
1369 EXPORT_SYMBOL(xslcr_init_preload_fpga);
1370
1371 /**
1372  * xslcr_init_postload_fpga - Re-enable communication from the PL to PS.
1373  */
1374 void xslcr_init_postload_fpga(void)
1375 {
1376
1377         /* Enable level shifters */
1378         xslcr_write(0xf, XSLCR_LVL_SHFTR_EN_OFFSET);
1379
1380         /* Deassert AXI interface resets */
1381         xslcr_write(0, XSLCR_FPGA_RST_CTRL_OFFSET);
1382 }
1383 EXPORT_SYMBOL(xslcr_init_postload_fpga);
1384
1385 /**
1386  * xslcr_set_bit - Set a bit
1387  *
1388  * @data:       Address of the data in which a bit is to be set
1389  * @bit:        Bit number to set
1390  **/
1391 static inline void xslcr_set_bit(u32 *data, unsigned int bit)
1392 {
1393         unsigned long mask = 1UL << (bit & 31);
1394
1395         *(data + (bit >> 5)) |= mask;
1396 }
1397
1398 /**
1399  * xslcr_clear_bit - Clear a bit
1400  *
1401  * @data:       Address of the data in which a bit is to be cleared
1402  * @bit:        Bit number to clear
1403  **/
1404 static inline void xslcr_clear_bit(u32 *data, unsigned int bit)
1405 {
1406         unsigned long mask = 1UL << (bit & 31);
1407
1408         *(data + (bit >> 5)) &= ~mask;
1409 }
1410
1411 /**
1412  * xslcr_test_bit - Check if a bit is set
1413  *
1414  * @data:       Address of the data in which a bit is to be checked
1415  * @bit:        Bit number to check
1416  *
1417  * return:      True or false
1418  **/
1419 static inline int xslcr_test_bit(u32 *data, unsigned int bit)
1420 {
1421         unsigned long mask = 1UL << (bit & 31);
1422
1423         return (*(data + (bit >> 5)) & mask) != 0;
1424 }
1425
1426 /**
1427  * xslcr_mio_isavailable - Check if a MIO pin is available for assignment.
1428  *
1429  * @pin         MIO pin to be checked.
1430  *
1431  * return:      -EBUSY if the pin is in use.
1432  *              0 if the pin is not assigned.
1433  **/
1434 static int xslcr_mio_isavailable(u32 pin)
1435 {
1436         u32 reg;
1437
1438         reg = xslcr_readreg(slcr->regs + XSLCR_MIO_PIN_00_OFFSET + (pin * 4));
1439         if (reg & XSLCR_MIO_PIN_XX_TRI_ENABLE)
1440                 return 0;
1441
1442         return -EBUSY;  /* pin is assigned */
1443 }
1444
1445 /**
1446  * xslcr_enable_mio_peripheral - Enable a MIO peripheral.
1447  *
1448  * @mio:        id used to lookup the data needed to enable the peripheral.
1449  *
1450  * This function enables a MIO peripheral on a pinset previously set by the
1451  * user, thru sysfs attribute 'pinset'.
1452  *
1453  * @return      0 if the peripheral is enabled on the given pin set.
1454  *              negative error if the peripheral is already enabled, if an
1455  *              invalid pinset is specified, or if the pins are assigned to a
1456  *              different peripheral.
1457  **/
1458 static int xslcr_enable_mio_peripheral(int mio)
1459 {
1460         const struct xslcr_mio *mio_ptr;
1461         unsigned long flags;
1462         int pin_set, pin, i;
1463
1464         /* enable the peripheral only if it hasn't been already enabled */
1465         if (xslcr_test_bit(periph_status, mio))
1466                 return -EBUSY;
1467
1468         /* get the pin set */
1469         pin_set = active_pinset[mio];
1470
1471         mio_ptr = &mio_periphs[mio];
1472         if (pin_set >= mio_ptr->max_sets) {
1473                 pr_err("%s: Invalid pinset\n", mio_periph_name[mio]);
1474                 return -EINVAL;
1475         }
1476
1477         /* check whether all the pins in this pin set are unassigned */
1478         pin = mio_ptr->set_pins[pin_set]; /* 1st pin */
1479         for (i = 0; i < mio_ptr->numpins; i++) {
1480                 if (xslcr_mio_isavailable(pin + i)) {
1481                         pr_err("%s: One or more pins in pinset %d are busy\n",
1482                                 mio_periph_name[mio], pin_set);
1483                         return -EBUSY;
1484                 }
1485         }
1486
1487         spin_lock_irqsave(&slcr->io_lock, flags);
1488         /* assign all pins in the set to this peripheral */
1489         for (i = 0; i < mio_ptr->numpins; i++)
1490                 /* update the MIO register */
1491                 xslcr_writereg((slcr->regs + ((pin + i) * 4) +
1492                                 XSLCR_MIO_PIN_00_OFFSET), mio_ptr->enable_val);
1493
1494         /* mark that the peripheral has been enabled */
1495         xslcr_set_bit(periph_status, mio);
1496         spin_unlock_irqrestore(&slcr->io_lock, flags);
1497
1498         pr_debug("Enabled peripheral %s on pinset %d\n",
1499                  mio_periph_name[mio], pin_set);
1500         return 0;
1501 }
1502
1503 /**
1504  * xslcr_disable_mio_peripheral - Disable a MIO peripheral.
1505  *
1506  * @mio:        id used to lookup the data needed to enable the peripheral.
1507  *
1508  * This function checks if a MIO peripheral is previously enabled on the pinset
1509  * specified by the user, disables the peripheral and releases the MIO pins.
1510  *
1511  * return:      0 if the peripheral is disabled and MIO pins are released.
1512  *              negative error if the peripheral is already disabled, if an
1513  *              invalid peripheral is specified, or if the pins are assigned to
1514  *              a different peripheral.
1515  **/
1516 static int xslcr_disable_mio_peripheral(int mio)
1517 {
1518         const struct xslcr_mio *mio_ptr;
1519         unsigned long flags;
1520         int pin_set, pin, i;
1521         u32 reg;
1522
1523         /* disable the peripheral only if it has been already enabled */
1524         if (!xslcr_test_bit(periph_status, mio))
1525                 return -EBUSY;
1526
1527         /* get the pin set */
1528         pin_set = active_pinset[mio];
1529
1530         mio_ptr = &mio_periphs[mio];
1531         if (pin_set >= mio_ptr->max_sets) {
1532                 pr_err("%s: Invalid pinset %d\n",
1533                         mio_periph_name[mio], pin_set);
1534                 return -EINVAL;
1535         }
1536
1537         pin = mio_ptr->set_pins[pin_set]; /* 1st pin */
1538         for (i = 0; i < mio_ptr->numpins; i++) {
1539
1540                 /* check if each pin in the pin_set is assigned to this periph,
1541                  * to make sure the pins are not being released accidentally*/
1542                 reg = xslcr_readreg(slcr->regs + XSLCR_MIO_PIN_00_OFFSET +
1543                                     (pin * 4));
1544                 reg &= XSLCR_MIO_LMASK;
1545                 if (reg != mio_ptr->enable_val) {
1546                         pr_err("%s: One or more pins in pinset %d are busy\n",
1547                                 mio_periph_name[mio], pin_set);
1548                         return -EBUSY;
1549                 }
1550         }
1551
1552         spin_lock_irqsave(&slcr->io_lock, flags);
1553         /* release all pins in the set */
1554         for (i = 0; i < mio_ptr->numpins; i++) {
1555
1556                 /* update MIO register, set tri-state */
1557                 xslcr_writereg((slcr->regs + ((pin + i) * 4) +
1558                                 XSLCR_MIO_PIN_00_OFFSET),
1559                                 xslcr_readreg((slcr->regs + ((pin + i) * 4) +
1560                                         XSLCR_MIO_PIN_00_OFFSET)) |
1561                                 XSLCR_MIO_PIN_XX_TRI_ENABLE);
1562         }
1563
1564         /* mark that the peripheral has been disabled */
1565         xslcr_clear_bit(periph_status, mio);
1566         spin_unlock_irqrestore(&slcr->io_lock, flags);
1567
1568         pr_debug("Disabled peripheral %s on pinset %d\n",
1569                  mio_periph_name[mio], pin_set);
1570         return 0;
1571 }
1572
1573 /**
1574  * xslcr_config_mio_peripheral - Enable/disable a MIO peripheral.
1575  *
1576  * @dev:        pointer to the MIO device.
1577  * @attr:       pointer to the 'enable_pinset' device attribute descriptor.
1578  * @buf:        pointer to the buffer with user data.
1579  * @size:       size of the buf.
1580  *
1581  * This function parses the user data in buf and enables/disables the MIO
1582  * peripheral specified by dev.
1583  *
1584  * return:      0 if the peripheral is enabled/disabled successfully.
1585  *              negative error if the peripheral configuration failed.
1586  **/
1587 static ssize_t xslcr_config_mio_peripheral(struct device *dev,
1588                                            struct device_attribute *attr,
1589                                            const char *buf, size_t size)
1590 {
1591         unsigned long en;
1592         int mio, ret;
1593
1594         /* get the peripheral */
1595         for (mio = 0; mio < ARRAY_SIZE(mio_periph_name); mio++) {
1596                 if (sysfs_streq(dev_name(dev), mio_periph_name[mio]) == 1)
1597                         break;
1598         }
1599
1600         if (mio == ARRAY_SIZE(mio_periph_name)) {
1601                 dev_err(dev, "Invalid peripheral specified\n");
1602                 return -EINVAL;
1603         }
1604
1605         ret = kstrtoul(buf, 10, &en);
1606         if ((ret) || (en > 1)) {
1607                 dev_err(dev, "Invalid user argument\n");
1608                 return -EINVAL;
1609         }
1610
1611         if (en == 1)
1612                 ret = xslcr_enable_mio_peripheral(mio);
1613         else if (en == 0)
1614                 ret = xslcr_disable_mio_peripheral(mio);
1615
1616         return size;
1617 }
1618
1619 static DEVICE_ATTR(enable_pinset, 0222, NULL, xslcr_config_mio_peripheral);
1620
1621 /**
1622  * xslcr_store_pinset - Store a pinset for a MIO peripheral.
1623  *
1624  * @dev:        pointer to the MIO device.
1625  * @attr:       pointer to the 'pinset' device attribute descriptor.
1626  * @buf:        pointer to the buffer with user data.
1627  * @size:       size of the buf.
1628  *
1629  * This function parses the user data in buf and stores the pinset for the MIO
1630  * peripheral specified by dev. This pinset will be later used to enable or
1631  * disable the MIO peripheral.
1632  *
1633  * return:      0 if the peripheral is enabled/disabled successfully.
1634  *              negative error if the peripheral configuration failed.
1635  **/
1636 static ssize_t xslcr_store_pinset(struct device *dev,
1637                                   struct device_attribute *attr,
1638                                   const char *buf, size_t size)
1639 {
1640         unsigned long pin_set;
1641         int mio, ret;
1642
1643         /* get the peripheral */
1644         for (mio = 0; mio < ARRAY_SIZE(mio_periph_name); mio++) {
1645                 if (sysfs_streq(dev_name(dev), mio_periph_name[mio]) == 1)
1646                         break;
1647         }
1648
1649         if (mio == ARRAY_SIZE(mio_periph_name)) {
1650                 dev_err(dev, "Invalid peripheral specified\n");
1651                 return -EINVAL;
1652         }
1653
1654         /* get the pin set */
1655         ret = kstrtoul(buf, 10, &pin_set);
1656         if ((ret) || (pin_set >= mio_periphs[mio].max_sets)) {
1657                 dev_err(dev, "Invalid pinset\n");
1658                 return -EINVAL;
1659         }
1660
1661         /* store the pin set */
1662         active_pinset[mio] = pin_set;
1663         dev_dbg(dev, "Pinset=%d\n", (unsigned int)pin_set);
1664
1665         return size;
1666 }
1667
1668 static DEVICE_ATTR(pinset, 222, NULL, xslcr_store_pinset);
1669
1670 /**
1671  * xslcr_get_periph_status - Get the current status of a MIO peripheral.
1672  *
1673  * @dev:        pointer to this device.
1674  * @attr:       pointer to the device attribute descriptor.
1675  * @buf:        pointer to the buffer in which pin status is returned as a str.
1676  *
1677  * This function returns the current status of a MIO peripheral specified by the
1678  * user.
1679  *
1680  * return:      negative error if an invalid peripheral is specified or size of
1681  *              the buf, with the status of the peripheral.
1682  **/
1683 static ssize_t xslcr_get_periph_status(struct device *dev,
1684                                        struct device_attribute *attr, char *buf)
1685 {
1686         ssize_t size;
1687         int mio;
1688
1689         /* check if a valid peripheral is specified */
1690         for (mio = 0; mio < ARRAY_SIZE(mio_periph_name); mio++) {
1691                 if (sysfs_streq(dev_name(dev), mio_periph_name[mio]) == 1)
1692                         break;
1693         }
1694
1695         if (mio == ARRAY_SIZE(mio_periph_name)) {
1696                 dev_err(dev, "Invalid peripheral specified\n");
1697                 return -EINVAL;
1698         }
1699
1700         size = sprintf(buf, "%d\n", xslcr_test_bit(periph_status, mio));
1701
1702         return size;
1703 }
1704
1705 static DEVICE_ATTR(status, 0444, xslcr_get_periph_status, NULL);
1706
1707 /**
1708  * xslcr_reset_periph - Reset a peripheral within PS.
1709  *
1710  * @dev:        pointer to this device.
1711  * @attr:       pointer to the device attribute descriptor.
1712  * @buf:        pointer to the buffer with user data.
1713  * @size:       size of the buf.
1714  *
1715  * This function performs a software reset on the peripheral specified by the
1716  * user.
1717  *
1718  * return: negative error if an invalid peripheral is specified or size of the
1719  * buf if the peripheral is reset successfully.
1720  **/
1721 static ssize_t xslcr_reset_periph(struct device *dev,
1722                                   struct device_attribute *attr,
1723                                   const char *buf, size_t size)
1724 {
1725         unsigned long flags, rst;
1726         int i, ret;
1727         u32 reg;
1728
1729         /* check for a valid peripheral */
1730         for (i = 0; i < ARRAY_SIZE(reset_periph_name); i++) {
1731                 if (sysfs_streq(dev_name(dev), reset_periph_name[i]) == 1)
1732                         break;
1733         }
1734
1735         if (i == ARRAY_SIZE(reset_periph_name)) {
1736                 dev_err(dev, "Invalid peripheral specified\n");
1737                 return -EINVAL;
1738         }
1739
1740         ret = kstrtoul(buf, 10, &rst);
1741         if (ret) {
1742                 dev_err(dev, "Invalid user argument\n");
1743                 return -EINVAL;
1744         }
1745
1746         /* reset the peripheral */
1747         spin_lock_irqsave(&slcr->io_lock, flags);
1748
1749         /* read the register and modify only the specified bit */
1750         reg = xslcr_readreg(slcr->regs + reset_info[i].reg_offset);
1751         if (!rst)
1752                 reg &= ~(reset_info[i].reset_mask);
1753         else
1754                 reg |= reset_info[i].reset_mask;
1755
1756         xslcr_writereg(slcr->regs + reset_info[i].reg_offset, reg);
1757
1758         spin_unlock_irqrestore(&slcr->io_lock, flags);
1759         return size;
1760 }
1761
1762 static DEVICE_ATTR(reset, 0222, NULL, xslcr_reset_periph);
1763
1764 /**
1765  * show_mio_pin_status - Get the status of all the MIO pins.
1766  *
1767  * @dev:        pointer to this device.
1768  * @attr:       pointer to the device attribute descriptor.
1769  * @buf:        pointer to the buffer in which pin status is returned as a str.
1770  *
1771  * This function returns overall status of the MIO pins as a 64-bit mask. Bit
1772  * positions with 1 indicate that the corresponding MIO pin has been assigned to
1773  * a peripheral and bit positions with 0 indicate that the pin is free.
1774  *
1775  * return:      length of the buffer containing the mio pin status.
1776  **/
1777 static ssize_t show_mio_pin_status(struct device *dev,
1778                 struct device_attribute *attr, char *buf)
1779 {
1780         u64 pin_status = 0;
1781         ssize_t status;
1782         u32 reg;
1783         int i;
1784
1785         for (i = 0; i < 54; i++) {
1786
1787                 /* read the MIO control register to determine if its free */
1788                 reg = xslcr_readreg((slcr->regs + (i * 4) +
1789                                     XSLCR_MIO_PIN_00_OFFSET));
1790                 if (!(reg & XSLCR_MIO_PIN_XX_TRI_ENABLE))
1791                         xslcr_set_bit((u32 *)&pin_status, i);
1792         }
1793         status = sprintf(buf, "0x%016Lx\n", pin_status);
1794
1795         return status;
1796 }
1797
1798 static DEVICE_ATTR(mio_pin_status, 0444, show_mio_pin_status, NULL);
1799
1800 /* MIO attributes */
1801 static const struct attribute *xslcr_mio_attrs[] = {
1802         &dev_attr_enable_pinset.attr,
1803         &dev_attr_pinset.attr,
1804         &dev_attr_status.attr,
1805         NULL,
1806 };
1807
1808 static const struct attribute_group xslcr_mio_attr_group = {
1809         .attrs = (struct attribute **) xslcr_mio_attrs,
1810 };
1811
1812 /* MIO class */
1813 static struct class xslcr_mio_class = {
1814         .name =         "xslcr_mio",
1815         .owner =        THIS_MODULE,
1816 };
1817
1818 /* Reset class */
1819 static struct class xslcr_reset_class = {
1820         .name =         "xslcr_reset",
1821         .owner =        THIS_MODULE,
1822 };
1823
1824 /**
1825  * match_dev - Match function for finding a device
1826  *
1827  * @dev:        Device to find.
1828  * @data:       Device private data used for finding the device.
1829  */
1830 static int match_dev(struct device *dev, const void *data)
1831 {
1832         return dev_get_drvdata(dev) == data;
1833 }
1834
1835 /**
1836  * xslcr_create_devices - Create devices and their sysfs files.
1837  *
1838  * @dev:        pointer to the platform device structure.
1839  * @xslcr_class:pointer to the class that the devices should be registered to.
1840  * @buf:        pointer to the array of device names.
1841  * @nr:         number of devices that should be created.
1842  *
1843  * This function creates devices for MIO peripherals or reset peripherals and
1844  * registers them to their respective classes. It also creates sysfs files for
1845  * each of these devices.
1846  *
1847  * return:      0 if all the devices and sysfs files are created successfully.
1848  *              negative error if the devices or their sysfs files can't be
1849  *              created.
1850  **/
1851 static int xslcr_create_devices(struct platform_device *pdev,
1852                                 struct class *xslcr_class,
1853                                 const char * const *periph, int nr)
1854 {
1855         int i, ret;
1856
1857         for (i = 0; i < nr; i++) {
1858                 struct device   *dev;
1859
1860                 dev = device_create(xslcr_class, &pdev->dev, MKDEV(0, 0),
1861                                     (void *)(periph[i]), periph[i], i);
1862                 if (!IS_ERR(dev)) {
1863                         dev_set_drvdata(dev, (void *)(periph[i]));
1864                         if (xslcr_class == &xslcr_mio_class) {
1865                                 ret = sysfs_create_group(&dev->kobj,
1866                                                          &xslcr_mio_attr_group);
1867                         } else {
1868                                 ret = device_create_file(dev, &dev_attr_reset);
1869                         }
1870
1871                         if (ret != 0) {
1872                                 device_unregister(dev);
1873                                 dev_err(dev, "Failed to create sysfs attrs\n");
1874                                 return ret;
1875                         }
1876                 } else
1877                         return PTR_ERR(dev);
1878         }
1879
1880         return 0;
1881 }
1882
1883 /**
1884  * xslcr_remove_devices - Remove devices and their sysfs files.
1885  *
1886  * @dev:        pointer to the platform device structure.
1887  * @xslcr_class:pointer to the class that the devices should be registered to.
1888  * @buf:        pointer to the array of device names.
1889  * @nr:         number of devices that should be created.
1890  *
1891  * This function removes devices and sysfs files created by xslcr_create_devices
1892  * It also unregisters the class to which these devices were registered to.
1893  *
1894  * return:      0 if all the devices and sysfs files are removed successfully.
1895  *              negative error if the devices or their sysfs files can't be
1896  *              removed.
1897  **/
1898 static void xslcr_remove_devices(struct class *xslcr_class,
1899                                  const char * const *periph, int nr)
1900 {
1901         int i;
1902
1903         for (i = 0; i < nr; i++) {
1904                 struct device   *dev = NULL;
1905
1906                 dev = class_find_device(xslcr_class, NULL, (const void *)(periph[i]),
1907                                         match_dev);
1908                 if (dev) {
1909                         if (xslcr_class == &xslcr_mio_class) {
1910                                 sysfs_remove_group(&dev->kobj,
1911                                                    &xslcr_mio_attr_group);
1912                         } else {
1913                                 device_remove_file(dev, &dev_attr_reset);
1914                         }
1915                         put_device(dev);
1916                         device_unregister(dev);
1917                 }
1918         }
1919
1920         class_unregister(xslcr_class);
1921 }
1922
1923 /**
1924  * xslcr_get_mio_status - Initialize periph_status
1925  *
1926  * Read all the MIO control registers and determine which MIO peripherals are
1927  * enabled and initialize the global array .
1928  **/
1929
1930 static void xslcr_get_mio_status(void)
1931 {
1932         const struct xslcr_mio *mio_ptr;
1933         u32 mio_reg;
1934         int i, j, k;
1935
1936         /* num pins */
1937         for (i = 0; i < XSLCR_MIO_MAX_PIN;) {
1938                 mio_reg = xslcr_readreg(slcr->regs + (i * 4) +
1939                                         XSLCR_MIO_PIN_00_OFFSET);
1940                 if (mio_reg & XSLCR_MIO_PIN_XX_TRI_ENABLE) {
1941                         i++;
1942                         continue;
1943                 }
1944                 mio_reg &= XSLCR_MIO_LMASK;
1945                 /* num periphs */
1946                 for (j = 0; j < ARRAY_SIZE(mio_periphs); j++) {
1947                         if (mio_reg == mio_periphs[j].enable_val) {
1948                                 mio_ptr = &mio_periphs[j];
1949                                 for (k = 0; k < mio_ptr->max_sets; k++) {
1950                                         if (i == mio_ptr->set_pins[k]) {
1951                                                 /* mark the periph as enabled */
1952                                                 xslcr_set_bit(periph_status, j);
1953                                                 active_pinset[j] = k;
1954                                                 i += mio_ptr->numpins;
1955                                                 goto next_periph;
1956                                         }
1957                                 }
1958                         }
1959                 }
1960                 /* Noone claims this pin */
1961                 pr_info("MIO pin %2d not assigned(%08x)\n",
1962                         i,
1963                         xslcr_readreg(slcr->regs + (i * 4) +
1964                                 XSLCR_MIO_PIN_00_OFFSET)
1965                         );
1966                 i++;
1967 next_periph:
1968                 continue;
1969         }
1970 }
1971
1972 /************************Platform Operations*****************************/
1973 /**
1974  * xslcr_probe - Probe call for the device.
1975  *
1976  * @pdev:       handle to the platform device structure.
1977  *
1978  * This fucntion allocates resources for the SLCR device and creates sysfs
1979  * attributes for the functionality available in the SLCR block. User can
1980  * write to these sysfs files to enable/diable mio peripherals/cocks, reset
1981  * peripherals, etc.
1982  *
1983  * Return: 0 on success, negative error otherwise.
1984  **/
1985 static int xslcr_probe(struct platform_device *pdev)
1986 {
1987         int ret;
1988
1989         spin_lock_init(&slcr->io_lock);
1990
1991         ret = class_register(&xslcr_mio_class);
1992         if (ret < 0)
1993                 return ret;
1994
1995         ret = xslcr_create_devices(pdev, &xslcr_mio_class, mio_periph_name,
1996                                    ARRAY_SIZE(mio_periph_name));
1997         if (ret)
1998                 goto err_mio_class;
1999
2000         ret = class_register(&xslcr_reset_class);
2001         if (ret < 0)
2002                 goto err_mio_class;
2003
2004         ret = xslcr_create_devices(pdev, &xslcr_reset_class, reset_periph_name,
2005                                    ARRAY_SIZE(reset_periph_name));
2006         if (ret)
2007                 goto err_rst_class;
2008
2009         ret = device_create_file(&pdev->dev, &dev_attr_mio_pin_status);
2010         if (ret) {
2011                 dev_err(&pdev->dev, "Failed to create sysfs attr\n");
2012                 goto err_rst_class;
2013         }
2014
2015         platform_set_drvdata(pdev, slcr);
2016
2017         return 0;
2018
2019 err_rst_class:
2020         xslcr_remove_devices(&xslcr_reset_class, reset_periph_name,
2021                              ARRAY_SIZE(reset_periph_name));
2022 err_mio_class:
2023         xslcr_remove_devices(&xslcr_mio_class, mio_periph_name,
2024                              ARRAY_SIZE(mio_periph_name));
2025
2026         return ret;
2027 }
2028
2029 static struct of_device_id slcr_of_match[] = {
2030         { .compatible = "xlnx,zynq-slcr", },
2031         { /* end of list */ },
2032 };
2033 MODULE_DEVICE_TABLE(of, slcr_of_match);
2034
2035 /* Driver Structure */
2036 static struct platform_driver xslcr_driver = {
2037         .probe          = xslcr_probe,
2038         .driver         = {
2039                 .name   = DRIVER_NAME,
2040                 .owner  = THIS_MODULE,
2041                 .of_match_table = slcr_of_match,
2042         },
2043 };
2044
2045 /**
2046  * xslcr_arch_init -  Register the SLCR
2047  *
2048  * Returns 0 on success, otherwise negative error.
2049  */
2050 static int __init xslcr_arch_init(void)
2051 {
2052         return platform_driver_register(&xslcr_driver);
2053 }
2054 module_init(xslcr_arch_init);
2055
2056 /**
2057  * zynq_slcr_cpu_start - Start cpu
2058  * @cpu:        cpu number
2059  */
2060 void zynq_slcr_cpu_start(int cpu)
2061 {
2062         /* enable CPUn */
2063         writel(SLCR_A9_CPU_CLKSTOP << cpu,
2064                zynq_slcr_base + SLCR_A9_CPU_RST_CTRL);
2065         /* enable CLK for CPUn */
2066         writel(0x0 << cpu, zynq_slcr_base + SLCR_A9_CPU_RST_CTRL);
2067 }
2068
2069 /**
2070  * zynq_slcr_cpu_stop - Stop cpu
2071  * @cpu:        cpu number
2072  */
2073 void zynq_slcr_cpu_stop(int cpu)
2074 {
2075         /* stop CLK and reset CPUn */
2076         writel((SLCR_A9_CPU_CLKSTOP | SLCR_A9_CPU_RST) << cpu,
2077                zynq_slcr_base + SLCR_A9_CPU_RST_CTRL);
2078 }
2079
2080 /**
2081  * zynq_slcr_init
2082  * Returns 0 on success, negative errno otherwise.
2083  *
2084  * Called early during boot from platform code to remap SLCR area.
2085  */
2086 int __init zynq_slcr_init(void)
2087 {
2088         struct device_node *np;
2089
2090         np = of_find_compatible_node(NULL, NULL, "xlnx,zynq-slcr");
2091         if (!np) {
2092                 pr_err("%s: no slcr node found\n", __func__);
2093                 BUG();
2094         }
2095
2096         zynq_slcr_base = of_iomap(np, 0);
2097         if (!zynq_slcr_base) {
2098                 pr_err("%s: Unable to map I/O memory\n", __func__);
2099                 BUG();
2100         }
2101
2102         slcr = kzalloc(sizeof(*slcr), GFP_KERNEL);
2103         if (!slcr) {
2104                 pr_err("%s: Unable to allocate memory for driver data\n",
2105                                 __func__);
2106                 BUG();
2107         }
2108
2109         slcr->regs = zynq_slcr_base;
2110
2111         /* init periph_status based on the data from MIO control registers */
2112         xslcr_get_mio_status();
2113
2114         /* unlock the SLCR so that registers can be changed */
2115         writel(SLCR_UNLOCK_MAGIC, zynq_slcr_base + SLCR_UNLOCK);
2116
2117         pr_info("%s mapped to %p\n", np->name, zynq_slcr_base);
2118
2119         zynq_clock_init(zynq_slcr_base);
2120
2121         of_node_put(np);
2122
2123         return 0;
2124 }