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
6 * Copyright (C) 2004-2017 Cavium, Inc.
7 * Copyright (C) 2008 Wind River Systems
10 #include <linux/etherdevice.h>
12 #include <linux/of_platform.h>
13 #include <linux/of_fdt.h>
14 #include <linux/platform_device.h>
15 #include <linux/libfdt.h>
17 #include <asm/octeon/octeon.h>
18 #include <asm/octeon/cvmx-helper-board.h>
21 #include <linux/usb/ehci_def.h>
22 #include <linux/usb/ehci_pdriver.h>
23 #include <linux/usb/ohci_pdriver.h>
24 #include <asm/octeon/cvmx-uctlx-defs.h>
26 #define CVMX_UAHCX_EHCI_USBCMD (CVMX_ADD_IO_SEG(0x00016F0000000010ull))
27 #define CVMX_UAHCX_OHCI_USBCMD (CVMX_ADD_IO_SEG(0x00016F0000000408ull))
29 static DEFINE_MUTEX(octeon2_usb_clocks_mutex
);
31 static int octeon2_usb_clock_start_cnt
;
33 static int __init
octeon2_usb_reset(void)
35 union cvmx_uctlx_clk_rst_ctl clk_rst_ctl
;
38 if (!OCTEON_IS_OCTEON2())
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
);
45 cvmx_write64_uint32(CVMX_UAHCX_EHCI_USBCMD
, ucmd
);
48 cvmx_write64_uint32(CVMX_UAHCX_EHCI_USBCMD
, ucmd
);
49 ucmd
= cvmx_read64_uint32(CVMX_UAHCX_OHCI_USBCMD
);
51 cvmx_write64_uint32(CVMX_UAHCX_OHCI_USBCMD
, ucmd
);
56 arch_initcall(octeon2_usb_reset
);
58 static void octeon2_usb_clocks_start(struct device
*dev
)
61 union cvmx_uctlx_if_ena if_ena
;
62 union cvmx_uctlx_clk_rst_ctl clk_rst_ctl
;
63 union cvmx_uctlx_uphy_portx_ctl_status port_ctl_status
;
65 unsigned long io_clk_64_to_ns
;
66 u32 clock_rate
= 12000000;
67 bool is_crystal_clock
= false;
70 mutex_lock(&octeon2_usb_clocks_mutex
);
72 octeon2_usb_clock_start_cnt
++;
73 if (octeon2_usb_clock_start_cnt
!= 1)
76 io_clk_64_to_ns
= 64000000000ull / octeon_get_io_clock_rate();
79 struct device_node
*uctl_node
;
80 const char *clock_type
;
82 uctl_node
= of_get_parent(dev
->of_node
);
84 dev_err(dev
, "No UCTL device node\n");
87 i
= of_property_read_u32(uctl_node
,
88 "refclk-frequency", &clock_rate
);
90 dev_err(dev
, "No UCTL \"refclk-frequency\"\n");
91 of_node_put(uctl_node
);
94 i
= of_property_read_string(uctl_node
,
95 "refclk-type", &clock_type
);
96 of_node_put(uctl_node
);
97 if (!i
&& strcmp("crystal", clock_type
) == 0)
98 is_crystal_clock
= true;
102 * Step 1: Wait for voltages stable. That surely happened
103 * before starting the kernel.
105 * Step 2: Enable SCLK of UCTL by writing UCTL0_IF_ENA[EN] = 1
109 cvmx_write_csr(CVMX_UCTLX_IF_ENA(0), if_ena
.u64
);
111 for (i
= 0; i
<= 1; i
++) {
112 port_ctl_status
.u64
=
113 cvmx_read_csr(CVMX_UCTLX_UPHY_PORTX_CTL_STATUS(i
, 0));
114 /* Set txvreftune to 15 to obtain compliant 'eye' diagram. */
115 port_ctl_status
.s
.txvreftune
= 15;
116 port_ctl_status
.s
.txrisetune
= 1;
117 port_ctl_status
.s
.txpreemphasistune
= 1;
118 cvmx_write_csr(CVMX_UCTLX_UPHY_PORTX_CTL_STATUS(i
, 0),
119 port_ctl_status
.u64
);
122 /* Step 3: Configure the reference clock, PHY, and HCLK */
123 clk_rst_ctl
.u64
= cvmx_read_csr(CVMX_UCTLX_CLK_RST_CTL(0));
126 * If the UCTL looks like it has already been started, skip
127 * the initialization, otherwise bus errors are obtained.
129 if (clk_rst_ctl
.s
.hrst
)
132 clk_rst_ctl
.s
.p_por
= 1;
133 clk_rst_ctl
.s
.hrst
= 0;
134 clk_rst_ctl
.s
.p_prst
= 0;
135 clk_rst_ctl
.s
.h_clkdiv_rst
= 0;
136 clk_rst_ctl
.s
.o_clkdiv_rst
= 0;
137 clk_rst_ctl
.s
.h_clkdiv_en
= 0;
138 clk_rst_ctl
.s
.o_clkdiv_en
= 0;
139 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl
.u64
);
142 clk_rst_ctl
.s
.p_refclk_sel
= is_crystal_clock
? 0 : 1;
143 switch (clock_rate
) {
145 pr_err("Invalid UCTL clock rate of %u, using 12000000 instead\n",
149 clk_rst_ctl
.s
.p_refclk_div
= 0;
152 clk_rst_ctl
.s
.p_refclk_div
= 1;
155 clk_rst_ctl
.s
.p_refclk_div
= 2;
158 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl
.u64
);
161 div
= octeon_get_io_clock_rate() / 130000000ull;
189 clk_rst_ctl
.s
.h_div
= div
;
190 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl
.u64
);
192 clk_rst_ctl
.u64
= cvmx_read_csr(CVMX_UCTLX_CLK_RST_CTL(0));
193 clk_rst_ctl
.s
.h_clkdiv_en
= 1;
194 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl
.u64
);
196 clk_rst_ctl
.s
.h_clkdiv_rst
= 1;
197 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl
.u64
);
199 /* 3e: delay 64 io clocks */
200 ndelay(io_clk_64_to_ns
);
203 * Step 4: Program the power-on reset field in the UCTL
204 * clock-reset-control register.
206 clk_rst_ctl
.s
.p_por
= 0;
207 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl
.u64
);
209 /* Step 5: Wait 3 ms for the PHY clock to start. */
212 /* Steps 6..9 for ATE only, are skipped. */
214 /* Step 10: Configure the OHCI_CLK48 and OHCI_CLK12 clocks. */
216 clk_rst_ctl
.s
.o_clkdiv_rst
= 1;
217 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl
.u64
);
220 clk_rst_ctl
.s
.o_clkdiv_en
= 1;
221 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl
.u64
);
224 ndelay(io_clk_64_to_ns
);
227 * Step 11: Program the PHY reset field:
228 * UCTL0_CLK_RST_CTL[P_PRST] = 1
230 clk_rst_ctl
.s
.p_prst
= 1;
231 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl
.u64
);
237 clk_rst_ctl
.s
.p_prst
= 0;
238 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl
.u64
);
244 clk_rst_ctl
.s
.p_prst
= 1;
245 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl
.u64
);
247 /* Step 12: Wait 1 uS. */
250 /* Step 13: Program the HRESET_N field: UCTL0_CLK_RST_CTL[HRST] = 1 */
251 clk_rst_ctl
.s
.hrst
= 1;
252 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl
.u64
);
255 /* Set uSOF cycle period to 60,000 bits. */
256 cvmx_write_csr(CVMX_UCTLX_EHCI_FLA(0), 0x20ull
);
259 mutex_unlock(&octeon2_usb_clocks_mutex
);
262 static void octeon2_usb_clocks_stop(void)
264 mutex_lock(&octeon2_usb_clocks_mutex
);
265 octeon2_usb_clock_start_cnt
--;
266 mutex_unlock(&octeon2_usb_clocks_mutex
);
269 static int octeon_ehci_power_on(struct platform_device
*pdev
)
271 octeon2_usb_clocks_start(&pdev
->dev
);
275 static void octeon_ehci_power_off(struct platform_device
*pdev
)
277 octeon2_usb_clocks_stop();
280 static struct usb_ehci_pdata octeon_ehci_pdata
= {
281 /* Octeon EHCI matches CPU endianness. */
283 .big_endian_mmio
= 1,
286 * We can DMA from anywhere. But the descriptors must be in
290 .power_on
= octeon_ehci_power_on
,
291 .power_off
= octeon_ehci_power_off
,
294 static void __init
octeon_ehci_hw_start(struct device
*dev
)
296 union cvmx_uctlx_ehci_ctl ehci_ctl
;
298 octeon2_usb_clocks_start(dev
);
300 ehci_ctl
.u64
= cvmx_read_csr(CVMX_UCTLX_EHCI_CTL(0));
301 /* Use 64-bit addressing. */
302 ehci_ctl
.s
.ehci_64b_addr_en
= 1;
303 ehci_ctl
.s
.l2c_addr_msb
= 0;
305 ehci_ctl
.s
.l2c_buff_emod
= 1; /* Byte swapped. */
306 ehci_ctl
.s
.l2c_desc_emod
= 1; /* Byte swapped. */
308 ehci_ctl
.s
.l2c_buff_emod
= 0; /* not swapped. */
309 ehci_ctl
.s
.l2c_desc_emod
= 0; /* not swapped. */
310 ehci_ctl
.s
.inv_reg_a2
= 1;
312 cvmx_write_csr(CVMX_UCTLX_EHCI_CTL(0), ehci_ctl
.u64
);
314 octeon2_usb_clocks_stop();
317 static int __init
octeon_ehci_device_init(void)
319 struct platform_device
*pd
;
320 struct device_node
*ehci_node
;
323 ehci_node
= of_find_node_by_name(NULL
, "ehci");
327 pd
= of_find_device_by_node(ehci_node
);
328 of_node_put(ehci_node
);
332 pd
->dev
.platform_data
= &octeon_ehci_pdata
;
333 octeon_ehci_hw_start(&pd
->dev
);
334 put_device(&pd
->dev
);
338 device_initcall(octeon_ehci_device_init
);
340 static int octeon_ohci_power_on(struct platform_device
*pdev
)
342 octeon2_usb_clocks_start(&pdev
->dev
);
346 static void octeon_ohci_power_off(struct platform_device
*pdev
)
348 octeon2_usb_clocks_stop();
351 static struct usb_ohci_pdata octeon_ohci_pdata
= {
352 /* Octeon OHCI matches CPU endianness. */
354 .big_endian_mmio
= 1,
356 .power_on
= octeon_ohci_power_on
,
357 .power_off
= octeon_ohci_power_off
,
360 static void __init
octeon_ohci_hw_start(struct device
*dev
)
362 union cvmx_uctlx_ohci_ctl ohci_ctl
;
364 octeon2_usb_clocks_start(dev
);
366 ohci_ctl
.u64
= cvmx_read_csr(CVMX_UCTLX_OHCI_CTL(0));
367 ohci_ctl
.s
.l2c_addr_msb
= 0;
369 ohci_ctl
.s
.l2c_buff_emod
= 1; /* Byte swapped. */
370 ohci_ctl
.s
.l2c_desc_emod
= 1; /* Byte swapped. */
372 ohci_ctl
.s
.l2c_buff_emod
= 0; /* not swapped. */
373 ohci_ctl
.s
.l2c_desc_emod
= 0; /* not swapped. */
374 ohci_ctl
.s
.inv_reg_a2
= 1;
376 cvmx_write_csr(CVMX_UCTLX_OHCI_CTL(0), ohci_ctl
.u64
);
378 octeon2_usb_clocks_stop();
381 static int __init
octeon_ohci_device_init(void)
383 struct platform_device
*pd
;
384 struct device_node
*ohci_node
;
387 ohci_node
= of_find_node_by_name(NULL
, "ohci");
391 pd
= of_find_device_by_node(ohci_node
);
392 of_node_put(ohci_node
);
396 pd
->dev
.platform_data
= &octeon_ohci_pdata
;
397 octeon_ohci_hw_start(&pd
->dev
);
398 put_device(&pd
->dev
);
402 device_initcall(octeon_ohci_device_init
);
404 #endif /* CONFIG_USB */
406 /* Octeon Random Number Generator. */
407 static int __init
octeon_rng_device_init(void)
409 struct platform_device
*pd
;
412 struct resource rng_resources
[] = {
414 .flags
= IORESOURCE_MEM
,
415 .start
= XKPHYS_TO_PHYS(CVMX_RNM_CTL_STATUS
),
416 .end
= XKPHYS_TO_PHYS(CVMX_RNM_CTL_STATUS
) + 0xf
418 .flags
= IORESOURCE_MEM
,
419 .start
= cvmx_build_io_address(8, 0),
420 .end
= cvmx_build_io_address(8, 0) + 0x7
424 pd
= platform_device_alloc("octeon_rng", -1);
430 ret
= platform_device_add_resources(pd
, rng_resources
,
431 ARRAY_SIZE(rng_resources
));
435 ret
= platform_device_add(pd
);
441 platform_device_put(pd
);
446 device_initcall(octeon_rng_device_init
);
448 static const struct of_device_id octeon_ids
[] __initconst
= {
449 { .compatible
= "simple-bus", },
450 { .compatible
= "cavium,octeon-6335-uctl", },
451 { .compatible
= "cavium,octeon-5750-usbn", },
452 { .compatible
= "cavium,octeon-3860-bootbus", },
453 { .compatible
= "cavium,mdio-mux", },
454 { .compatible
= "gpio-leds", },
458 static bool __init
octeon_has_88e1145(void)
460 return !OCTEON_IS_MODEL(OCTEON_CN52XX
) &&
461 !OCTEON_IS_MODEL(OCTEON_CN6XXX
) &&
462 !OCTEON_IS_MODEL(OCTEON_CN56XX
);
465 static bool __init
octeon_has_fixed_link(int ipd_port
)
467 switch (cvmx_sysinfo_get()->board_type
) {
468 case CVMX_BOARD_TYPE_CN3005_EVB_HS5
:
469 case CVMX_BOARD_TYPE_CN3010_EVB_HS5
:
470 case CVMX_BOARD_TYPE_CN3020_EVB_HS5
:
471 case CVMX_BOARD_TYPE_CUST_NB5
:
472 case CVMX_BOARD_TYPE_EBH3100
:
473 /* Port 1 on these boards is always gigabit. */
474 return ipd_port
== 1;
475 case CVMX_BOARD_TYPE_BBGW_REF
:
476 /* Ports 0 and 1 connect to the switch. */
477 return ipd_port
== 0 || ipd_port
== 1;
482 static void __init
octeon_fdt_set_phy(int eth
, int phy_addr
)
484 const __be32
*phy_handle
;
485 const __be32
*alt_phy_handle
;
494 phy_handle
= fdt_getprop(initial_boot_params
, eth
, "phy-handle", NULL
);
498 phandle
= be32_to_cpup(phy_handle
);
499 phy
= fdt_node_offset_by_phandle(initial_boot_params
, phandle
);
501 alt_phy_handle
= fdt_getprop(initial_boot_params
, eth
, "cavium,alt-phy-handle", NULL
);
502 if (alt_phy_handle
) {
503 u32 alt_phandle
= be32_to_cpup(alt_phy_handle
);
505 alt_phy
= fdt_node_offset_by_phandle(initial_boot_params
, alt_phandle
);
510 if (phy_addr
< 0 || phy
< 0) {
511 /* Delete the PHY things */
512 fdt_nop_property(initial_boot_params
, eth
, "phy-handle");
513 /* This one may fail */
514 fdt_nop_property(initial_boot_params
, eth
, "cavium,alt-phy-handle");
516 fdt_nop_node(initial_boot_params
, phy
);
518 fdt_nop_node(initial_boot_params
, alt_phy
);
522 if (phy_addr
>= 256 && alt_phy
> 0) {
523 const struct fdt_property
*phy_prop
;
524 struct fdt_property
*alt_prop
;
525 fdt32_t phy_handle_name
;
527 /* Use the alt phy node instead.*/
528 phy_prop
= fdt_get_property(initial_boot_params
, eth
, "phy-handle", NULL
);
529 phy_handle_name
= phy_prop
->nameoff
;
530 fdt_nop_node(initial_boot_params
, phy
);
531 fdt_nop_property(initial_boot_params
, eth
, "phy-handle");
532 alt_prop
= fdt_get_property_w(initial_boot_params
, eth
, "cavium,alt-phy-handle", NULL
);
533 alt_prop
->nameoff
= phy_handle_name
;
539 if (octeon_has_88e1145()) {
540 fdt_nop_property(initial_boot_params
, phy
, "marvell,reg-init");
541 memset(new_name
, 0, sizeof(new_name
));
542 strcpy(new_name
, "marvell,88e1145");
543 p
= fdt_getprop(initial_boot_params
, phy
, "compatible",
545 if (p
&& current_len
>= strlen(new_name
))
546 fdt_setprop_inplace(initial_boot_params
, phy
,
547 "compatible", new_name
, current_len
);
550 reg
= fdt_getprop(initial_boot_params
, phy
, "reg", NULL
);
551 if (phy_addr
== be32_to_cpup(reg
))
554 fdt_setprop_inplace_cell(initial_boot_params
, phy
, "reg", phy_addr
);
556 snprintf(new_name
, sizeof(new_name
), "ethernet-phy@%x", phy_addr
);
558 p
= fdt_get_name(initial_boot_params
, phy
, ¤t_len
);
559 if (p
&& current_len
== strlen(new_name
))
560 fdt_set_name(initial_boot_params
, phy
, new_name
);
562 pr_err("Error: could not rename ethernet phy: <%s>", p
);
565 static void __init
octeon_fdt_set_mac_addr(int n
, u64
*pmac
)
573 old_mac
= fdt_getprop(initial_boot_params
, n
, "local-mac-address",
575 if (!old_mac
|| old_len
!= 6 || is_valid_ether_addr(old_mac
))
578 new_mac
[0] = (mac
>> 40) & 0xff;
579 new_mac
[1] = (mac
>> 32) & 0xff;
580 new_mac
[2] = (mac
>> 24) & 0xff;
581 new_mac
[3] = (mac
>> 16) & 0xff;
582 new_mac
[4] = (mac
>> 8) & 0xff;
583 new_mac
[5] = mac
& 0xff;
585 r
= fdt_setprop_inplace(initial_boot_params
, n
, "local-mac-address",
586 new_mac
, sizeof(new_mac
));
589 pr_err("Setting \"local-mac-address\" failed %d", r
);
595 static void __init
octeon_fdt_rm_ethernet(int node
)
597 const __be32
*phy_handle
;
599 phy_handle
= fdt_getprop(initial_boot_params
, node
, "phy-handle", NULL
);
601 u32 ph
= be32_to_cpup(phy_handle
);
602 int p
= fdt_node_offset_by_phandle(initial_boot_params
, ph
);
605 fdt_nop_node(initial_boot_params
, p
);
607 fdt_nop_node(initial_boot_params
, node
);
610 static void __init
_octeon_rx_tx_delay(int eth
, int rx_delay
, int tx_delay
)
612 fdt_setprop_inplace_cell(initial_boot_params
, eth
, "rx-delay",
614 fdt_setprop_inplace_cell(initial_boot_params
, eth
, "tx-delay",
618 static void __init
octeon_rx_tx_delay(int eth
, int iface
, int port
)
620 switch (cvmx_sysinfo_get()->board_type
) {
621 case CVMX_BOARD_TYPE_CN3005_EVB_HS5
:
625 * Boards with gigabit WAN ports need a
626 * different setting that is compatible with
629 _octeon_rx_tx_delay(eth
, 0xc, 0x0c);
631 } else if (port
== 1) {
632 /* Different config for switch port. */
633 _octeon_rx_tx_delay(eth
, 0x0, 0x0);
638 case CVMX_BOARD_TYPE_UBNT_E100
:
639 if (iface
== 0 && port
<= 2) {
640 _octeon_rx_tx_delay(eth
, 0x0, 0x10);
645 fdt_nop_property(initial_boot_params
, eth
, "rx-delay");
646 fdt_nop_property(initial_boot_params
, eth
, "tx-delay");
649 static void __init
octeon_fdt_pip_port(int iface
, int i
, int p
, int max
)
651 char name_buffer
[20];
657 snprintf(name_buffer
, sizeof(name_buffer
), "ethernet@%x", p
);
658 eth
= fdt_subnode_offset(initial_boot_params
, iface
, name_buffer
);
662 pr_debug("Deleting port %x:%x\n", i
, p
);
663 octeon_fdt_rm_ethernet(eth
);
666 if (OCTEON_IS_MODEL(OCTEON_CN68XX
))
667 ipd_port
= (0x100 * i
) + (0x10 * p
) + 0x800;
669 ipd_port
= 16 * i
+ p
;
671 phy_addr
= cvmx_helper_board_get_mii_address(ipd_port
);
672 octeon_fdt_set_phy(eth
, phy_addr
);
674 fixed_link
= fdt_subnode_offset(initial_boot_params
, eth
, "fixed-link");
676 WARN_ON(octeon_has_fixed_link(ipd_port
));
677 else if (!octeon_has_fixed_link(ipd_port
))
678 fdt_nop_node(initial_boot_params
, fixed_link
);
679 octeon_rx_tx_delay(eth
, i
, p
);
682 static void __init
octeon_fdt_pip_iface(int pip
, int idx
)
684 char name_buffer
[20];
689 snprintf(name_buffer
, sizeof(name_buffer
), "interface@%d", idx
);
690 iface
= fdt_subnode_offset(initial_boot_params
, pip
, name_buffer
);
694 if (cvmx_helper_interface_enumerate(idx
) == 0)
695 count
= cvmx_helper_ports_on_interface(idx
);
697 for (p
= 0; p
< 16; p
++)
698 octeon_fdt_pip_port(iface
, idx
, p
, count
- 1);
701 void __init
octeon_fill_mac_addresses(void)
703 const char *alias_prop
;
704 char name_buffer
[20];
710 aliases
= fdt_path_offset(initial_boot_params
, "/aliases");
715 ((octeon_bootinfo
->mac_addr_base
[0] & 0xffull
)) << 40 |
716 ((octeon_bootinfo
->mac_addr_base
[1] & 0xffull
)) << 32 |
717 ((octeon_bootinfo
->mac_addr_base
[2] & 0xffull
)) << 24 |
718 ((octeon_bootinfo
->mac_addr_base
[3] & 0xffull
)) << 16 |
719 ((octeon_bootinfo
->mac_addr_base
[4] & 0xffull
)) << 8 |
720 (octeon_bootinfo
->mac_addr_base
[5] & 0xffull
);
722 for (i
= 0; i
< 2; i
++) {
725 snprintf(name_buffer
, sizeof(name_buffer
), "mix%d", i
);
726 alias_prop
= fdt_getprop(initial_boot_params
, aliases
,
730 mgmt
= fdt_path_offset(initial_boot_params
, alias_prop
);
733 octeon_fdt_set_mac_addr(mgmt
, &mac_addr_base
);
736 alias_prop
= fdt_getprop(initial_boot_params
, aliases
, "pip", NULL
);
740 pip
= fdt_path_offset(initial_boot_params
, alias_prop
);
744 for (i
= 0; i
<= 4; i
++) {
748 snprintf(name_buffer
, sizeof(name_buffer
), "interface@%d", i
);
749 iface
= fdt_subnode_offset(initial_boot_params
, pip
,
753 for (p
= 0; p
< 16; p
++) {
756 snprintf(name_buffer
, sizeof(name_buffer
),
758 eth
= fdt_subnode_offset(initial_boot_params
, iface
,
762 octeon_fdt_set_mac_addr(eth
, &mac_addr_base
);
767 int __init
octeon_prune_device_tree(void)
769 int i
, max_port
, uart_mask
;
770 const char *pip_path
;
771 const char *alias_prop
;
772 char name_buffer
[20];
775 if (fdt_check_header(initial_boot_params
))
776 panic("Corrupt Device Tree.");
778 WARN(octeon_bootinfo
->board_type
== CVMX_BOARD_TYPE_CUST_DSR1000N
,
779 "Built-in DTB booting is deprecated on %s. Please switch to use appended DTB.",
780 cvmx_board_type_to_string(octeon_bootinfo
->board_type
));
782 aliases
= fdt_path_offset(initial_boot_params
, "/aliases");
784 pr_err("Error: No /aliases node in device tree.");
788 if (OCTEON_IS_MODEL(OCTEON_CN52XX
) || OCTEON_IS_MODEL(OCTEON_CN63XX
))
790 else if (OCTEON_IS_MODEL(OCTEON_CN56XX
) || OCTEON_IS_MODEL(OCTEON_CN68XX
))
795 if (octeon_bootinfo
->board_type
== CVMX_BOARD_TYPE_NIC10E
)
798 for (i
= 0; i
< 2; i
++) {
801 snprintf(name_buffer
, sizeof(name_buffer
),
803 alias_prop
= fdt_getprop(initial_boot_params
, aliases
,
806 mgmt
= fdt_path_offset(initial_boot_params
, alias_prop
);
810 pr_debug("Deleting mix%d\n", i
);
811 octeon_fdt_rm_ethernet(mgmt
);
812 fdt_nop_property(initial_boot_params
, aliases
,
815 int phy_addr
= cvmx_helper_board_get_mii_address(CVMX_HELPER_BOARD_MGMT_IPD_PORT
+ i
);
817 octeon_fdt_set_phy(mgmt
, phy_addr
);
822 pip_path
= fdt_getprop(initial_boot_params
, aliases
, "pip", NULL
);
824 int pip
= fdt_path_offset(initial_boot_params
, pip_path
);
827 for (i
= 0; i
<= 4; i
++)
828 octeon_fdt_pip_iface(pip
, i
);
832 if (OCTEON_IS_MODEL(OCTEON_CN52XX
) ||
833 OCTEON_IS_MODEL(OCTEON_CN63XX
) ||
834 OCTEON_IS_MODEL(OCTEON_CN68XX
) ||
835 OCTEON_IS_MODEL(OCTEON_CN56XX
))
840 for (i
= 0; i
< 2; i
++) {
843 snprintf(name_buffer
, sizeof(name_buffer
),
845 alias_prop
= fdt_getprop(initial_boot_params
, aliases
,
849 i2c
= fdt_path_offset(initial_boot_params
, alias_prop
);
853 pr_debug("Deleting twsi%d\n", i
);
854 fdt_nop_node(initial_boot_params
, i2c
);
855 fdt_nop_property(initial_boot_params
, aliases
,
862 if (OCTEON_IS_MODEL(OCTEON_CN68XX
))
864 else if (OCTEON_IS_MODEL(OCTEON_CN52XX
) ||
865 OCTEON_IS_MODEL(OCTEON_CN63XX
) ||
866 OCTEON_IS_MODEL(OCTEON_CN56XX
))
871 for (i
= 0; i
< 2; i
++) {
874 snprintf(name_buffer
, sizeof(name_buffer
),
876 alias_prop
= fdt_getprop(initial_boot_params
, aliases
,
879 i2c
= fdt_path_offset(initial_boot_params
, alias_prop
);
883 pr_debug("Deleting smi%d\n", i
);
884 fdt_nop_node(initial_boot_params
, i2c
);
885 fdt_nop_property(initial_boot_params
, aliases
,
894 /* Right now CN52XX is the only chip with a third uart */
895 if (OCTEON_IS_MODEL(OCTEON_CN52XX
))
896 uart_mask
|= 4; /* uart2 */
898 for (i
= 0; i
< 3; i
++) {
901 snprintf(name_buffer
, sizeof(name_buffer
),
903 alias_prop
= fdt_getprop(initial_boot_params
, aliases
,
907 uart
= fdt_path_offset(initial_boot_params
, alias_prop
);
908 if (uart_mask
& (1 << i
)) {
911 f
= cpu_to_be32(octeon_get_io_clock_rate());
912 fdt_setprop_inplace(initial_boot_params
,
913 uart
, "clock-frequency",
917 pr_debug("Deleting uart%d\n", i
);
918 fdt_nop_node(initial_boot_params
, uart
);
919 fdt_nop_property(initial_boot_params
, aliases
,
925 alias_prop
= fdt_getprop(initial_boot_params
, aliases
,
928 union cvmx_mio_boot_reg_cfgx mio_boot_reg_cfg
;
929 unsigned long base_ptr
, region_base
, region_size
;
930 unsigned long region1_base
= 0;
931 unsigned long region1_size
= 0;
933 bool is_16bit
= false;
934 bool is_true_ide
= false;
939 int cf
= fdt_path_offset(initial_boot_params
, alias_prop
);
942 if (octeon_bootinfo
->major_version
== 1
943 && octeon_bootinfo
->minor_version
>= 1) {
944 if (octeon_bootinfo
->compact_flash_common_base_addr
)
945 base_ptr
= octeon_bootinfo
->compact_flash_common_base_addr
;
947 base_ptr
= 0x1d000800;
953 /* Find CS0 region. */
954 for (cs
= 0; cs
< 8; cs
++) {
955 mio_boot_reg_cfg
.u64
= cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs
));
956 region_base
= mio_boot_reg_cfg
.s
.base
<< 16;
957 region_size
= (mio_boot_reg_cfg
.s
.size
+ 1) << 16;
958 if (mio_boot_reg_cfg
.s
.en
&& base_ptr
>= region_base
959 && base_ptr
< region_base
+ region_size
) {
960 is_16bit
= mio_boot_reg_cfg
.s
.width
;
965 /* cs and cs + 1 are CS0 and CS1, both must be less than 8. */
969 if (!(base_ptr
& 0xfffful
)) {
971 * Boot loader signals availability of DMA (true_ide
972 * mode) by setting low order bits of base_ptr to
976 /* Assume that CS1 immediately follows. */
977 mio_boot_reg_cfg
.u64
=
978 cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs
+ 1));
979 region1_base
= mio_boot_reg_cfg
.s
.base
<< 16;
980 region1_size
= (mio_boot_reg_cfg
.s
.size
+ 1) << 16;
981 if (!mio_boot_reg_cfg
.s
.en
)
986 fdt_nop_property(initial_boot_params
, cf
, "cavium,true-ide");
987 fdt_nop_property(initial_boot_params
, cf
, "cavium,dma-engine-handle");
989 __be32 width
= cpu_to_be32(8);
991 fdt_setprop_inplace(initial_boot_params
, cf
,
992 "cavium,bus-width", &width
, sizeof(width
));
995 new_reg
[0] = cpu_to_be32(cs
);
996 new_reg
[1] = cpu_to_be32(0);
997 new_reg
[2] = cpu_to_be32(0x10000);
998 new_reg
[3] = cpu_to_be32(cs
+ 1);
999 new_reg
[4] = cpu_to_be32(0);
1000 new_reg
[5] = cpu_to_be32(0x10000);
1001 fdt_setprop_inplace(initial_boot_params
, cf
,
1002 "reg", new_reg
, sizeof(new_reg
));
1004 bootbus
= fdt_parent_offset(initial_boot_params
, cf
);
1007 ranges
= fdt_getprop_w(initial_boot_params
, bootbus
, "ranges", &len
);
1008 if (!ranges
|| len
< (5 * 8 * sizeof(__be32
)))
1011 ranges
[(cs
* 5) + 2] = cpu_to_be32(region_base
>> 32);
1012 ranges
[(cs
* 5) + 3] = cpu_to_be32(region_base
& 0xffffffff);
1013 ranges
[(cs
* 5) + 4] = cpu_to_be32(region_size
);
1016 ranges
[(cs
* 5) + 2] = cpu_to_be32(region1_base
>> 32);
1017 ranges
[(cs
* 5) + 3] = cpu_to_be32(region1_base
& 0xffffffff);
1018 ranges
[(cs
* 5) + 4] = cpu_to_be32(region1_size
);
1022 fdt_nop_node(initial_boot_params
, cf
);
1029 alias_prop
= fdt_getprop(initial_boot_params
, aliases
,
1032 union cvmx_mio_boot_reg_cfgx mio_boot_reg_cfg
;
1033 unsigned long base_ptr
, region_base
, region_size
;
1038 int led
= fdt_path_offset(initial_boot_params
, alias_prop
);
1040 base_ptr
= octeon_bootinfo
->led_display_base_addr
;
1043 /* Find CS0 region. */
1044 for (cs
= 0; cs
< 8; cs
++) {
1045 mio_boot_reg_cfg
.u64
= cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs
));
1046 region_base
= mio_boot_reg_cfg
.s
.base
<< 16;
1047 region_size
= (mio_boot_reg_cfg
.s
.size
+ 1) << 16;
1048 if (mio_boot_reg_cfg
.s
.en
&& base_ptr
>= region_base
1049 && base_ptr
< region_base
+ region_size
)
1056 new_reg
[0] = cpu_to_be32(cs
);
1057 new_reg
[1] = cpu_to_be32(0x20);
1058 new_reg
[2] = cpu_to_be32(0x20);
1059 new_reg
[3] = cpu_to_be32(cs
);
1060 new_reg
[4] = cpu_to_be32(0);
1061 new_reg
[5] = cpu_to_be32(0x20);
1062 fdt_setprop_inplace(initial_boot_params
, led
,
1063 "reg", new_reg
, sizeof(new_reg
));
1065 bootbus
= fdt_parent_offset(initial_boot_params
, led
);
1068 ranges
= fdt_getprop_w(initial_boot_params
, bootbus
, "ranges", &len
);
1069 if (!ranges
|| len
< (5 * 8 * sizeof(__be32
)))
1072 ranges
[(cs
* 5) + 2] = cpu_to_be32(region_base
>> 32);
1073 ranges
[(cs
* 5) + 3] = cpu_to_be32(region_base
& 0xffffffff);
1074 ranges
[(cs
* 5) + 4] = cpu_to_be32(region_size
);
1078 fdt_nop_node(initial_boot_params
, led
);
1085 alias_prop
= fdt_getprop(initial_boot_params
, aliases
,
1088 int uctl
= fdt_path_offset(initial_boot_params
, alias_prop
);
1090 if (uctl
>= 0 && (!OCTEON_IS_MODEL(OCTEON_CN6XXX
) ||
1091 octeon_bootinfo
->board_type
== CVMX_BOARD_TYPE_NIC2E
)) {
1092 pr_debug("Deleting uctl\n");
1093 fdt_nop_node(initial_boot_params
, uctl
);
1094 fdt_nop_property(initial_boot_params
, aliases
, "uctl");
1095 } else if (octeon_bootinfo
->board_type
== CVMX_BOARD_TYPE_NIC10E
||
1096 octeon_bootinfo
->board_type
== CVMX_BOARD_TYPE_NIC4E
) {
1097 /* Missing "refclk-type" defaults to crystal. */
1098 fdt_nop_property(initial_boot_params
, uctl
, "refclk-type");
1103 alias_prop
= fdt_getprop(initial_boot_params
, aliases
,
1106 int usbn
= fdt_path_offset(initial_boot_params
, alias_prop
);
1108 if (usbn
>= 0 && (current_cpu_type() == CPU_CAVIUM_OCTEON2
||
1109 !octeon_has_feature(OCTEON_FEATURE_USB
))) {
1110 pr_debug("Deleting usbn\n");
1111 fdt_nop_node(initial_boot_params
, usbn
);
1112 fdt_nop_property(initial_boot_params
, aliases
, "usbn");
1115 enum cvmx_helper_board_usb_clock_types c
;
1117 c
= __cvmx_helper_board_usb_get_clock_type();
1119 case USB_CLOCK_TYPE_REF_48
:
1120 new_f
[0] = cpu_to_be32(48000000);
1121 fdt_setprop_inplace(initial_boot_params
, usbn
,
1122 "refclk-frequency", new_f
, sizeof(new_f
));
1124 case USB_CLOCK_TYPE_REF_12
:
1125 /* Missing "refclk-type" defaults to external. */
1126 fdt_nop_property(initial_boot_params
, usbn
, "refclk-type");
1138 static int __init
octeon_publish_devices(void)
1140 return of_platform_populate(NULL
, octeon_ids
, NULL
, NULL
);
1142 arch_initcall(octeon_publish_devices
);