David Daney | 512254b | 2009-09-16 14:54:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
Steven J. Hill | 7fd57ab | 2017-03-09 08:15:38 -0600 | [diff] [blame^] | 6 | * Copyright (C) 2004-2017 Cavium, Inc. |
David Daney | 512254b | 2009-09-16 14:54:18 -0700 | [diff] [blame] | 7 | * Copyright (C) 2008 Wind River Systems |
| 8 | */ |
| 9 | |
| 10 | #include <linux/init.h> |
Steven J. Hill | 7e78db9 | 2016-07-26 10:26:26 -0500 | [diff] [blame] | 11 | #include <linux/delay.h> |
Aaro Koskinen | 377de399 | 2016-02-24 00:52:06 +0200 | [diff] [blame] | 12 | #include <linux/etherdevice.h> |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 13 | #include <linux/of_platform.h> |
| 14 | #include <linux/of_fdt.h> |
| 15 | #include <linux/libfdt.h> |
David Daney | 512254b | 2009-09-16 14:54:18 -0700 | [diff] [blame] | 16 | |
| 17 | #include <asm/octeon/octeon.h> |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 18 | #include <asm/octeon/cvmx-helper-board.h> |
Steven J. Hill | 7fd57ab | 2017-03-09 08:15:38 -0600 | [diff] [blame^] | 19 | |
| 20 | #ifdef CONFIG_USB |
| 21 | #include <linux/usb/ehci_def.h> |
| 22 | #include <linux/usb/ehci_pdriver.h> |
| 23 | #include <linux/usb/ohci_pdriver.h> |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 24 | #include <asm/octeon/cvmx-uctlx-defs.h> |
David Daney | 512254b | 2009-09-16 14:54:18 -0700 | [diff] [blame] | 25 | |
Steven J. Hill | 7e78db9 | 2016-07-26 10:26:26 -0500 | [diff] [blame] | 26 | #define CVMX_UAHCX_EHCI_USBCMD (CVMX_ADD_IO_SEG(0x00016F0000000010ull)) |
| 27 | #define CVMX_UAHCX_OHCI_USBCMD (CVMX_ADD_IO_SEG(0x00016F0000000408ull)) |
| 28 | |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 29 | static DEFINE_MUTEX(octeon2_usb_clocks_mutex); |
| 30 | |
| 31 | static int octeon2_usb_clock_start_cnt; |
| 32 | |
Steven J. Hill | 7e78db9 | 2016-07-26 10:26:26 -0500 | [diff] [blame] | 33 | static int __init octeon2_usb_reset(void) |
| 34 | { |
| 35 | union cvmx_uctlx_clk_rst_ctl clk_rst_ctl; |
| 36 | u32 ucmd; |
| 37 | |
| 38 | if (!OCTEON_IS_OCTEON2()) |
| 39 | return 0; |
| 40 | |
| 41 | clk_rst_ctl.u64 = cvmx_read_csr(CVMX_UCTLX_CLK_RST_CTL(0)); |
| 42 | if (clk_rst_ctl.s.hrst) { |
| 43 | ucmd = cvmx_read64_uint32(CVMX_UAHCX_EHCI_USBCMD); |
| 44 | ucmd &= ~CMD_RUN; |
| 45 | cvmx_write64_uint32(CVMX_UAHCX_EHCI_USBCMD, ucmd); |
| 46 | mdelay(2); |
| 47 | ucmd |= CMD_RESET; |
| 48 | cvmx_write64_uint32(CVMX_UAHCX_EHCI_USBCMD, ucmd); |
| 49 | ucmd = cvmx_read64_uint32(CVMX_UAHCX_OHCI_USBCMD); |
| 50 | ucmd |= CMD_RUN; |
| 51 | cvmx_write64_uint32(CVMX_UAHCX_OHCI_USBCMD, ucmd); |
| 52 | } |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | arch_initcall(octeon2_usb_reset); |
| 57 | |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 58 | static void octeon2_usb_clocks_start(struct device *dev) |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 59 | { |
| 60 | u64 div; |
| 61 | union cvmx_uctlx_if_ena if_ena; |
| 62 | union cvmx_uctlx_clk_rst_ctl clk_rst_ctl; |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 63 | union cvmx_uctlx_uphy_portx_ctl_status port_ctl_status; |
| 64 | int i; |
| 65 | unsigned long io_clk_64_to_ns; |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 66 | u32 clock_rate = 12000000; |
| 67 | bool is_crystal_clock = false; |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 68 | |
| 69 | |
| 70 | mutex_lock(&octeon2_usb_clocks_mutex); |
| 71 | |
| 72 | octeon2_usb_clock_start_cnt++; |
| 73 | if (octeon2_usb_clock_start_cnt != 1) |
| 74 | goto exit; |
| 75 | |
| 76 | io_clk_64_to_ns = 64000000000ull / octeon_get_io_clock_rate(); |
| 77 | |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 78 | if (dev->of_node) { |
| 79 | struct device_node *uctl_node; |
| 80 | const char *clock_type; |
| 81 | |
| 82 | uctl_node = of_get_parent(dev->of_node); |
| 83 | if (!uctl_node) { |
| 84 | dev_err(dev, "No UCTL device node\n"); |
| 85 | goto exit; |
| 86 | } |
| 87 | i = of_property_read_u32(uctl_node, |
| 88 | "refclk-frequency", &clock_rate); |
| 89 | if (i) { |
| 90 | dev_err(dev, "No UCTL \"refclk-frequency\"\n"); |
| 91 | goto exit; |
| 92 | } |
| 93 | i = of_property_read_string(uctl_node, |
| 94 | "refclk-type", &clock_type); |
| 95 | |
| 96 | if (!i && strcmp("crystal", clock_type) == 0) |
| 97 | is_crystal_clock = true; |
| 98 | } |
| 99 | |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 100 | /* |
| 101 | * Step 1: Wait for voltages stable. That surely happened |
| 102 | * before starting the kernel. |
| 103 | * |
| 104 | * Step 2: Enable SCLK of UCTL by writing UCTL0_IF_ENA[EN] = 1 |
| 105 | */ |
| 106 | if_ena.u64 = 0; |
| 107 | if_ena.s.en = 1; |
| 108 | cvmx_write_csr(CVMX_UCTLX_IF_ENA(0), if_ena.u64); |
| 109 | |
Steven J. Hill | 7e78db9 | 2016-07-26 10:26:26 -0500 | [diff] [blame] | 110 | for (i = 0; i <= 1; i++) { |
| 111 | port_ctl_status.u64 = |
| 112 | cvmx_read_csr(CVMX_UCTLX_UPHY_PORTX_CTL_STATUS(i, 0)); |
| 113 | /* Set txvreftune to 15 to obtain compliant 'eye' diagram. */ |
| 114 | port_ctl_status.s.txvreftune = 15; |
| 115 | port_ctl_status.s.txrisetune = 1; |
| 116 | port_ctl_status.s.txpreemphasistune = 1; |
| 117 | cvmx_write_csr(CVMX_UCTLX_UPHY_PORTX_CTL_STATUS(i, 0), |
| 118 | port_ctl_status.u64); |
| 119 | } |
| 120 | |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 121 | /* Step 3: Configure the reference clock, PHY, and HCLK */ |
| 122 | clk_rst_ctl.u64 = cvmx_read_csr(CVMX_UCTLX_CLK_RST_CTL(0)); |
| 123 | |
| 124 | /* |
| 125 | * If the UCTL looks like it has already been started, skip |
| 126 | * the initialization, otherwise bus errors are obtained. |
| 127 | */ |
| 128 | if (clk_rst_ctl.s.hrst) |
| 129 | goto end_clock; |
| 130 | /* 3a */ |
| 131 | clk_rst_ctl.s.p_por = 1; |
| 132 | clk_rst_ctl.s.hrst = 0; |
| 133 | clk_rst_ctl.s.p_prst = 0; |
| 134 | clk_rst_ctl.s.h_clkdiv_rst = 0; |
| 135 | clk_rst_ctl.s.o_clkdiv_rst = 0; |
| 136 | clk_rst_ctl.s.h_clkdiv_en = 0; |
| 137 | clk_rst_ctl.s.o_clkdiv_en = 0; |
| 138 | cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64); |
| 139 | |
| 140 | /* 3b */ |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 141 | clk_rst_ctl.s.p_refclk_sel = is_crystal_clock ? 0 : 1; |
| 142 | switch (clock_rate) { |
| 143 | default: |
| 144 | pr_err("Invalid UCTL clock rate of %u, using 12000000 instead\n", |
| 145 | clock_rate); |
| 146 | /* Fall through */ |
| 147 | case 12000000: |
| 148 | clk_rst_ctl.s.p_refclk_div = 0; |
| 149 | break; |
| 150 | case 24000000: |
| 151 | clk_rst_ctl.s.p_refclk_div = 1; |
| 152 | break; |
| 153 | case 48000000: |
| 154 | clk_rst_ctl.s.p_refclk_div = 2; |
| 155 | break; |
| 156 | } |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 157 | cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64); |
| 158 | |
| 159 | /* 3c */ |
| 160 | div = octeon_get_io_clock_rate() / 130000000ull; |
| 161 | |
| 162 | switch (div) { |
| 163 | case 0: |
| 164 | div = 1; |
| 165 | break; |
| 166 | case 1: |
| 167 | case 2: |
| 168 | case 3: |
| 169 | case 4: |
| 170 | break; |
| 171 | case 5: |
| 172 | div = 4; |
| 173 | break; |
| 174 | case 6: |
| 175 | case 7: |
| 176 | div = 6; |
| 177 | break; |
| 178 | case 8: |
| 179 | case 9: |
| 180 | case 10: |
| 181 | case 11: |
| 182 | div = 8; |
| 183 | break; |
| 184 | default: |
| 185 | div = 12; |
| 186 | break; |
| 187 | } |
| 188 | clk_rst_ctl.s.h_div = div; |
| 189 | cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64); |
| 190 | /* Read it back, */ |
| 191 | clk_rst_ctl.u64 = cvmx_read_csr(CVMX_UCTLX_CLK_RST_CTL(0)); |
| 192 | clk_rst_ctl.s.h_clkdiv_en = 1; |
| 193 | cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64); |
| 194 | /* 3d */ |
| 195 | clk_rst_ctl.s.h_clkdiv_rst = 1; |
| 196 | cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64); |
| 197 | |
| 198 | /* 3e: delay 64 io clocks */ |
| 199 | ndelay(io_clk_64_to_ns); |
| 200 | |
| 201 | /* |
| 202 | * Step 4: Program the power-on reset field in the UCTL |
| 203 | * clock-reset-control register. |
| 204 | */ |
| 205 | clk_rst_ctl.s.p_por = 0; |
| 206 | cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64); |
| 207 | |
Steven J. Hill | 7e78db9 | 2016-07-26 10:26:26 -0500 | [diff] [blame] | 208 | /* Step 5: Wait 3 ms for the PHY clock to start. */ |
| 209 | mdelay(3); |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 210 | |
Steven J. Hill | 7e78db9 | 2016-07-26 10:26:26 -0500 | [diff] [blame] | 211 | /* Steps 6..9 for ATE only, are skipped. */ |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 212 | |
| 213 | /* Step 10: Configure the OHCI_CLK48 and OHCI_CLK12 clocks. */ |
| 214 | /* 10a */ |
| 215 | clk_rst_ctl.s.o_clkdiv_rst = 1; |
| 216 | cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64); |
| 217 | |
| 218 | /* 10b */ |
| 219 | clk_rst_ctl.s.o_clkdiv_en = 1; |
| 220 | cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64); |
| 221 | |
| 222 | /* 10c */ |
| 223 | ndelay(io_clk_64_to_ns); |
| 224 | |
| 225 | /* |
| 226 | * Step 11: Program the PHY reset field: |
| 227 | * UCTL0_CLK_RST_CTL[P_PRST] = 1 |
| 228 | */ |
| 229 | clk_rst_ctl.s.p_prst = 1; |
| 230 | cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64); |
| 231 | |
Steven J. Hill | 7e78db9 | 2016-07-26 10:26:26 -0500 | [diff] [blame] | 232 | /* Step 11b */ |
| 233 | udelay(1); |
| 234 | |
| 235 | /* Step 11c */ |
| 236 | clk_rst_ctl.s.p_prst = 0; |
| 237 | cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64); |
| 238 | |
| 239 | /* Step 11d */ |
| 240 | mdelay(1); |
| 241 | |
| 242 | /* Step 11e */ |
| 243 | clk_rst_ctl.s.p_prst = 1; |
| 244 | cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64); |
| 245 | |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 246 | /* Step 12: Wait 1 uS. */ |
| 247 | udelay(1); |
| 248 | |
| 249 | /* Step 13: Program the HRESET_N field: UCTL0_CLK_RST_CTL[HRST] = 1 */ |
| 250 | clk_rst_ctl.s.hrst = 1; |
| 251 | cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64); |
| 252 | |
| 253 | end_clock: |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 254 | /* Set uSOF cycle period to 60,000 bits. */ |
| 255 | cvmx_write_csr(CVMX_UCTLX_EHCI_FLA(0), 0x20ull); |
Steven J. Hill | 7e78db9 | 2016-07-26 10:26:26 -0500 | [diff] [blame] | 256 | |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 257 | exit: |
| 258 | mutex_unlock(&octeon2_usb_clocks_mutex); |
| 259 | } |
| 260 | |
| 261 | static void octeon2_usb_clocks_stop(void) |
| 262 | { |
| 263 | mutex_lock(&octeon2_usb_clocks_mutex); |
| 264 | octeon2_usb_clock_start_cnt--; |
| 265 | mutex_unlock(&octeon2_usb_clocks_mutex); |
| 266 | } |
| 267 | |
| 268 | static int octeon_ehci_power_on(struct platform_device *pdev) |
| 269 | { |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 270 | octeon2_usb_clocks_start(&pdev->dev); |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 271 | return 0; |
| 272 | } |
| 273 | |
| 274 | static void octeon_ehci_power_off(struct platform_device *pdev) |
| 275 | { |
| 276 | octeon2_usb_clocks_stop(); |
| 277 | } |
| 278 | |
| 279 | static struct usb_ehci_pdata octeon_ehci_pdata = { |
| 280 | /* Octeon EHCI matches CPU endianness. */ |
| 281 | #ifdef __BIG_ENDIAN |
| 282 | .big_endian_mmio = 1, |
| 283 | #endif |
Steven J. Hill | 8552b5b | 2016-07-26 10:26:23 -0500 | [diff] [blame] | 284 | /* |
| 285 | * We can DMA from anywhere. But the descriptors must be in |
| 286 | * the lower 4GB. |
| 287 | */ |
| 288 | .dma_mask_64 = 0, |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 289 | .power_on = octeon_ehci_power_on, |
| 290 | .power_off = octeon_ehci_power_off, |
| 291 | }; |
| 292 | |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 293 | static void __init octeon_ehci_hw_start(struct device *dev) |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 294 | { |
| 295 | union cvmx_uctlx_ehci_ctl ehci_ctl; |
| 296 | |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 297 | octeon2_usb_clocks_start(dev); |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 298 | |
| 299 | ehci_ctl.u64 = cvmx_read_csr(CVMX_UCTLX_EHCI_CTL(0)); |
| 300 | /* Use 64-bit addressing. */ |
| 301 | ehci_ctl.s.ehci_64b_addr_en = 1; |
| 302 | ehci_ctl.s.l2c_addr_msb = 0; |
Paul Martin | b0abf36 | 2015-03-30 17:00:57 +0100 | [diff] [blame] | 303 | #ifdef __BIG_ENDIAN |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 304 | ehci_ctl.s.l2c_buff_emod = 1; /* Byte swapped. */ |
| 305 | ehci_ctl.s.l2c_desc_emod = 1; /* Byte swapped. */ |
Paul Martin | b0abf36 | 2015-03-30 17:00:57 +0100 | [diff] [blame] | 306 | #else |
| 307 | ehci_ctl.s.l2c_buff_emod = 0; /* not swapped. */ |
| 308 | ehci_ctl.s.l2c_desc_emod = 0; /* not swapped. */ |
| 309 | ehci_ctl.s.inv_reg_a2 = 1; |
| 310 | #endif |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 311 | cvmx_write_csr(CVMX_UCTLX_EHCI_CTL(0), ehci_ctl.u64); |
| 312 | |
| 313 | octeon2_usb_clocks_stop(); |
| 314 | } |
| 315 | |
David Daney | 340fbb8 | 2010-10-08 14:47:53 -0700 | [diff] [blame] | 316 | static int __init octeon_ehci_device_init(void) |
| 317 | { |
| 318 | struct platform_device *pd; |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 319 | struct device_node *ehci_node; |
David Daney | 340fbb8 | 2010-10-08 14:47:53 -0700 | [diff] [blame] | 320 | int ret = 0; |
| 321 | |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 322 | ehci_node = of_find_node_by_name(NULL, "ehci"); |
| 323 | if (!ehci_node) |
David Daney | 340fbb8 | 2010-10-08 14:47:53 -0700 | [diff] [blame] | 324 | return 0; |
| 325 | |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 326 | pd = of_find_device_by_node(ehci_node); |
| 327 | if (!pd) |
| 328 | return 0; |
David Daney | 340fbb8 | 2010-10-08 14:47:53 -0700 | [diff] [blame] | 329 | |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 330 | pd->dev.platform_data = &octeon_ehci_pdata; |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 331 | octeon_ehci_hw_start(&pd->dev); |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 332 | |
David Daney | 340fbb8 | 2010-10-08 14:47:53 -0700 | [diff] [blame] | 333 | return ret; |
| 334 | } |
| 335 | device_initcall(octeon_ehci_device_init); |
| 336 | |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 337 | static int octeon_ohci_power_on(struct platform_device *pdev) |
| 338 | { |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 339 | octeon2_usb_clocks_start(&pdev->dev); |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | static void octeon_ohci_power_off(struct platform_device *pdev) |
| 344 | { |
| 345 | octeon2_usb_clocks_stop(); |
| 346 | } |
| 347 | |
| 348 | static struct usb_ohci_pdata octeon_ohci_pdata = { |
| 349 | /* Octeon OHCI matches CPU endianness. */ |
| 350 | #ifdef __BIG_ENDIAN |
| 351 | .big_endian_mmio = 1, |
| 352 | #endif |
| 353 | .power_on = octeon_ohci_power_on, |
| 354 | .power_off = octeon_ohci_power_off, |
| 355 | }; |
| 356 | |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 357 | static void __init octeon_ohci_hw_start(struct device *dev) |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 358 | { |
| 359 | union cvmx_uctlx_ohci_ctl ohci_ctl; |
| 360 | |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 361 | octeon2_usb_clocks_start(dev); |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 362 | |
| 363 | ohci_ctl.u64 = cvmx_read_csr(CVMX_UCTLX_OHCI_CTL(0)); |
| 364 | ohci_ctl.s.l2c_addr_msb = 0; |
Paul Martin | b0abf36 | 2015-03-30 17:00:57 +0100 | [diff] [blame] | 365 | #ifdef __BIG_ENDIAN |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 366 | ohci_ctl.s.l2c_buff_emod = 1; /* Byte swapped. */ |
| 367 | ohci_ctl.s.l2c_desc_emod = 1; /* Byte swapped. */ |
Paul Martin | b0abf36 | 2015-03-30 17:00:57 +0100 | [diff] [blame] | 368 | #else |
| 369 | ohci_ctl.s.l2c_buff_emod = 0; /* not swapped. */ |
| 370 | ohci_ctl.s.l2c_desc_emod = 0; /* not swapped. */ |
| 371 | ohci_ctl.s.inv_reg_a2 = 1; |
| 372 | #endif |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 373 | cvmx_write_csr(CVMX_UCTLX_OHCI_CTL(0), ohci_ctl.u64); |
| 374 | |
| 375 | octeon2_usb_clocks_stop(); |
| 376 | } |
| 377 | |
David Daney | 340fbb8 | 2010-10-08 14:47:53 -0700 | [diff] [blame] | 378 | static int __init octeon_ohci_device_init(void) |
| 379 | { |
| 380 | struct platform_device *pd; |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 381 | struct device_node *ohci_node; |
David Daney | 340fbb8 | 2010-10-08 14:47:53 -0700 | [diff] [blame] | 382 | int ret = 0; |
| 383 | |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 384 | ohci_node = of_find_node_by_name(NULL, "ohci"); |
| 385 | if (!ohci_node) |
David Daney | 340fbb8 | 2010-10-08 14:47:53 -0700 | [diff] [blame] | 386 | return 0; |
| 387 | |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 388 | pd = of_find_device_by_node(ohci_node); |
| 389 | if (!pd) |
| 390 | return 0; |
David Daney | 340fbb8 | 2010-10-08 14:47:53 -0700 | [diff] [blame] | 391 | |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 392 | pd->dev.platform_data = &octeon_ohci_pdata; |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 393 | octeon_ohci_hw_start(&pd->dev); |
Alan Stern | 2193dda | 2014-11-25 12:28:46 +0100 | [diff] [blame] | 394 | |
David Daney | 340fbb8 | 2010-10-08 14:47:53 -0700 | [diff] [blame] | 395 | return ret; |
| 396 | } |
| 397 | device_initcall(octeon_ohci_device_init); |
| 398 | |
| 399 | #endif /* CONFIG_USB */ |
| 400 | |
Steven J. Hill | 7fd57ab | 2017-03-09 08:15:38 -0600 | [diff] [blame^] | 401 | /* Octeon Random Number Generator. */ |
| 402 | static int __init octeon_rng_device_init(void) |
| 403 | { |
| 404 | struct platform_device *pd; |
| 405 | int ret = 0; |
| 406 | |
| 407 | struct resource rng_resources[] = { |
| 408 | { |
| 409 | .flags = IORESOURCE_MEM, |
| 410 | .start = XKPHYS_TO_PHYS(CVMX_RNM_CTL_STATUS), |
| 411 | .end = XKPHYS_TO_PHYS(CVMX_RNM_CTL_STATUS) + 0xf |
| 412 | }, { |
| 413 | .flags = IORESOURCE_MEM, |
| 414 | .start = cvmx_build_io_address(8, 0), |
| 415 | .end = cvmx_build_io_address(8, 0) + 0x7 |
| 416 | } |
| 417 | }; |
| 418 | |
| 419 | pd = platform_device_alloc("octeon_rng", -1); |
| 420 | if (!pd) { |
| 421 | ret = -ENOMEM; |
| 422 | goto out; |
| 423 | } |
| 424 | |
| 425 | ret = platform_device_add_resources(pd, rng_resources, |
| 426 | ARRAY_SIZE(rng_resources)); |
| 427 | if (ret) |
| 428 | goto fail; |
| 429 | |
| 430 | ret = platform_device_add(pd); |
| 431 | if (ret) |
| 432 | goto fail; |
| 433 | |
| 434 | return ret; |
| 435 | fail: |
| 436 | platform_device_put(pd); |
| 437 | |
| 438 | out: |
| 439 | return ret; |
| 440 | } |
| 441 | device_initcall(octeon_rng_device_init); |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 442 | |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 443 | static struct of_device_id __initdata octeon_ids[] = { |
| 444 | { .compatible = "simple-bus", }, |
| 445 | { .compatible = "cavium,octeon-6335-uctl", }, |
David Daney | d617f9e | 2013-12-03 11:46:51 -0800 | [diff] [blame] | 446 | { .compatible = "cavium,octeon-5750-usbn", }, |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 447 | { .compatible = "cavium,octeon-3860-bootbus", }, |
| 448 | { .compatible = "cavium,mdio-mux", }, |
| 449 | { .compatible = "gpio-leds", }, |
Steven J. Hill | 93e502b | 2017-01-25 01:02:28 -0600 | [diff] [blame] | 450 | { .compatible = "cavium,octeon-7130-usb-uctl", }, |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 451 | {}, |
| 452 | }; |
| 453 | |
| 454 | static bool __init octeon_has_88e1145(void) |
| 455 | { |
| 456 | return !OCTEON_IS_MODEL(OCTEON_CN52XX) && |
| 457 | !OCTEON_IS_MODEL(OCTEON_CN6XXX) && |
| 458 | !OCTEON_IS_MODEL(OCTEON_CN56XX); |
| 459 | } |
| 460 | |
| 461 | static void __init octeon_fdt_set_phy(int eth, int phy_addr) |
| 462 | { |
| 463 | const __be32 *phy_handle; |
| 464 | const __be32 *alt_phy_handle; |
| 465 | const __be32 *reg; |
| 466 | u32 phandle; |
| 467 | int phy; |
| 468 | int alt_phy; |
| 469 | const char *p; |
| 470 | int current_len; |
| 471 | char new_name[20]; |
| 472 | |
| 473 | phy_handle = fdt_getprop(initial_boot_params, eth, "phy-handle", NULL); |
| 474 | if (!phy_handle) |
| 475 | return; |
| 476 | |
| 477 | phandle = be32_to_cpup(phy_handle); |
| 478 | phy = fdt_node_offset_by_phandle(initial_boot_params, phandle); |
| 479 | |
| 480 | alt_phy_handle = fdt_getprop(initial_boot_params, eth, "cavium,alt-phy-handle", NULL); |
| 481 | if (alt_phy_handle) { |
| 482 | u32 alt_phandle = be32_to_cpup(alt_phy_handle); |
| 483 | alt_phy = fdt_node_offset_by_phandle(initial_boot_params, alt_phandle); |
| 484 | } else { |
| 485 | alt_phy = -1; |
| 486 | } |
| 487 | |
| 488 | if (phy_addr < 0 || phy < 0) { |
| 489 | /* Delete the PHY things */ |
| 490 | fdt_nop_property(initial_boot_params, eth, "phy-handle"); |
| 491 | /* This one may fail */ |
| 492 | fdt_nop_property(initial_boot_params, eth, "cavium,alt-phy-handle"); |
| 493 | if (phy >= 0) |
| 494 | fdt_nop_node(initial_boot_params, phy); |
| 495 | if (alt_phy >= 0) |
| 496 | fdt_nop_node(initial_boot_params, alt_phy); |
| 497 | return; |
| 498 | } |
| 499 | |
| 500 | if (phy_addr >= 256 && alt_phy > 0) { |
| 501 | const struct fdt_property *phy_prop; |
| 502 | struct fdt_property *alt_prop; |
| 503 | u32 phy_handle_name; |
| 504 | |
| 505 | /* Use the alt phy node instead.*/ |
| 506 | phy_prop = fdt_get_property(initial_boot_params, eth, "phy-handle", NULL); |
| 507 | phy_handle_name = phy_prop->nameoff; |
| 508 | fdt_nop_node(initial_boot_params, phy); |
| 509 | fdt_nop_property(initial_boot_params, eth, "phy-handle"); |
| 510 | alt_prop = fdt_get_property_w(initial_boot_params, eth, "cavium,alt-phy-handle", NULL); |
| 511 | alt_prop->nameoff = phy_handle_name; |
| 512 | phy = alt_phy; |
| 513 | } |
| 514 | |
| 515 | phy_addr &= 0xff; |
| 516 | |
| 517 | if (octeon_has_88e1145()) { |
| 518 | fdt_nop_property(initial_boot_params, phy, "marvell,reg-init"); |
| 519 | memset(new_name, 0, sizeof(new_name)); |
| 520 | strcpy(new_name, "marvell,88e1145"); |
| 521 | p = fdt_getprop(initial_boot_params, phy, "compatible", |
| 522 | ¤t_len); |
| 523 | if (p && current_len >= strlen(new_name)) |
| 524 | fdt_setprop_inplace(initial_boot_params, phy, |
| 525 | "compatible", new_name, current_len); |
| 526 | } |
| 527 | |
| 528 | reg = fdt_getprop(initial_boot_params, phy, "reg", NULL); |
| 529 | if (phy_addr == be32_to_cpup(reg)) |
| 530 | return; |
| 531 | |
| 532 | fdt_setprop_inplace_cell(initial_boot_params, phy, "reg", phy_addr); |
| 533 | |
| 534 | snprintf(new_name, sizeof(new_name), "ethernet-phy@%x", phy_addr); |
| 535 | |
| 536 | p = fdt_get_name(initial_boot_params, phy, ¤t_len); |
| 537 | if (p && current_len == strlen(new_name)) |
| 538 | fdt_set_name(initial_boot_params, phy, new_name); |
| 539 | else |
| 540 | pr_err("Error: could not rename ethernet phy: <%s>", p); |
| 541 | } |
| 542 | |
| 543 | static void __init octeon_fdt_set_mac_addr(int n, u64 *pmac) |
| 544 | { |
Aaro Koskinen | 377de399 | 2016-02-24 00:52:06 +0200 | [diff] [blame] | 545 | const u8 *old_mac; |
| 546 | int old_len; |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 547 | u8 new_mac[6]; |
| 548 | u64 mac = *pmac; |
| 549 | int r; |
| 550 | |
Aaro Koskinen | 377de399 | 2016-02-24 00:52:06 +0200 | [diff] [blame] | 551 | old_mac = fdt_getprop(initial_boot_params, n, "local-mac-address", |
| 552 | &old_len); |
| 553 | if (!old_mac || old_len != 6 || is_valid_ether_addr(old_mac)) |
| 554 | return; |
| 555 | |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 556 | new_mac[0] = (mac >> 40) & 0xff; |
| 557 | new_mac[1] = (mac >> 32) & 0xff; |
| 558 | new_mac[2] = (mac >> 24) & 0xff; |
| 559 | new_mac[3] = (mac >> 16) & 0xff; |
| 560 | new_mac[4] = (mac >> 8) & 0xff; |
| 561 | new_mac[5] = mac & 0xff; |
| 562 | |
| 563 | r = fdt_setprop_inplace(initial_boot_params, n, "local-mac-address", |
| 564 | new_mac, sizeof(new_mac)); |
| 565 | |
| 566 | if (r) { |
| 567 | pr_err("Setting \"local-mac-address\" failed %d", r); |
| 568 | return; |
| 569 | } |
| 570 | *pmac = mac + 1; |
| 571 | } |
| 572 | |
| 573 | static void __init octeon_fdt_rm_ethernet(int node) |
| 574 | { |
| 575 | const __be32 *phy_handle; |
| 576 | |
| 577 | phy_handle = fdt_getprop(initial_boot_params, node, "phy-handle", NULL); |
| 578 | if (phy_handle) { |
| 579 | u32 ph = be32_to_cpup(phy_handle); |
| 580 | int p = fdt_node_offset_by_phandle(initial_boot_params, ph); |
| 581 | if (p >= 0) |
| 582 | fdt_nop_node(initial_boot_params, p); |
| 583 | } |
| 584 | fdt_nop_node(initial_boot_params, node); |
| 585 | } |
| 586 | |
Aaro Koskinen | 43349b9 | 2016-02-24 00:52:05 +0200 | [diff] [blame] | 587 | static void __init octeon_fdt_pip_port(int iface, int i, int p, int max) |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 588 | { |
| 589 | char name_buffer[20]; |
| 590 | int eth; |
| 591 | int phy_addr; |
| 592 | int ipd_port; |
| 593 | |
| 594 | snprintf(name_buffer, sizeof(name_buffer), "ethernet@%x", p); |
| 595 | eth = fdt_subnode_offset(initial_boot_params, iface, name_buffer); |
| 596 | if (eth < 0) |
| 597 | return; |
| 598 | if (p > max) { |
| 599 | pr_debug("Deleting port %x:%x\n", i, p); |
| 600 | octeon_fdt_rm_ethernet(eth); |
| 601 | return; |
| 602 | } |
| 603 | if (OCTEON_IS_MODEL(OCTEON_CN68XX)) |
| 604 | ipd_port = (0x100 * i) + (0x10 * p) + 0x800; |
| 605 | else |
| 606 | ipd_port = 16 * i + p; |
| 607 | |
| 608 | phy_addr = cvmx_helper_board_get_mii_address(ipd_port); |
| 609 | octeon_fdt_set_phy(eth, phy_addr); |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 610 | } |
| 611 | |
Aaro Koskinen | 43349b9 | 2016-02-24 00:52:05 +0200 | [diff] [blame] | 612 | static void __init octeon_fdt_pip_iface(int pip, int idx) |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 613 | { |
| 614 | char name_buffer[20]; |
| 615 | int iface; |
| 616 | int p; |
Faidon Liambotis | ab2bb14 | 2013-07-11 21:08:09 +0000 | [diff] [blame] | 617 | int count = 0; |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 618 | |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 619 | snprintf(name_buffer, sizeof(name_buffer), "interface@%d", idx); |
| 620 | iface = fdt_subnode_offset(initial_boot_params, pip, name_buffer); |
| 621 | if (iface < 0) |
| 622 | return; |
| 623 | |
Aaro Koskinen | b2e4f15 | 2013-11-01 17:06:04 +0200 | [diff] [blame] | 624 | if (cvmx_helper_interface_enumerate(idx) == 0) |
| 625 | count = cvmx_helper_ports_on_interface(idx); |
| 626 | |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 627 | for (p = 0; p < 16; p++) |
Aaro Koskinen | 43349b9 | 2016-02-24 00:52:05 +0200 | [diff] [blame] | 628 | octeon_fdt_pip_port(iface, idx, p, count - 1); |
| 629 | } |
| 630 | |
| 631 | void __init octeon_fill_mac_addresses(void) |
| 632 | { |
| 633 | const char *alias_prop; |
| 634 | char name_buffer[20]; |
| 635 | u64 mac_addr_base; |
| 636 | int aliases; |
| 637 | int pip; |
| 638 | int i; |
| 639 | |
| 640 | aliases = fdt_path_offset(initial_boot_params, "/aliases"); |
| 641 | if (aliases < 0) |
| 642 | return; |
| 643 | |
| 644 | mac_addr_base = |
| 645 | ((octeon_bootinfo->mac_addr_base[0] & 0xffull)) << 40 | |
| 646 | ((octeon_bootinfo->mac_addr_base[1] & 0xffull)) << 32 | |
| 647 | ((octeon_bootinfo->mac_addr_base[2] & 0xffull)) << 24 | |
| 648 | ((octeon_bootinfo->mac_addr_base[3] & 0xffull)) << 16 | |
| 649 | ((octeon_bootinfo->mac_addr_base[4] & 0xffull)) << 8 | |
| 650 | (octeon_bootinfo->mac_addr_base[5] & 0xffull); |
| 651 | |
| 652 | for (i = 0; i < 2; i++) { |
| 653 | int mgmt; |
| 654 | |
| 655 | snprintf(name_buffer, sizeof(name_buffer), "mix%d", i); |
| 656 | alias_prop = fdt_getprop(initial_boot_params, aliases, |
| 657 | name_buffer, NULL); |
| 658 | if (!alias_prop) |
| 659 | continue; |
| 660 | mgmt = fdt_path_offset(initial_boot_params, alias_prop); |
| 661 | if (mgmt < 0) |
| 662 | continue; |
| 663 | octeon_fdt_set_mac_addr(mgmt, &mac_addr_base); |
| 664 | } |
| 665 | |
| 666 | alias_prop = fdt_getprop(initial_boot_params, aliases, "pip", NULL); |
| 667 | if (!alias_prop) |
| 668 | return; |
| 669 | |
| 670 | pip = fdt_path_offset(initial_boot_params, alias_prop); |
| 671 | if (pip < 0) |
| 672 | return; |
| 673 | |
| 674 | for (i = 0; i <= 4; i++) { |
| 675 | int iface; |
| 676 | int p; |
| 677 | |
| 678 | snprintf(name_buffer, sizeof(name_buffer), "interface@%d", i); |
| 679 | iface = fdt_subnode_offset(initial_boot_params, pip, |
| 680 | name_buffer); |
| 681 | if (iface < 0) |
| 682 | continue; |
| 683 | for (p = 0; p < 16; p++) { |
| 684 | int eth; |
| 685 | |
| 686 | snprintf(name_buffer, sizeof(name_buffer), |
| 687 | "ethernet@%x", p); |
| 688 | eth = fdt_subnode_offset(initial_boot_params, iface, |
| 689 | name_buffer); |
| 690 | if (eth < 0) |
| 691 | continue; |
| 692 | octeon_fdt_set_mac_addr(eth, &mac_addr_base); |
| 693 | } |
| 694 | } |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | int __init octeon_prune_device_tree(void) |
| 698 | { |
| 699 | int i, max_port, uart_mask; |
| 700 | const char *pip_path; |
| 701 | const char *alias_prop; |
| 702 | char name_buffer[20]; |
| 703 | int aliases; |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 704 | |
| 705 | if (fdt_check_header(initial_boot_params)) |
| 706 | panic("Corrupt Device Tree."); |
| 707 | |
Aaro Koskinen | 86bee12 | 2016-06-05 00:18:18 +0300 | [diff] [blame] | 708 | WARN(octeon_bootinfo->board_type == CVMX_BOARD_TYPE_CUST_DSR1000N, |
| 709 | "Built-in DTB booting is deprecated on %s. Please switch to use appended DTB.", |
| 710 | cvmx_board_type_to_string(octeon_bootinfo->board_type)); |
| 711 | |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 712 | aliases = fdt_path_offset(initial_boot_params, "/aliases"); |
| 713 | if (aliases < 0) { |
| 714 | pr_err("Error: No /aliases node in device tree."); |
| 715 | return -EINVAL; |
| 716 | } |
| 717 | |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 718 | if (OCTEON_IS_MODEL(OCTEON_CN52XX) || OCTEON_IS_MODEL(OCTEON_CN63XX)) |
| 719 | max_port = 2; |
| 720 | else if (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN68XX)) |
| 721 | max_port = 1; |
| 722 | else |
| 723 | max_port = 0; |
| 724 | |
| 725 | if (octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC10E) |
| 726 | max_port = 0; |
| 727 | |
| 728 | for (i = 0; i < 2; i++) { |
| 729 | int mgmt; |
| 730 | snprintf(name_buffer, sizeof(name_buffer), |
| 731 | "mix%d", i); |
| 732 | alias_prop = fdt_getprop(initial_boot_params, aliases, |
| 733 | name_buffer, NULL); |
| 734 | if (alias_prop) { |
| 735 | mgmt = fdt_path_offset(initial_boot_params, alias_prop); |
| 736 | if (mgmt < 0) |
| 737 | continue; |
| 738 | if (i >= max_port) { |
| 739 | pr_debug("Deleting mix%d\n", i); |
| 740 | octeon_fdt_rm_ethernet(mgmt); |
| 741 | fdt_nop_property(initial_boot_params, aliases, |
| 742 | name_buffer); |
| 743 | } else { |
| 744 | int phy_addr = cvmx_helper_board_get_mii_address(CVMX_HELPER_BOARD_MGMT_IPD_PORT + i); |
| 745 | octeon_fdt_set_phy(mgmt, phy_addr); |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | pip_path = fdt_getprop(initial_boot_params, aliases, "pip", NULL); |
| 751 | if (pip_path) { |
| 752 | int pip = fdt_path_offset(initial_boot_params, pip_path); |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 753 | if (pip >= 0) |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 754 | for (i = 0; i <= 4; i++) |
Aaro Koskinen | 43349b9 | 2016-02-24 00:52:05 +0200 | [diff] [blame] | 755 | octeon_fdt_pip_iface(pip, i); |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | /* I2C */ |
| 759 | if (OCTEON_IS_MODEL(OCTEON_CN52XX) || |
| 760 | OCTEON_IS_MODEL(OCTEON_CN63XX) || |
| 761 | OCTEON_IS_MODEL(OCTEON_CN68XX) || |
| 762 | OCTEON_IS_MODEL(OCTEON_CN56XX)) |
| 763 | max_port = 2; |
| 764 | else |
| 765 | max_port = 1; |
| 766 | |
| 767 | for (i = 0; i < 2; i++) { |
| 768 | int i2c; |
| 769 | snprintf(name_buffer, sizeof(name_buffer), |
| 770 | "twsi%d", i); |
| 771 | alias_prop = fdt_getprop(initial_boot_params, aliases, |
| 772 | name_buffer, NULL); |
| 773 | |
| 774 | if (alias_prop) { |
| 775 | i2c = fdt_path_offset(initial_boot_params, alias_prop); |
| 776 | if (i2c < 0) |
| 777 | continue; |
| 778 | if (i >= max_port) { |
| 779 | pr_debug("Deleting twsi%d\n", i); |
| 780 | fdt_nop_node(initial_boot_params, i2c); |
| 781 | fdt_nop_property(initial_boot_params, aliases, |
| 782 | name_buffer); |
| 783 | } |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | /* SMI/MDIO */ |
| 788 | if (OCTEON_IS_MODEL(OCTEON_CN68XX)) |
| 789 | max_port = 4; |
| 790 | else if (OCTEON_IS_MODEL(OCTEON_CN52XX) || |
| 791 | OCTEON_IS_MODEL(OCTEON_CN63XX) || |
| 792 | OCTEON_IS_MODEL(OCTEON_CN56XX)) |
| 793 | max_port = 2; |
| 794 | else |
| 795 | max_port = 1; |
| 796 | |
| 797 | for (i = 0; i < 2; i++) { |
| 798 | int i2c; |
| 799 | snprintf(name_buffer, sizeof(name_buffer), |
| 800 | "smi%d", i); |
| 801 | alias_prop = fdt_getprop(initial_boot_params, aliases, |
| 802 | name_buffer, NULL); |
| 803 | |
| 804 | if (alias_prop) { |
| 805 | i2c = fdt_path_offset(initial_boot_params, alias_prop); |
| 806 | if (i2c < 0) |
| 807 | continue; |
| 808 | if (i >= max_port) { |
| 809 | pr_debug("Deleting smi%d\n", i); |
| 810 | fdt_nop_node(initial_boot_params, i2c); |
| 811 | fdt_nop_property(initial_boot_params, aliases, |
| 812 | name_buffer); |
| 813 | } |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | /* Serial */ |
| 818 | uart_mask = 3; |
| 819 | |
| 820 | /* Right now CN52XX is the only chip with a third uart */ |
| 821 | if (OCTEON_IS_MODEL(OCTEON_CN52XX)) |
| 822 | uart_mask |= 4; /* uart2 */ |
| 823 | |
| 824 | for (i = 0; i < 3; i++) { |
| 825 | int uart; |
| 826 | snprintf(name_buffer, sizeof(name_buffer), |
| 827 | "uart%d", i); |
| 828 | alias_prop = fdt_getprop(initial_boot_params, aliases, |
| 829 | name_buffer, NULL); |
| 830 | |
| 831 | if (alias_prop) { |
| 832 | uart = fdt_path_offset(initial_boot_params, alias_prop); |
David Daney | 5219343 | 2013-06-19 20:37:26 +0000 | [diff] [blame] | 833 | if (uart_mask & (1 << i)) { |
| 834 | __be32 f; |
| 835 | |
| 836 | f = cpu_to_be32(octeon_get_io_clock_rate()); |
| 837 | fdt_setprop_inplace(initial_boot_params, |
| 838 | uart, "clock-frequency", |
| 839 | &f, sizeof(f)); |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 840 | continue; |
David Daney | 5219343 | 2013-06-19 20:37:26 +0000 | [diff] [blame] | 841 | } |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 842 | pr_debug("Deleting uart%d\n", i); |
| 843 | fdt_nop_node(initial_boot_params, uart); |
| 844 | fdt_nop_property(initial_boot_params, aliases, |
| 845 | name_buffer); |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | /* Compact Flash */ |
| 850 | alias_prop = fdt_getprop(initial_boot_params, aliases, |
| 851 | "cf0", NULL); |
| 852 | if (alias_prop) { |
| 853 | union cvmx_mio_boot_reg_cfgx mio_boot_reg_cfg; |
| 854 | unsigned long base_ptr, region_base, region_size; |
| 855 | unsigned long region1_base = 0; |
| 856 | unsigned long region1_size = 0; |
| 857 | int cs, bootbus; |
| 858 | bool is_16bit = false; |
| 859 | bool is_true_ide = false; |
| 860 | __be32 new_reg[6]; |
| 861 | __be32 *ranges; |
| 862 | int len; |
| 863 | |
| 864 | int cf = fdt_path_offset(initial_boot_params, alias_prop); |
| 865 | base_ptr = 0; |
| 866 | if (octeon_bootinfo->major_version == 1 |
| 867 | && octeon_bootinfo->minor_version >= 1) { |
| 868 | if (octeon_bootinfo->compact_flash_common_base_addr) |
| 869 | base_ptr = octeon_bootinfo->compact_flash_common_base_addr; |
| 870 | } else { |
| 871 | base_ptr = 0x1d000800; |
| 872 | } |
| 873 | |
| 874 | if (!base_ptr) |
| 875 | goto no_cf; |
| 876 | |
| 877 | /* Find CS0 region. */ |
| 878 | for (cs = 0; cs < 8; cs++) { |
| 879 | mio_boot_reg_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs)); |
| 880 | region_base = mio_boot_reg_cfg.s.base << 16; |
| 881 | region_size = (mio_boot_reg_cfg.s.size + 1) << 16; |
| 882 | if (mio_boot_reg_cfg.s.en && base_ptr >= region_base |
| 883 | && base_ptr < region_base + region_size) { |
| 884 | is_16bit = mio_boot_reg_cfg.s.width; |
| 885 | break; |
| 886 | } |
| 887 | } |
| 888 | if (cs >= 7) { |
| 889 | /* cs and cs + 1 are CS0 and CS1, both must be less than 8. */ |
| 890 | goto no_cf; |
| 891 | } |
| 892 | |
| 893 | if (!(base_ptr & 0xfffful)) { |
| 894 | /* |
| 895 | * Boot loader signals availability of DMA (true_ide |
| 896 | * mode) by setting low order bits of base_ptr to |
| 897 | * zero. |
| 898 | */ |
| 899 | |
| 900 | /* Asume that CS1 immediately follows. */ |
| 901 | mio_boot_reg_cfg.u64 = |
| 902 | cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs + 1)); |
| 903 | region1_base = mio_boot_reg_cfg.s.base << 16; |
| 904 | region1_size = (mio_boot_reg_cfg.s.size + 1) << 16; |
| 905 | if (!mio_boot_reg_cfg.s.en) |
| 906 | goto no_cf; |
| 907 | is_true_ide = true; |
| 908 | |
| 909 | } else { |
| 910 | fdt_nop_property(initial_boot_params, cf, "cavium,true-ide"); |
| 911 | fdt_nop_property(initial_boot_params, cf, "cavium,dma-engine-handle"); |
| 912 | if (!is_16bit) { |
| 913 | __be32 width = cpu_to_be32(8); |
| 914 | fdt_setprop_inplace(initial_boot_params, cf, |
| 915 | "cavium,bus-width", &width, sizeof(width)); |
| 916 | } |
| 917 | } |
| 918 | new_reg[0] = cpu_to_be32(cs); |
| 919 | new_reg[1] = cpu_to_be32(0); |
| 920 | new_reg[2] = cpu_to_be32(0x10000); |
| 921 | new_reg[3] = cpu_to_be32(cs + 1); |
| 922 | new_reg[4] = cpu_to_be32(0); |
| 923 | new_reg[5] = cpu_to_be32(0x10000); |
| 924 | fdt_setprop_inplace(initial_boot_params, cf, |
| 925 | "reg", new_reg, sizeof(new_reg)); |
| 926 | |
| 927 | bootbus = fdt_parent_offset(initial_boot_params, cf); |
| 928 | if (bootbus < 0) |
| 929 | goto no_cf; |
| 930 | ranges = fdt_getprop_w(initial_boot_params, bootbus, "ranges", &len); |
| 931 | if (!ranges || len < (5 * 8 * sizeof(__be32))) |
| 932 | goto no_cf; |
| 933 | |
| 934 | ranges[(cs * 5) + 2] = cpu_to_be32(region_base >> 32); |
| 935 | ranges[(cs * 5) + 3] = cpu_to_be32(region_base & 0xffffffff); |
| 936 | ranges[(cs * 5) + 4] = cpu_to_be32(region_size); |
| 937 | if (is_true_ide) { |
| 938 | cs++; |
| 939 | ranges[(cs * 5) + 2] = cpu_to_be32(region1_base >> 32); |
| 940 | ranges[(cs * 5) + 3] = cpu_to_be32(region1_base & 0xffffffff); |
| 941 | ranges[(cs * 5) + 4] = cpu_to_be32(region1_size); |
| 942 | } |
| 943 | goto end_cf; |
| 944 | no_cf: |
| 945 | fdt_nop_node(initial_boot_params, cf); |
| 946 | |
| 947 | end_cf: |
| 948 | ; |
| 949 | } |
| 950 | |
| 951 | /* 8 char LED */ |
| 952 | alias_prop = fdt_getprop(initial_boot_params, aliases, |
| 953 | "led0", NULL); |
| 954 | if (alias_prop) { |
| 955 | union cvmx_mio_boot_reg_cfgx mio_boot_reg_cfg; |
| 956 | unsigned long base_ptr, region_base, region_size; |
| 957 | int cs, bootbus; |
| 958 | __be32 new_reg[6]; |
| 959 | __be32 *ranges; |
| 960 | int len; |
| 961 | int led = fdt_path_offset(initial_boot_params, alias_prop); |
| 962 | |
| 963 | base_ptr = octeon_bootinfo->led_display_base_addr; |
| 964 | if (base_ptr == 0) |
| 965 | goto no_led; |
| 966 | /* Find CS0 region. */ |
| 967 | for (cs = 0; cs < 8; cs++) { |
| 968 | mio_boot_reg_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs)); |
| 969 | region_base = mio_boot_reg_cfg.s.base << 16; |
| 970 | region_size = (mio_boot_reg_cfg.s.size + 1) << 16; |
| 971 | if (mio_boot_reg_cfg.s.en && base_ptr >= region_base |
| 972 | && base_ptr < region_base + region_size) |
| 973 | break; |
| 974 | } |
| 975 | |
| 976 | if (cs > 7) |
| 977 | goto no_led; |
| 978 | |
| 979 | new_reg[0] = cpu_to_be32(cs); |
| 980 | new_reg[1] = cpu_to_be32(0x20); |
| 981 | new_reg[2] = cpu_to_be32(0x20); |
| 982 | new_reg[3] = cpu_to_be32(cs); |
| 983 | new_reg[4] = cpu_to_be32(0); |
| 984 | new_reg[5] = cpu_to_be32(0x20); |
| 985 | fdt_setprop_inplace(initial_boot_params, led, |
| 986 | "reg", new_reg, sizeof(new_reg)); |
| 987 | |
| 988 | bootbus = fdt_parent_offset(initial_boot_params, led); |
| 989 | if (bootbus < 0) |
| 990 | goto no_led; |
| 991 | ranges = fdt_getprop_w(initial_boot_params, bootbus, "ranges", &len); |
| 992 | if (!ranges || len < (5 * 8 * sizeof(__be32))) |
| 993 | goto no_led; |
| 994 | |
| 995 | ranges[(cs * 5) + 2] = cpu_to_be32(region_base >> 32); |
| 996 | ranges[(cs * 5) + 3] = cpu_to_be32(region_base & 0xffffffff); |
| 997 | ranges[(cs * 5) + 4] = cpu_to_be32(region_size); |
| 998 | goto end_led; |
| 999 | |
| 1000 | no_led: |
| 1001 | fdt_nop_node(initial_boot_params, led); |
| 1002 | end_led: |
| 1003 | ; |
| 1004 | } |
| 1005 | |
Steven J. Hill | 7fd57ab | 2017-03-09 08:15:38 -0600 | [diff] [blame^] | 1006 | #ifdef CONFIG_USB |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 1007 | /* OHCI/UHCI USB */ |
| 1008 | alias_prop = fdt_getprop(initial_boot_params, aliases, |
| 1009 | "uctl", NULL); |
| 1010 | if (alias_prop) { |
| 1011 | int uctl = fdt_path_offset(initial_boot_params, alias_prop); |
| 1012 | |
| 1013 | if (uctl >= 0 && (!OCTEON_IS_MODEL(OCTEON_CN6XXX) || |
| 1014 | octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC2E)) { |
| 1015 | pr_debug("Deleting uctl\n"); |
| 1016 | fdt_nop_node(initial_boot_params, uctl); |
| 1017 | fdt_nop_property(initial_boot_params, aliases, "uctl"); |
| 1018 | } else if (octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC10E || |
| 1019 | octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC4E) { |
| 1020 | /* Missing "refclk-type" defaults to crystal. */ |
| 1021 | fdt_nop_property(initial_boot_params, uctl, "refclk-type"); |
| 1022 | } |
| 1023 | } |
| 1024 | |
David Daney | d617f9e | 2013-12-03 11:46:51 -0800 | [diff] [blame] | 1025 | /* DWC2 USB */ |
| 1026 | alias_prop = fdt_getprop(initial_boot_params, aliases, |
| 1027 | "usbn", NULL); |
| 1028 | if (alias_prop) { |
| 1029 | int usbn = fdt_path_offset(initial_boot_params, alias_prop); |
| 1030 | |
| 1031 | if (usbn >= 0 && (current_cpu_type() == CPU_CAVIUM_OCTEON2 || |
| 1032 | !octeon_has_feature(OCTEON_FEATURE_USB))) { |
| 1033 | pr_debug("Deleting usbn\n"); |
| 1034 | fdt_nop_node(initial_boot_params, usbn); |
| 1035 | fdt_nop_property(initial_boot_params, aliases, "usbn"); |
| 1036 | } else { |
| 1037 | __be32 new_f[1]; |
| 1038 | enum cvmx_helper_board_usb_clock_types c; |
| 1039 | c = __cvmx_helper_board_usb_get_clock_type(); |
| 1040 | switch (c) { |
| 1041 | case USB_CLOCK_TYPE_REF_48: |
| 1042 | new_f[0] = cpu_to_be32(48000000); |
| 1043 | fdt_setprop_inplace(initial_boot_params, usbn, |
| 1044 | "refclk-frequency", new_f, sizeof(new_f)); |
| 1045 | /* Fall through ...*/ |
| 1046 | case USB_CLOCK_TYPE_REF_12: |
| 1047 | /* Missing "refclk-type" defaults to external. */ |
| 1048 | fdt_nop_property(initial_boot_params, usbn, "refclk-type"); |
| 1049 | break; |
| 1050 | default: |
| 1051 | break; |
| 1052 | } |
| 1053 | } |
| 1054 | } |
Steven J. Hill | 7fd57ab | 2017-03-09 08:15:38 -0600 | [diff] [blame^] | 1055 | #endif |
David Daney | d617f9e | 2013-12-03 11:46:51 -0800 | [diff] [blame] | 1056 | |
David Daney | 7ed1815 | 2012-07-05 18:12:38 +0200 | [diff] [blame] | 1057 | return 0; |
| 1058 | } |
| 1059 | |
| 1060 | static int __init octeon_publish_devices(void) |
| 1061 | { |
| 1062 | return of_platform_bus_probe(NULL, octeon_ids, NULL); |
| 1063 | } |
Aaro Koskinen | 8074d78 | 2016-08-23 21:39:43 +0300 | [diff] [blame] | 1064 | arch_initcall(octeon_publish_devices); |