1 /* 2 * Copyright (C) 2015-2016 Wills Wang <wills.wang@live.com> 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <asm/errno.h> 9 #include <asm/io.h> 10 #include <asm/addrspace.h> 11 #include <asm/types.h> 12 #include <mach/ath79.h> 13 #include <mach/ar71xx_regs.h> 14 15 void _machine_restart(void) 16 { 17 void __iomem *base; 18 u32 reg = 0; 19 20 base = map_physmem(AR71XX_RESET_BASE, AR71XX_RESET_SIZE, 21 MAP_NOCACHE); 22 if (soc_is_ar71xx()) 23 reg = AR71XX_RESET_REG_RESET_MODULE; 24 else if (soc_is_ar724x()) 25 reg = AR724X_RESET_REG_RESET_MODULE; 26 else if (soc_is_ar913x()) 27 reg = AR913X_RESET_REG_RESET_MODULE; 28 else if (soc_is_ar933x()) 29 reg = AR933X_RESET_REG_RESET_MODULE; 30 else if (soc_is_ar934x()) 31 reg = AR934X_RESET_REG_RESET_MODULE; 32 else if (soc_is_qca953x()) 33 reg = QCA953X_RESET_REG_RESET_MODULE; 34 else if (soc_is_qca955x()) 35 reg = QCA955X_RESET_REG_RESET_MODULE; 36 else if (soc_is_qca956x()) 37 reg = QCA956X_RESET_REG_RESET_MODULE; 38 else 39 puts("Reset register not defined for this SOC\n"); 40 41 if (reg) 42 setbits_be32(base + reg, AR71XX_RESET_FULL_CHIP); 43 44 while (1) 45 /* NOP */; 46 } 47 48 u32 get_bootstrap(void) 49 { 50 void __iomem *base; 51 u32 reg = 0; 52 53 base = map_physmem(AR71XX_RESET_BASE, AR71XX_RESET_SIZE, 54 MAP_NOCACHE); 55 if (soc_is_ar933x()) 56 reg = AR933X_RESET_REG_BOOTSTRAP; 57 else if (soc_is_ar934x()) 58 reg = AR934X_RESET_REG_BOOTSTRAP; 59 else if (soc_is_qca953x()) 60 reg = QCA953X_RESET_REG_BOOTSTRAP; 61 else if (soc_is_qca955x()) 62 reg = QCA955X_RESET_REG_BOOTSTRAP; 63 else if (soc_is_qca956x()) 64 reg = QCA956X_RESET_REG_BOOTSTRAP; 65 else 66 puts("Bootstrap register not defined for this SOC\n"); 67 68 if (reg) 69 return readl(base + reg); 70 71 return 0; 72 } 73 74 static int eth_init_ar933x(void) 75 { 76 void __iomem *rregs = map_physmem(AR71XX_RESET_BASE, AR71XX_RESET_SIZE, 77 MAP_NOCACHE); 78 void __iomem *pregs = map_physmem(AR71XX_PLL_BASE, AR71XX_PLL_SIZE, 79 MAP_NOCACHE); 80 void __iomem *gregs = map_physmem(AR933X_GMAC_BASE, AR933X_GMAC_SIZE, 81 MAP_NOCACHE); 82 const u32 mask = AR933X_RESET_GE0_MAC | AR933X_RESET_GE0_MDIO | 83 AR933X_RESET_GE1_MAC | AR933X_RESET_GE1_MDIO | 84 AR933X_RESET_ETH_SWITCH | 85 AR933X_RESET_ETH_SWITCH_ANALOG; 86 87 /* Clear MDIO slave EN bit. */ 88 clrbits_be32(rregs + AR933X_RESET_REG_BOOTSTRAP, BIT(17)); 89 mdelay(10); 90 91 /* Get Atheros S26 PHY out of reset. */ 92 clrsetbits_be32(pregs + AR934X_PLL_SWITCH_CLOCK_CONTROL_REG, 93 0x1f, 0x10); 94 mdelay(10); 95 96 setbits_be32(rregs + AR933X_RESET_REG_RESET_MODULE, mask); 97 mdelay(10); 98 clrbits_be32(rregs + AR933X_RESET_REG_RESET_MODULE, mask); 99 mdelay(10); 100 101 /* Configure AR93xx GMAC register. */ 102 clrsetbits_be32(gregs + AR933X_GMAC_REG_ETH_CFG, 103 AR933X_ETH_CFG_MII_GE0_MASTER | 104 AR933X_ETH_CFG_MII_GE0_SLAVE, 105 AR933X_ETH_CFG_MII_GE0_SLAVE); 106 return 0; 107 } 108 109 static int eth_init_ar934x(void) 110 { 111 void __iomem *rregs = map_physmem(AR71XX_RESET_BASE, AR71XX_RESET_SIZE, 112 MAP_NOCACHE); 113 void __iomem *pregs = map_physmem(AR71XX_PLL_BASE, AR71XX_PLL_SIZE, 114 MAP_NOCACHE); 115 void __iomem *gregs = map_physmem(AR934X_GMAC_BASE, AR934X_GMAC_SIZE, 116 MAP_NOCACHE); 117 const u32 mask = AR934X_RESET_GE0_MAC | AR934X_RESET_GE0_MDIO | 118 AR934X_RESET_GE1_MAC | AR934X_RESET_GE1_MDIO | 119 AR934X_RESET_ETH_SWITCH_ANALOG; 120 u32 reg; 121 122 reg = readl(rregs + AR934X_RESET_REG_BOOTSTRAP); 123 if (reg & AR934X_BOOTSTRAP_REF_CLK_40) 124 writel(0x570, pregs + AR934X_PLL_SWITCH_CLOCK_CONTROL_REG); 125 else 126 writel(0x271, pregs + AR934X_PLL_SWITCH_CLOCK_CONTROL_REG); 127 writel(BIT(26) | BIT(25), pregs + AR934X_PLL_ETH_XMII_CONTROL_REG); 128 129 setbits_be32(rregs + AR934X_RESET_REG_RESET_MODULE, mask); 130 mdelay(1); 131 clrbits_be32(rregs + AR934X_RESET_REG_RESET_MODULE, mask); 132 mdelay(1); 133 134 /* Configure AR934x GMAC register. */ 135 writel(AR934X_ETH_CFG_RGMII_GMAC0, gregs + AR934X_GMAC_REG_ETH_CFG); 136 return 0; 137 } 138 139 int ath79_eth_reset(void) 140 { 141 /* 142 * Un-reset ethernet. DM still doesn't have any notion of reset 143 * framework, so we do it by hand here. 144 */ 145 if (soc_is_ar933x()) 146 return eth_init_ar933x(); 147 if (soc_is_ar934x()) 148 return eth_init_ar934x(); 149 150 return -EINVAL; 151 } 152 153 static int usb_reset_ar933x(void __iomem *reset_regs) 154 { 155 /* Ungate the USB block */ 156 setbits_be32(reset_regs + AR933X_RESET_REG_RESET_MODULE, 157 AR933X_RESET_USBSUS_OVERRIDE); 158 mdelay(1); 159 clrbits_be32(reset_regs + AR933X_RESET_REG_RESET_MODULE, 160 AR933X_RESET_USB_HOST); 161 mdelay(1); 162 clrbits_be32(reset_regs + AR933X_RESET_REG_RESET_MODULE, 163 AR933X_RESET_USB_PHY); 164 mdelay(1); 165 166 return 0; 167 } 168 169 static int usb_reset_ar934x(void __iomem *reset_regs) 170 { 171 /* Ungate the USB block */ 172 setbits_be32(reset_regs + AR934X_RESET_REG_RESET_MODULE, 173 AR934X_RESET_USBSUS_OVERRIDE); 174 mdelay(1); 175 clrbits_be32(reset_regs + AR934X_RESET_REG_RESET_MODULE, 176 AR934X_RESET_USB_PHY); 177 mdelay(1); 178 clrbits_be32(reset_regs + AR934X_RESET_REG_RESET_MODULE, 179 AR934X_RESET_USB_PHY_ANALOG); 180 mdelay(1); 181 clrbits_be32(reset_regs + AR934X_RESET_REG_RESET_MODULE, 182 AR934X_RESET_USB_HOST); 183 mdelay(1); 184 185 return 0; 186 } 187 188 int ath79_usb_reset(void) 189 { 190 void __iomem *usbc_regs = map_physmem(AR71XX_USB_CTRL_BASE, 191 AR71XX_USB_CTRL_SIZE, 192 MAP_NOCACHE); 193 void __iomem *reset_regs = map_physmem(AR71XX_RESET_BASE, 194 AR71XX_RESET_SIZE, 195 MAP_NOCACHE); 196 /* 197 * Turn on the Buff and Desc swap bits. 198 * NOTE: This write into an undocumented register in mandatory to 199 * get the USB controller operational in BigEndian mode. 200 */ 201 writel(0xf0000, usbc_regs + AR71XX_USB_CTRL_REG_CONFIG); 202 203 if (soc_is_ar933x()) 204 return usb_reset_ar933x(reset_regs); 205 if (soc_is_ar934x()) 206 return usb_reset_ar934x(reset_regs); 207 208 return -EINVAL; 209 } 210