4 * Copyright (c) 2011-2013 Xilinx Inc.
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.
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
17 #include <linux/export.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>
32 #define SLCR_UNLOCK_MAGIC 0xDF0D
33 #define SLCR_UNLOCK 0x8 /* SCLR unlock register */
35 #define DRIVER_NAME "xslcr"
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 */
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
66 #define XSLCR_MIO_LMASK 0x000000FE
68 #define XSLCR_MIO_PIN_XX_TRI_ENABLE 0x00000001
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)
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)
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)
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)
95 /* The following constants define the number of pins associated with each
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
122 /* The following two constants define the indices of the MIO peripherals EMAC0/1
123 * in the array mio_periph_name */
127 #define XSLCR_MDIO_PIN_0 52
128 #define XSLCR_MIO_MAX_PIN 54
130 #define xslcr_writereg(offset, val) __raw_writel(val, offset)
131 #define xslcr_readreg(offset) __raw_readl(offset)
134 #define SLCR_PS_RST_CTRL_OFFSET 0x200 /* PS Software Reset Control */
136 #define SLCR_A9_CPU_CLKSTOP 0x10
137 #define SLCR_A9_CPU_RST 0x1
139 #define SLCR_A9_CPU_RST_CTRL 0x244 /* CPU Software Reset Control */
140 #define SLCR_REBOOT_STATUS 0x258 /* PS Reboot Status */
142 void __iomem *zynq_slcr_base;
145 * struct xslcr - slcr device data.
146 * @regs: baseaddress of device.
147 * @io_lock: spinlock used for synchronization.
155 static struct xslcr *slcr;
158 * xslcr_mio - Holds information required to enable/disable a MIO peripheral.
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
173 * xslcr_periph_reset - Holds information required to reset a peripheral.
175 * @reg_offset: offset of the reset reg for the peripheral
176 * @reset_mask: mask to reset the peripheral
178 struct xslcr_periph_reset {
183 /* MIO peripheral names */
184 static const char * const mio_periph_name[] = {
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)];
281 * The following arrays contain the first pin in each pin set of a MIO
282 * corresponding peripheral.
284 static const int emac0_pins[] = {
288 static const int emac1_pins[] = {
292 static const int qspi0_pins[] = {
296 static const int qspi0_sel_pins[] = {
300 static const int qspi1_pins[] = {
304 static const int qspi1_sel_pins[] = {
308 static const int qspi_foc_pins[] = {
312 static const int trace_data2_pins[] = {
316 static const int trace_data4_pins[] = {
320 static const int trace_data8_pins[] = {
324 static const int trace_data16_pins[] = {
328 static const int usb0_pins[] = {
332 static const int usb1_pins[] = {
336 static const int smc_a25_pins[] = {
340 static const int smc_cs_pins[] = {
344 static const int sram_nor_pins[] = {
348 static const int nand_pins[] = {
352 static const int nand_cs_pins[] = {
356 static const int gpio00_pins[] = {
360 static const int gpio01_pins[] = {
365 static const int gpio02_pins[] = {
369 static const int gpio03_pins[] = {
373 static const int gpio04_pins[] = {
377 static const int gpio05_pins[] = {
381 static const int gpio06_pins[] = {
385 static const int gpio07_pins[] = {
390 static const int gpio08_pins[] = {
394 static const int gpio09_pins[] = {
399 static const int gpio10_pins[] = {
403 static const int gpio11_pins[] = {
407 static const int gpio12_pins[] = {
411 static const int gpio13_pins[] = {
415 static const int gpio14_pins[] = {
420 static const int gpio15_pins[] = {
424 static const int gpio16_pins[] = {
428 static const int gpio17_pins[] = {
432 static const int gpio18_pins[] = {
436 static const int gpio19_pins[] = {
440 static const int gpio20_pins[] = {
444 static const int gpio21_pins[] = {
449 static const int gpio22_pins[] = {
453 static const int gpio23_pins[] = {
457 static const int gpio24_pins[] = {
461 static const int gpio25_pins[] = {
465 static const int gpio26_pins[] = {
469 static const int gpio27_pins[] = {
474 static const int gpio28_pins[] = {
478 static const int gpio29_pins[] = {
483 static const int gpio30_pins[] = {
487 static const int gpio31_pins[] = {
491 static const int gpio32_pins[] = {
495 static const int gpio33_pins[] = {
499 static const int gpio34_pins[] = {
504 static const int gpio35_pins[] = {
508 static const int gpio36_pins[] = {
512 static const int gpio37_pins[] = {
516 static const int gpio38_pins[] = {
520 static const int gpio39_pins[] = {
524 static const int gpio40_pins[] = {
528 static const int gpio41_pins[] = {
532 static const int gpio42_pins[] = {
536 static const int gpio43_pins[] = {
540 static const int gpio44_pins[] = {
545 static const int gpio45_pins[] = {
549 static const int gpio46_pins[] = {
553 static const int gpio47_pins[] = {
557 static const int gpio48_pins[] = {
561 static const int gpio49_pins[] = {
565 static const int gpio50_pins[] = {
569 static const int gpio51_pins[] = {
573 static const int gpio52_pins[] = {
577 static const int gpio53_pins[] = {
581 static const int can0_pins[] = {
582 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50
585 static const int can1_pins[] = {
586 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52
589 static const int iic0_pins[] = {
590 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50
593 static const int iic1_pins[] = {
594 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52
597 static const int jtag0_pins[] = {
601 static const int wdt_pins[] = {
605 static const int mdio0_pins[] = {
609 static const int sdio0_pins[] = {
613 static const int sdio1_pins[] = {
617 static const int mdio1_pins[] = {
621 static const int spi0_pins[] = {
625 static const int spi1_pins[] = {
629 static const int ttc0_pins[] = {
633 static const int ttc1_pins[] = {
637 static const int uart0_pins[] = {
638 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50
641 static const int uart1_pins[] = {
642 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52
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[] = {
651 ARRAY_SIZE(emac0_pins),
652 XSLCR_MIO_NUM_EMAC_PINS,
653 XSLCR_MIO_PIN_EMAC_ENABLE,
657 ARRAY_SIZE(emac1_pins),
658 XSLCR_MIO_NUM_EMAC_PINS,
659 XSLCR_MIO_PIN_EMAC_ENABLE,
663 ARRAY_SIZE(qspi0_pins),
664 XSLCR_MIO_NUM_QSPI_PINS,
665 XSLCR_MIO_PIN_QSPI_ENABLE,
669 ARRAY_SIZE(qspi0_sel_pins),
670 XSLCR_MIO_NUM_QSPI_SEL_PINS,
671 XSLCR_MIO_PIN_QSPI_ENABLE,
675 ARRAY_SIZE(qspi1_pins),
676 XSLCR_MIO_NUM_QSPI_PINS,
677 XSLCR_MIO_PIN_QSPI_ENABLE,
681 ARRAY_SIZE(qspi1_sel_pins),
682 XSLCR_MIO_NUM_QSPI_SEL_PINS,
683 XSLCR_MIO_PIN_QSPI_ENABLE,
686 ARRAY_SIZE(qspi_foc_pins),
687 XSLCR_MIO_NUM_QSPI_FOC_PINS,
688 XSLCR_MIO_PIN_QSPI_ENABLE,
692 ARRAY_SIZE(trace_data2_pins),
693 XSLCR_MIO_NUM_TRACE_DATA2_PINS,
694 XSLCR_MIO_PIN_TRACE_PORT_ENABLE,
698 ARRAY_SIZE(trace_data4_pins),
699 XSLCR_MIO_NUM_TRACE_DATA4_PINS,
700 XSLCR_MIO_PIN_TRACE_PORT_ENABLE,
704 ARRAY_SIZE(trace_data8_pins),
705 XSLCR_MIO_NUM_TRACE_DATA8_PINS,
706 XSLCR_MIO_PIN_TRACE_PORT_ENABLE,
710 ARRAY_SIZE(trace_data16_pins),
711 XSLCR_MIO_NUM_TRACE_DATA4_PINS,
712 XSLCR_MIO_PIN_TRACE_PORT_ENABLE,
716 ARRAY_SIZE(usb0_pins),
717 XSLCR_MIO_NUM_USB_PINS,
718 XSLCR_MIO_PIN_USB_ENABLE,
722 ARRAY_SIZE(usb1_pins),
723 XSLCR_MIO_NUM_USB_PINS,
724 XSLCR_MIO_PIN_USB_ENABLE,
728 ARRAY_SIZE(smc_a25_pins),
729 XSLCR_MIO_NUM_SMC_A25_PINS,
730 XSLCR_MIO_PIN_SRAM_NOR_ENABLE,
734 ARRAY_SIZE(smc_cs_pins),
735 XSLCR_MIO_NUM_SMC_CS_PINS,
736 XSLCR_MIO_PIN_SRAM_NOR_ENABLE,
740 ARRAY_SIZE(sram_nor_pins),
741 XSLCR_MIO_NUM_SRAM_NOR_PINS,
742 XSLCR_MIO_PIN_SRAM_NOR_ENABLE,
746 ARRAY_SIZE(nand_pins),
747 XSLCR_MIO_NUM_NAND_PINS,
748 XSLCR_MIO_PIN_NAND_ENABLE,
752 ARRAY_SIZE(nand_cs_pins),
753 XSLCR_MIO_NUM_NAND_CS_PINS,
754 XSLCR_MIO_PIN_NAND_ENABLE,
758 ARRAY_SIZE(gpio00_pins),
759 XSLCR_MIO_NUM_GPIO_PINS,
760 XSLCR_MIO_PIN_GPIO_ENABLE,
764 ARRAY_SIZE(gpio01_pins),
765 XSLCR_MIO_NUM_GPIO_PINS,
766 XSLCR_MIO_PIN_GPIO_ENABLE,
770 ARRAY_SIZE(gpio02_pins),
771 XSLCR_MIO_NUM_GPIO_PINS,
772 XSLCR_MIO_PIN_GPIO_ENABLE,
776 ARRAY_SIZE(gpio03_pins),
777 XSLCR_MIO_NUM_GPIO_PINS,
778 XSLCR_MIO_PIN_GPIO_ENABLE,
782 ARRAY_SIZE(gpio04_pins),
783 XSLCR_MIO_NUM_GPIO_PINS,
784 XSLCR_MIO_PIN_GPIO_ENABLE,
788 ARRAY_SIZE(gpio05_pins),
789 XSLCR_MIO_NUM_GPIO_PINS,
790 XSLCR_MIO_PIN_GPIO_ENABLE,
794 ARRAY_SIZE(gpio06_pins),
795 XSLCR_MIO_NUM_GPIO_PINS,
796 XSLCR_MIO_PIN_GPIO_ENABLE,
800 ARRAY_SIZE(gpio07_pins),
801 XSLCR_MIO_NUM_GPIO_PINS,
802 XSLCR_MIO_PIN_GPIO_ENABLE,
806 ARRAY_SIZE(gpio08_pins),
807 XSLCR_MIO_NUM_GPIO_PINS,
808 XSLCR_MIO_PIN_GPIO_ENABLE,
812 ARRAY_SIZE(gpio09_pins),
813 XSLCR_MIO_NUM_GPIO_PINS,
814 XSLCR_MIO_PIN_GPIO_ENABLE,
818 ARRAY_SIZE(gpio10_pins),
819 XSLCR_MIO_NUM_GPIO_PINS,
820 XSLCR_MIO_PIN_GPIO_ENABLE,
824 ARRAY_SIZE(gpio11_pins),
825 XSLCR_MIO_NUM_GPIO_PINS,
826 XSLCR_MIO_PIN_GPIO_ENABLE,
830 ARRAY_SIZE(gpio12_pins),
831 XSLCR_MIO_NUM_GPIO_PINS,
832 XSLCR_MIO_PIN_GPIO_ENABLE,
836 ARRAY_SIZE(gpio13_pins),
837 XSLCR_MIO_NUM_GPIO_PINS,
838 XSLCR_MIO_PIN_GPIO_ENABLE,
842 ARRAY_SIZE(gpio14_pins),
843 XSLCR_MIO_NUM_GPIO_PINS,
844 XSLCR_MIO_PIN_GPIO_ENABLE,
848 ARRAY_SIZE(gpio15_pins),
849 XSLCR_MIO_NUM_GPIO_PINS,
850 XSLCR_MIO_PIN_GPIO_ENABLE,
854 ARRAY_SIZE(gpio16_pins),
855 XSLCR_MIO_NUM_GPIO_PINS,
856 XSLCR_MIO_PIN_GPIO_ENABLE,
860 ARRAY_SIZE(gpio17_pins),
861 XSLCR_MIO_NUM_GPIO_PINS,
862 XSLCR_MIO_PIN_GPIO_ENABLE,
866 ARRAY_SIZE(gpio18_pins),
867 XSLCR_MIO_NUM_GPIO_PINS,
868 XSLCR_MIO_PIN_GPIO_ENABLE,
872 ARRAY_SIZE(gpio19_pins),
873 XSLCR_MIO_NUM_GPIO_PINS,
874 XSLCR_MIO_PIN_GPIO_ENABLE,
878 ARRAY_SIZE(gpio20_pins),
879 XSLCR_MIO_NUM_GPIO_PINS,
880 XSLCR_MIO_PIN_GPIO_ENABLE,
884 ARRAY_SIZE(gpio21_pins),
885 XSLCR_MIO_NUM_GPIO_PINS,
886 XSLCR_MIO_PIN_GPIO_ENABLE,
890 ARRAY_SIZE(gpio22_pins),
891 XSLCR_MIO_NUM_GPIO_PINS,
892 XSLCR_MIO_PIN_GPIO_ENABLE,
896 ARRAY_SIZE(gpio23_pins),
897 XSLCR_MIO_NUM_GPIO_PINS,
898 XSLCR_MIO_PIN_GPIO_ENABLE,
902 ARRAY_SIZE(gpio24_pins),
903 XSLCR_MIO_NUM_GPIO_PINS,
904 XSLCR_MIO_PIN_GPIO_ENABLE,
908 ARRAY_SIZE(gpio25_pins),
909 XSLCR_MIO_NUM_GPIO_PINS,
910 XSLCR_MIO_PIN_GPIO_ENABLE,
914 ARRAY_SIZE(gpio26_pins),
915 XSLCR_MIO_NUM_GPIO_PINS,
916 XSLCR_MIO_PIN_GPIO_ENABLE,
920 ARRAY_SIZE(gpio27_pins),
921 XSLCR_MIO_NUM_GPIO_PINS,
922 XSLCR_MIO_PIN_GPIO_ENABLE,
926 ARRAY_SIZE(gpio28_pins),
927 XSLCR_MIO_NUM_GPIO_PINS,
928 XSLCR_MIO_PIN_GPIO_ENABLE,
932 ARRAY_SIZE(gpio29_pins),
933 XSLCR_MIO_NUM_GPIO_PINS,
934 XSLCR_MIO_PIN_GPIO_ENABLE,
938 ARRAY_SIZE(gpio30_pins),
939 XSLCR_MIO_NUM_GPIO_PINS,
940 XSLCR_MIO_PIN_GPIO_ENABLE,
944 ARRAY_SIZE(gpio31_pins),
945 XSLCR_MIO_NUM_GPIO_PINS,
946 XSLCR_MIO_PIN_GPIO_ENABLE,
950 ARRAY_SIZE(gpio32_pins),
951 XSLCR_MIO_NUM_GPIO_PINS,
952 XSLCR_MIO_PIN_GPIO_ENABLE,
956 ARRAY_SIZE(gpio33_pins),
957 XSLCR_MIO_NUM_GPIO_PINS,
958 XSLCR_MIO_PIN_GPIO_ENABLE,
962 ARRAY_SIZE(gpio34_pins),
963 XSLCR_MIO_NUM_GPIO_PINS,
964 XSLCR_MIO_PIN_GPIO_ENABLE,
968 ARRAY_SIZE(gpio35_pins),
969 XSLCR_MIO_NUM_GPIO_PINS,
970 XSLCR_MIO_PIN_GPIO_ENABLE,
974 ARRAY_SIZE(gpio36_pins),
975 XSLCR_MIO_NUM_GPIO_PINS,
976 XSLCR_MIO_PIN_GPIO_ENABLE,
980 ARRAY_SIZE(gpio37_pins),
981 XSLCR_MIO_NUM_GPIO_PINS,
982 XSLCR_MIO_PIN_GPIO_ENABLE,
986 ARRAY_SIZE(gpio38_pins),
987 XSLCR_MIO_NUM_GPIO_PINS,
988 XSLCR_MIO_PIN_GPIO_ENABLE,
992 ARRAY_SIZE(gpio39_pins),
993 XSLCR_MIO_NUM_GPIO_PINS,
994 XSLCR_MIO_PIN_GPIO_ENABLE,
998 ARRAY_SIZE(gpio40_pins),
999 XSLCR_MIO_NUM_GPIO_PINS,
1000 XSLCR_MIO_PIN_GPIO_ENABLE,
1004 ARRAY_SIZE(gpio41_pins),
1005 XSLCR_MIO_NUM_GPIO_PINS,
1006 XSLCR_MIO_PIN_GPIO_ENABLE,
1010 ARRAY_SIZE(gpio42_pins),
1011 XSLCR_MIO_NUM_GPIO_PINS,
1012 XSLCR_MIO_PIN_GPIO_ENABLE,
1016 ARRAY_SIZE(gpio43_pins),
1017 XSLCR_MIO_NUM_GPIO_PINS,
1018 XSLCR_MIO_PIN_GPIO_ENABLE,
1022 ARRAY_SIZE(gpio44_pins),
1023 XSLCR_MIO_NUM_GPIO_PINS,
1024 XSLCR_MIO_PIN_GPIO_ENABLE,
1028 ARRAY_SIZE(gpio45_pins),
1029 XSLCR_MIO_NUM_GPIO_PINS,
1030 XSLCR_MIO_PIN_GPIO_ENABLE,
1034 ARRAY_SIZE(gpio46_pins),
1035 XSLCR_MIO_NUM_GPIO_PINS,
1036 XSLCR_MIO_PIN_GPIO_ENABLE,
1040 ARRAY_SIZE(gpio47_pins),
1041 XSLCR_MIO_NUM_GPIO_PINS,
1042 XSLCR_MIO_PIN_GPIO_ENABLE,
1046 ARRAY_SIZE(gpio48_pins),
1047 XSLCR_MIO_NUM_GPIO_PINS,
1048 XSLCR_MIO_PIN_GPIO_ENABLE,
1052 ARRAY_SIZE(gpio49_pins),
1053 XSLCR_MIO_NUM_GPIO_PINS,
1054 XSLCR_MIO_PIN_GPIO_ENABLE,
1058 ARRAY_SIZE(gpio50_pins),
1059 XSLCR_MIO_NUM_GPIO_PINS,
1060 XSLCR_MIO_PIN_GPIO_ENABLE,
1064 ARRAY_SIZE(gpio51_pins),
1065 XSLCR_MIO_NUM_GPIO_PINS,
1066 XSLCR_MIO_PIN_GPIO_ENABLE,
1070 ARRAY_SIZE(gpio52_pins),
1071 XSLCR_MIO_NUM_GPIO_PINS,
1072 XSLCR_MIO_PIN_GPIO_ENABLE,
1076 ARRAY_SIZE(gpio53_pins),
1077 XSLCR_MIO_NUM_GPIO_PINS,
1078 XSLCR_MIO_PIN_GPIO_ENABLE,
1082 ARRAY_SIZE(can0_pins),
1083 XSLCR_MIO_NUM_CAN_PINS,
1084 XSLCR_MIO_PIN_CAN_ENABLE,
1088 ARRAY_SIZE(can1_pins),
1089 XSLCR_MIO_NUM_CAN_PINS,
1090 XSLCR_MIO_PIN_CAN_ENABLE,
1094 ARRAY_SIZE(iic0_pins),
1095 XSLCR_MIO_NUM_IIC_PINS,
1096 XSLCR_MIO_PIN_IIC_ENABLE,
1100 ARRAY_SIZE(iic1_pins),
1101 XSLCR_MIO_NUM_IIC_PINS,
1102 XSLCR_MIO_PIN_IIC_ENABLE,
1106 ARRAY_SIZE(jtag0_pins),
1107 XSLCR_MIO_NUM_JTAG_PINS,
1108 XSLCR_MIO_PIN_JTAG_ENABLE,
1112 ARRAY_SIZE(wdt_pins),
1113 XSLCR_MIO_NUM_WDT_PINS,
1114 XSLCR_MIO_PIN_WDT_ENABLE,
1118 ARRAY_SIZE(mdio0_pins),
1119 XSLCR_MIO_NUM_MDIO_PINS,
1120 XSLCR_MIO_PIN_MDIO0_ENABLE,
1124 ARRAY_SIZE(sdio0_pins),
1125 XSLCR_MIO_NUM_SDIO_PINS,
1126 XSLCR_MIO_PIN_SDIO_ENABLE,
1130 ARRAY_SIZE(sdio1_pins),
1131 XSLCR_MIO_NUM_SDIO_PINS,
1132 XSLCR_MIO_PIN_SDIO_ENABLE,
1136 ARRAY_SIZE(mdio1_pins),
1137 XSLCR_MIO_NUM_MDIO_PINS,
1138 XSLCR_MIO_PIN_MDIO1_ENABLE,
1142 ARRAY_SIZE(spi0_pins),
1143 XSLCR_MIO_NUM_SPI_PINS,
1144 XSLCR_MIO_PIN_SPI_ENABLE,
1148 ARRAY_SIZE(spi1_pins),
1149 XSLCR_MIO_NUM_SPI_PINS,
1150 XSLCR_MIO_PIN_SPI_ENABLE,
1154 ARRAY_SIZE(ttc0_pins),
1155 XSLCR_MIO_NUM_TTC_PINS,
1156 XSLCR_MIO_PIN_TTC_ENABLE,
1160 ARRAY_SIZE(ttc1_pins),
1161 XSLCR_MIO_NUM_TTC_PINS,
1162 XSLCR_MIO_PIN_TTC_ENABLE,
1166 ARRAY_SIZE(uart0_pins),
1167 XSLCR_MIO_NUM_UART_PINS,
1168 XSLCR_MIO_PIN_UART_ENABLE,
1172 ARRAY_SIZE(uart1_pins),
1173 XSLCR_MIO_NUM_UART_PINS,
1174 XSLCR_MIO_PIN_UART_ENABLE,
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
1183 static u32 periph_status[DIV_ROUND_UP(ARRAY_SIZE(mio_periphs), 32)];
1185 /* Peripherals that can be reset thru SLCR */
1186 static const char * const reset_periph_name[] = {
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 },
1306 * zynq_slcr_system_reset - Reset the entire system.
1308 void zynq_slcr_system_reset(void)
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?
1317 writel(SLCR_UNLOCK_MAGIC, zynq_slcr_base + SLCR_UNLOCK);
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.
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);
1330 * xslcr_write - Write to a register in SLCR block
1332 * @offset: Register offset in SLCR block
1333 * @val: Value to write to the register
1335 void xslcr_write(u32 val, u32 offset)
1337 xslcr_writereg(slcr->regs + offset, val);
1339 EXPORT_SYMBOL(xslcr_write);
1342 * xslcr_read - Read a register in SLCR block
1344 * @offset: Register offset in SLCR block
1346 * return: Value read from the SLCR register
1348 u32 xslcr_read(u32 offset)
1350 return xslcr_readreg(slcr->regs + offset);
1352 EXPORT_SYMBOL(xslcr_read);
1355 * xslcr_init_preload_fpga - Disable communication from the PL to PS.
1357 void xslcr_init_preload_fpga(void)
1360 /* Assert FPGA top level output resets */
1361 xslcr_write(0xF, XSLCR_FPGA_RST_CTRL_OFFSET);
1363 /* Disable level shifters */
1364 xslcr_write(0, XSLCR_LVL_SHFTR_EN_OFFSET);
1366 /* Enable output level shifters */
1367 xslcr_write(0xA, XSLCR_LVL_SHFTR_EN_OFFSET);
1369 EXPORT_SYMBOL(xslcr_init_preload_fpga);
1372 * xslcr_init_postload_fpga - Re-enable communication from the PL to PS.
1374 void xslcr_init_postload_fpga(void)
1377 /* Enable level shifters */
1378 xslcr_write(0xf, XSLCR_LVL_SHFTR_EN_OFFSET);
1380 /* Deassert AXI interface resets */
1381 xslcr_write(0, XSLCR_FPGA_RST_CTRL_OFFSET);
1383 EXPORT_SYMBOL(xslcr_init_postload_fpga);
1386 * xslcr_set_bit - Set a bit
1388 * @data: Address of the data in which a bit is to be set
1389 * @bit: Bit number to set
1391 static inline void xslcr_set_bit(u32 *data, unsigned int bit)
1393 unsigned long mask = 1UL << (bit & 31);
1395 *(data + (bit >> 5)) |= mask;
1399 * xslcr_clear_bit - Clear a bit
1401 * @data: Address of the data in which a bit is to be cleared
1402 * @bit: Bit number to clear
1404 static inline void xslcr_clear_bit(u32 *data, unsigned int bit)
1406 unsigned long mask = 1UL << (bit & 31);
1408 *(data + (bit >> 5)) &= ~mask;
1412 * xslcr_test_bit - Check if a bit is set
1414 * @data: Address of the data in which a bit is to be checked
1415 * @bit: Bit number to check
1417 * return: True or false
1419 static inline int xslcr_test_bit(u32 *data, unsigned int bit)
1421 unsigned long mask = 1UL << (bit & 31);
1423 return (*(data + (bit >> 5)) & mask) != 0;
1427 * xslcr_mio_isavailable - Check if a MIO pin is available for assignment.
1429 * @pin MIO pin to be checked.
1431 * return: -EBUSY if the pin is in use.
1432 * 0 if the pin is not assigned.
1434 static int xslcr_mio_isavailable(u32 pin)
1438 reg = xslcr_readreg(slcr->regs + XSLCR_MIO_PIN_00_OFFSET + (pin * 4));
1439 if (reg & XSLCR_MIO_PIN_XX_TRI_ENABLE)
1442 return -EBUSY; /* pin is assigned */
1446 * xslcr_enable_mio_peripheral - Enable a MIO peripheral.
1448 * @mio: id used to lookup the data needed to enable the peripheral.
1450 * This function enables a MIO peripheral on a pinset previously set by the
1451 * user, thru sysfs attribute 'pinset'.
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.
1458 static int xslcr_enable_mio_peripheral(int mio)
1460 const struct xslcr_mio *mio_ptr;
1461 unsigned long flags;
1462 int pin_set, pin, i;
1464 /* enable the peripheral only if it hasn't been already enabled */
1465 if (xslcr_test_bit(periph_status, mio))
1468 /* get the pin set */
1469 pin_set = active_pinset[mio];
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]);
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);
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);
1494 /* mark that the peripheral has been enabled */
1495 xslcr_set_bit(periph_status, mio);
1496 spin_unlock_irqrestore(&slcr->io_lock, flags);
1498 pr_debug("Enabled peripheral %s on pinset %d\n",
1499 mio_periph_name[mio], pin_set);
1504 * xslcr_disable_mio_peripheral - Disable a MIO peripheral.
1506 * @mio: id used to lookup the data needed to enable the peripheral.
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.
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.
1516 static int xslcr_disable_mio_peripheral(int mio)
1518 const struct xslcr_mio *mio_ptr;
1519 unsigned long flags;
1520 int pin_set, pin, i;
1523 /* disable the peripheral only if it has been already enabled */
1524 if (!xslcr_test_bit(periph_status, mio))
1527 /* get the pin set */
1528 pin_set = active_pinset[mio];
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);
1537 pin = mio_ptr->set_pins[pin_set]; /* 1st pin */
1538 for (i = 0; i < mio_ptr->numpins; i++) {
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 +
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);
1552 spin_lock_irqsave(&slcr->io_lock, flags);
1553 /* release all pins in the set */
1554 for (i = 0; i < mio_ptr->numpins; i++) {
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);
1564 /* mark that the peripheral has been disabled */
1565 xslcr_clear_bit(periph_status, mio);
1566 spin_unlock_irqrestore(&slcr->io_lock, flags);
1568 pr_debug("Disabled peripheral %s on pinset %d\n",
1569 mio_periph_name[mio], pin_set);
1574 * xslcr_config_mio_peripheral - Enable/disable a MIO peripheral.
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.
1581 * This function parses the user data in buf and enables/disables the MIO
1582 * peripheral specified by dev.
1584 * return: 0 if the peripheral is enabled/disabled successfully.
1585 * negative error if the peripheral configuration failed.
1587 static ssize_t xslcr_config_mio_peripheral(struct device *dev,
1588 struct device_attribute *attr,
1589 const char *buf, size_t size)
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)
1600 if (mio == ARRAY_SIZE(mio_periph_name)) {
1601 dev_err(dev, "Invalid peripheral specified\n");
1605 ret = kstrtoul(buf, 10, &en);
1606 if ((ret) || (en > 1)) {
1607 dev_err(dev, "Invalid user argument\n");
1612 ret = xslcr_enable_mio_peripheral(mio);
1614 ret = xslcr_disable_mio_peripheral(mio);
1619 static DEVICE_ATTR(enable_pinset, 0222, NULL, xslcr_config_mio_peripheral);
1622 * xslcr_store_pinset - Store a pinset for a MIO peripheral.
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.
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.
1633 * return: 0 if the peripheral is enabled/disabled successfully.
1634 * negative error if the peripheral configuration failed.
1636 static ssize_t xslcr_store_pinset(struct device *dev,
1637 struct device_attribute *attr,
1638 const char *buf, size_t size)
1640 unsigned long pin_set;
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)
1649 if (mio == ARRAY_SIZE(mio_periph_name)) {
1650 dev_err(dev, "Invalid peripheral specified\n");
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");
1661 /* store the pin set */
1662 active_pinset[mio] = pin_set;
1663 dev_dbg(dev, "Pinset=%d\n", (unsigned int)pin_set);
1668 static DEVICE_ATTR(pinset, 222, NULL, xslcr_store_pinset);
1671 * xslcr_get_periph_status - Get the current status of a MIO peripheral.
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.
1677 * This function returns the current status of a MIO peripheral specified by the
1680 * return: negative error if an invalid peripheral is specified or size of
1681 * the buf, with the status of the peripheral.
1683 static ssize_t xslcr_get_periph_status(struct device *dev,
1684 struct device_attribute *attr, char *buf)
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)
1695 if (mio == ARRAY_SIZE(mio_periph_name)) {
1696 dev_err(dev, "Invalid peripheral specified\n");
1700 size = sprintf(buf, "%d\n", xslcr_test_bit(periph_status, mio));
1705 static DEVICE_ATTR(status, 0444, xslcr_get_periph_status, NULL);
1708 * xslcr_reset_periph - Reset a peripheral within PS.
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.
1715 * This function performs a software reset on the peripheral specified by the
1718 * return: negative error if an invalid peripheral is specified or size of the
1719 * buf if the peripheral is reset successfully.
1721 static ssize_t xslcr_reset_periph(struct device *dev,
1722 struct device_attribute *attr,
1723 const char *buf, size_t size)
1725 unsigned long flags, rst;
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)
1735 if (i == ARRAY_SIZE(reset_periph_name)) {
1736 dev_err(dev, "Invalid peripheral specified\n");
1740 ret = kstrtoul(buf, 10, &rst);
1742 dev_err(dev, "Invalid user argument\n");
1746 /* reset the peripheral */
1747 spin_lock_irqsave(&slcr->io_lock, flags);
1749 /* read the register and modify only the specified bit */
1750 reg = xslcr_readreg(slcr->regs + reset_info[i].reg_offset);
1752 reg &= ~(reset_info[i].reset_mask);
1754 reg |= reset_info[i].reset_mask;
1756 xslcr_writereg(slcr->regs + reset_info[i].reg_offset, reg);
1758 spin_unlock_irqrestore(&slcr->io_lock, flags);
1762 static DEVICE_ATTR(reset, 0222, NULL, xslcr_reset_periph);
1765 * show_mio_pin_status - Get the status of all the MIO pins.
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.
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.
1775 * return: length of the buffer containing the mio pin status.
1777 static ssize_t show_mio_pin_status(struct device *dev,
1778 struct device_attribute *attr, char *buf)
1785 for (i = 0; i < 54; i++) {
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);
1793 status = sprintf(buf, "0x%016Lx\n", pin_status);
1798 static DEVICE_ATTR(mio_pin_status, 0444, show_mio_pin_status, NULL);
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,
1808 static const struct attribute_group xslcr_mio_attr_group = {
1809 .attrs = (struct attribute **) xslcr_mio_attrs,
1813 static struct class xslcr_mio_class = {
1814 .name = "xslcr_mio",
1815 .owner = THIS_MODULE,
1819 static struct class xslcr_reset_class = {
1820 .name = "xslcr_reset",
1821 .owner = THIS_MODULE,
1825 * match_dev - Match function for finding a device
1827 * @dev: Device to find.
1828 * @data: Device private data used for finding the device.
1830 static int match_dev(struct device *dev, const void *data)
1832 return dev_get_drvdata(dev) == data;
1836 * xslcr_create_devices - Create devices and their sysfs files.
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.
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.
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
1851 static int xslcr_create_devices(struct platform_device *pdev,
1852 struct class *xslcr_class,
1853 const char * const *periph, int nr)
1857 for (i = 0; i < nr; i++) {
1860 dev = device_create(xslcr_class, &pdev->dev, MKDEV(0, 0),
1861 (void *)(periph[i]), periph[i], i);
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);
1868 ret = device_create_file(dev, &dev_attr_reset);
1872 device_unregister(dev);
1873 dev_err(dev, "Failed to create sysfs attrs\n");
1877 return PTR_ERR(dev);
1884 * xslcr_remove_devices - Remove devices and their sysfs files.
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.
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.
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
1898 static void xslcr_remove_devices(struct class *xslcr_class,
1899 const char * const *periph, int nr)
1903 for (i = 0; i < nr; i++) {
1904 struct device *dev = NULL;
1906 dev = class_find_device(xslcr_class, NULL, (const void *)(periph[i]),
1909 if (xslcr_class == &xslcr_mio_class) {
1910 sysfs_remove_group(&dev->kobj,
1911 &xslcr_mio_attr_group);
1913 device_remove_file(dev, &dev_attr_reset);
1916 device_unregister(dev);
1920 class_unregister(xslcr_class);
1924 * xslcr_get_mio_status - Initialize periph_status
1926 * Read all the MIO control registers and determine which MIO peripherals are
1927 * enabled and initialize the global array .
1930 static void xslcr_get_mio_status(void)
1932 const struct xslcr_mio *mio_ptr;
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) {
1944 mio_reg &= XSLCR_MIO_LMASK;
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;
1960 /* Noone claims this pin */
1961 pr_info("MIO pin %2d not assigned(%08x)\n",
1963 xslcr_readreg(slcr->regs + (i * 4) +
1964 XSLCR_MIO_PIN_00_OFFSET)
1972 /************************Platform Operations*****************************/
1974 * xslcr_probe - Probe call for the device.
1976 * @pdev: handle to the platform device structure.
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
1983 * Return: 0 on success, negative error otherwise.
1985 static int xslcr_probe(struct platform_device *pdev)
1989 spin_lock_init(&slcr->io_lock);
1991 ret = class_register(&xslcr_mio_class);
1995 ret = xslcr_create_devices(pdev, &xslcr_mio_class, mio_periph_name,
1996 ARRAY_SIZE(mio_periph_name));
2000 ret = class_register(&xslcr_reset_class);
2004 ret = xslcr_create_devices(pdev, &xslcr_reset_class, reset_periph_name,
2005 ARRAY_SIZE(reset_periph_name));
2009 ret = device_create_file(&pdev->dev, &dev_attr_mio_pin_status);
2011 dev_err(&pdev->dev, "Failed to create sysfs attr\n");
2015 platform_set_drvdata(pdev, slcr);
2020 xslcr_remove_devices(&xslcr_reset_class, reset_periph_name,
2021 ARRAY_SIZE(reset_periph_name));
2023 xslcr_remove_devices(&xslcr_mio_class, mio_periph_name,
2024 ARRAY_SIZE(mio_periph_name));
2029 static struct of_device_id slcr_of_match[] = {
2030 { .compatible = "xlnx,zynq-slcr", },
2031 { /* end of list */ },
2033 MODULE_DEVICE_TABLE(of, slcr_of_match);
2035 /* Driver Structure */
2036 static struct platform_driver xslcr_driver = {
2037 .probe = xslcr_probe,
2039 .name = DRIVER_NAME,
2040 .owner = THIS_MODULE,
2041 .of_match_table = slcr_of_match,
2046 * xslcr_arch_init - Register the SLCR
2048 * Returns 0 on success, otherwise negative error.
2050 static int __init xslcr_arch_init(void)
2052 return platform_driver_register(&xslcr_driver);
2054 module_init(xslcr_arch_init);
2057 * zynq_slcr_cpu_start - Start cpu
2060 void zynq_slcr_cpu_start(int cpu)
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);
2070 * zynq_slcr_cpu_stop - Stop cpu
2073 void zynq_slcr_cpu_stop(int cpu)
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);
2082 * Returns 0 on success, negative errno otherwise.
2084 * Called early during boot from platform code to remap SLCR area.
2086 int __init zynq_slcr_init(void)
2088 struct device_node *np;
2090 np = of_find_compatible_node(NULL, NULL, "xlnx,zynq-slcr");
2092 pr_err("%s: no slcr node found\n", __func__);
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__);
2102 slcr = kzalloc(sizeof(*slcr), GFP_KERNEL);
2104 pr_err("%s: Unable to allocate memory for driver data\n",
2109 slcr->regs = zynq_slcr_base;
2111 /* init periph_status based on the data from MIO control registers */
2112 xslcr_get_mio_status();
2114 /* unlock the SLCR so that registers can be changed */
2115 writel(SLCR_UNLOCK_MAGIC, zynq_slcr_base + SLCR_UNLOCK);
2117 pr_info("%s mapped to %p\n", np->name, zynq_slcr_base);
2119 zynq_clock_init(zynq_slcr_base);