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-2011 Cavium Networks
7 * Copyright (C) 2008 Wind River Systems
10 #include <linux/delay.h>
11 #include <linux/init.h>
12 #include <linux/irq.h>
13 #include <linux/i2c.h>
14 #include <linux/usb.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/module.h>
17 #include <linux/mutex.h>
18 #include <linux/slab.h>
19 #include <linux/platform_device.h>
20 #include <linux/of_platform.h>
21 #include <linux/of_fdt.h>
22 #include <linux/libfdt.h>
23 #include <linux/usb/ehci_pdriver.h>
24 #include <linux/usb/ohci_pdriver.h>
26 #include <asm/octeon/octeon.h>
27 #include <asm/octeon/cvmx-rnm-defs.h>
28 #include <asm/octeon/cvmx-helper.h>
29 #include <asm/octeon/cvmx-helper-board.h>
30 #include <asm/octeon/cvmx-uctlx-defs.h>
32 /* Octeon Random Number Generator. */
33 static int __init octeon_rng_device_init(void)
35 struct platform_device *pd;
38 struct resource rng_resources[] = {
40 .flags = IORESOURCE_MEM,
41 .start = XKPHYS_TO_PHYS(CVMX_RNM_CTL_STATUS),
42 .end = XKPHYS_TO_PHYS(CVMX_RNM_CTL_STATUS) + 0xf
44 .flags = IORESOURCE_MEM,
45 .start = cvmx_build_io_address(8, 0),
46 .end = cvmx_build_io_address(8, 0) + 0x7
50 pd = platform_device_alloc("octeon_rng", -1);
56 ret = platform_device_add_resources(pd, rng_resources,
57 ARRAY_SIZE(rng_resources));
61 ret = platform_device_add(pd);
67 platform_device_put(pd);
72 device_initcall(octeon_rng_device_init);
76 static DEFINE_MUTEX(octeon2_usb_clocks_mutex);
78 static int octeon2_usb_clock_start_cnt;
80 static void octeon2_usb_clocks_start(void)
83 union cvmx_uctlx_if_ena if_ena;
84 union cvmx_uctlx_clk_rst_ctl clk_rst_ctl;
85 union cvmx_uctlx_uphy_ctl_status uphy_ctl_status;
86 union cvmx_uctlx_uphy_portx_ctl_status port_ctl_status;
88 unsigned long io_clk_64_to_ns;
91 mutex_lock(&octeon2_usb_clocks_mutex);
93 octeon2_usb_clock_start_cnt++;
94 if (octeon2_usb_clock_start_cnt != 1)
97 io_clk_64_to_ns = 64000000000ull / octeon_get_io_clock_rate();
100 * Step 1: Wait for voltages stable. That surely happened
101 * before starting the kernel.
103 * Step 2: Enable SCLK of UCTL by writing UCTL0_IF_ENA[EN] = 1
107 cvmx_write_csr(CVMX_UCTLX_IF_ENA(0), if_ena.u64);
109 /* Step 3: Configure the reference clock, PHY, and HCLK */
110 clk_rst_ctl.u64 = cvmx_read_csr(CVMX_UCTLX_CLK_RST_CTL(0));
113 * If the UCTL looks like it has already been started, skip
114 * the initialization, otherwise bus errors are obtained.
116 if (clk_rst_ctl.s.hrst)
119 clk_rst_ctl.s.p_por = 1;
120 clk_rst_ctl.s.hrst = 0;
121 clk_rst_ctl.s.p_prst = 0;
122 clk_rst_ctl.s.h_clkdiv_rst = 0;
123 clk_rst_ctl.s.o_clkdiv_rst = 0;
124 clk_rst_ctl.s.h_clkdiv_en = 0;
125 clk_rst_ctl.s.o_clkdiv_en = 0;
126 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
130 clk_rst_ctl.s.p_refclk_sel = 0;
131 clk_rst_ctl.s.p_refclk_div = 0;
132 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
135 div = octeon_get_io_clock_rate() / 130000000ull;
163 clk_rst_ctl.s.h_div = div;
164 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
166 clk_rst_ctl.u64 = cvmx_read_csr(CVMX_UCTLX_CLK_RST_CTL(0));
167 clk_rst_ctl.s.h_clkdiv_en = 1;
168 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
170 clk_rst_ctl.s.h_clkdiv_rst = 1;
171 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
173 /* 3e: delay 64 io clocks */
174 ndelay(io_clk_64_to_ns);
177 * Step 4: Program the power-on reset field in the UCTL
178 * clock-reset-control register.
180 clk_rst_ctl.s.p_por = 0;
181 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
183 /* Step 5: Wait 1 ms for the PHY clock to start. */
187 * Step 6: Program the reset input from automatic test
188 * equipment field in the UPHY CSR
190 uphy_ctl_status.u64 = cvmx_read_csr(CVMX_UCTLX_UPHY_CTL_STATUS(0));
191 uphy_ctl_status.s.ate_reset = 1;
192 cvmx_write_csr(CVMX_UCTLX_UPHY_CTL_STATUS(0), uphy_ctl_status.u64);
194 /* Step 7: Wait for at least 10ns. */
197 /* Step 8: Clear the ATE_RESET field in the UPHY CSR. */
198 uphy_ctl_status.s.ate_reset = 0;
199 cvmx_write_csr(CVMX_UCTLX_UPHY_CTL_STATUS(0), uphy_ctl_status.u64);
202 * Step 9: Wait for at least 20ns for UPHY to output PHY clock
203 * signals and OHCI_CLK48
207 /* Step 10: Configure the OHCI_CLK48 and OHCI_CLK12 clocks. */
209 clk_rst_ctl.s.o_clkdiv_rst = 1;
210 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
213 clk_rst_ctl.s.o_clkdiv_en = 1;
214 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
217 ndelay(io_clk_64_to_ns);
220 * Step 11: Program the PHY reset field:
221 * UCTL0_CLK_RST_CTL[P_PRST] = 1
223 clk_rst_ctl.s.p_prst = 1;
224 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
226 /* Step 12: Wait 1 uS. */
229 /* Step 13: Program the HRESET_N field: UCTL0_CLK_RST_CTL[HRST] = 1 */
230 clk_rst_ctl.s.hrst = 1;
231 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
234 /* Now we can set some other registers. */
236 for (i = 0; i <= 1; i++) {
237 port_ctl_status.u64 =
238 cvmx_read_csr(CVMX_UCTLX_UPHY_PORTX_CTL_STATUS(i, 0));
239 /* Set txvreftune to 15 to obtain compliant 'eye' diagram. */
240 port_ctl_status.s.txvreftune = 15;
241 port_ctl_status.s.txrisetune = 1;
242 port_ctl_status.s.txpreemphasistune = 1;
243 cvmx_write_csr(CVMX_UCTLX_UPHY_PORTX_CTL_STATUS(i, 0),
244 port_ctl_status.u64);
247 /* Set uSOF cycle period to 60,000 bits. */
248 cvmx_write_csr(CVMX_UCTLX_EHCI_FLA(0), 0x20ull);
250 mutex_unlock(&octeon2_usb_clocks_mutex);
253 static void octeon2_usb_clocks_stop(void)
255 mutex_lock(&octeon2_usb_clocks_mutex);
256 octeon2_usb_clock_start_cnt--;
257 mutex_unlock(&octeon2_usb_clocks_mutex);
260 static int octeon_ehci_power_on(struct platform_device *pdev)
262 octeon2_usb_clocks_start();
266 static void octeon_ehci_power_off(struct platform_device *pdev)
268 octeon2_usb_clocks_stop();
271 static struct usb_ehci_pdata octeon_ehci_pdata = {
272 /* Octeon EHCI matches CPU endianness. */
274 .big_endian_mmio = 1,
276 .power_on = octeon_ehci_power_on,
277 .power_off = octeon_ehci_power_off,
280 static void __init octeon_ehci_hw_start(void)
282 union cvmx_uctlx_ehci_ctl ehci_ctl;
284 octeon2_usb_clocks_start();
286 ehci_ctl.u64 = cvmx_read_csr(CVMX_UCTLX_EHCI_CTL(0));
287 /* Use 64-bit addressing. */
288 ehci_ctl.s.ehci_64b_addr_en = 1;
289 ehci_ctl.s.l2c_addr_msb = 0;
290 ehci_ctl.s.l2c_buff_emod = 1; /* Byte swapped. */
291 ehci_ctl.s.l2c_desc_emod = 1; /* Byte swapped. */
292 cvmx_write_csr(CVMX_UCTLX_EHCI_CTL(0), ehci_ctl.u64);
294 octeon2_usb_clocks_stop();
297 static u64 octeon_ehci_dma_mask = DMA_BIT_MASK(64);
299 static int __init octeon_ehci_device_init(void)
301 struct platform_device *pd;
304 struct resource usb_resources[] = {
306 .flags = IORESOURCE_MEM,
308 .flags = IORESOURCE_IRQ,
312 /* Only Octeon2 has ehci/ohci */
313 if (!OCTEON_IS_MODEL(OCTEON_CN63XX))
316 if (octeon_is_simulation() || usb_disabled())
317 return 0; /* No USB in the simulator. */
319 pd = platform_device_alloc("ehci-platform", 0);
325 usb_resources[0].start = 0x00016F0000000000ULL;
326 usb_resources[0].end = usb_resources[0].start + 0x100;
328 usb_resources[1].start = OCTEON_IRQ_USB0;
329 usb_resources[1].end = OCTEON_IRQ_USB0;
331 ret = platform_device_add_resources(pd, usb_resources,
332 ARRAY_SIZE(usb_resources));
336 pd->dev.dma_mask = &octeon_ehci_dma_mask;
337 pd->dev.platform_data = &octeon_ehci_pdata;
338 octeon_ehci_hw_start();
340 ret = platform_device_add(pd);
346 platform_device_put(pd);
350 device_initcall(octeon_ehci_device_init);
352 static int octeon_ohci_power_on(struct platform_device *pdev)
354 octeon2_usb_clocks_start();
358 static void octeon_ohci_power_off(struct platform_device *pdev)
360 octeon2_usb_clocks_stop();
363 static struct usb_ohci_pdata octeon_ohci_pdata = {
364 /* Octeon OHCI matches CPU endianness. */
366 .big_endian_mmio = 1,
368 .power_on = octeon_ohci_power_on,
369 .power_off = octeon_ohci_power_off,
372 static void __init octeon_ohci_hw_start(void)
374 union cvmx_uctlx_ohci_ctl ohci_ctl;
376 octeon2_usb_clocks_start();
378 ohci_ctl.u64 = cvmx_read_csr(CVMX_UCTLX_OHCI_CTL(0));
379 ohci_ctl.s.l2c_addr_msb = 0;
380 ohci_ctl.s.l2c_buff_emod = 1; /* Byte swapped. */
381 ohci_ctl.s.l2c_desc_emod = 1; /* Byte swapped. */
382 cvmx_write_csr(CVMX_UCTLX_OHCI_CTL(0), ohci_ctl.u64);
384 octeon2_usb_clocks_stop();
387 static int __init octeon_ohci_device_init(void)
389 struct platform_device *pd;
392 struct resource usb_resources[] = {
394 .flags = IORESOURCE_MEM,
396 .flags = IORESOURCE_IRQ,
400 /* Only Octeon2 has ehci/ohci */
401 if (!OCTEON_IS_MODEL(OCTEON_CN63XX))
404 if (octeon_is_simulation() || usb_disabled())
405 return 0; /* No USB in the simulator. */
407 pd = platform_device_alloc("ohci-platform", 0);
413 usb_resources[0].start = 0x00016F0000000400ULL;
414 usb_resources[0].end = usb_resources[0].start + 0x100;
416 usb_resources[1].start = OCTEON_IRQ_USB0;
417 usb_resources[1].end = OCTEON_IRQ_USB0;
419 ret = platform_device_add_resources(pd, usb_resources,
420 ARRAY_SIZE(usb_resources));
424 pd->dev.platform_data = &octeon_ohci_pdata;
425 octeon_ohci_hw_start();
427 ret = platform_device_add(pd);
433 platform_device_put(pd);
437 device_initcall(octeon_ohci_device_init);
439 #endif /* CONFIG_USB */
441 static struct of_device_id __initdata octeon_ids[] = {
442 { .compatible = "simple-bus", },
443 { .compatible = "cavium,octeon-6335-uctl", },
444 { .compatible = "cavium,octeon-5750-usbn", },
445 { .compatible = "cavium,octeon-3860-bootbus", },
446 { .compatible = "cavium,mdio-mux", },
447 { .compatible = "gpio-leds", },
451 static bool __init octeon_has_88e1145(void)
453 return !OCTEON_IS_MODEL(OCTEON_CN52XX) &&
454 !OCTEON_IS_MODEL(OCTEON_CN6XXX) &&
455 !OCTEON_IS_MODEL(OCTEON_CN56XX);
458 static void __init octeon_fdt_set_phy(int eth, int phy_addr)
460 const __be32 *phy_handle;
461 const __be32 *alt_phy_handle;
470 phy_handle = fdt_getprop(initial_boot_params, eth, "phy-handle", NULL);
474 phandle = be32_to_cpup(phy_handle);
475 phy = fdt_node_offset_by_phandle(initial_boot_params, phandle);
477 alt_phy_handle = fdt_getprop(initial_boot_params, eth, "cavium,alt-phy-handle", NULL);
478 if (alt_phy_handle) {
479 u32 alt_phandle = be32_to_cpup(alt_phy_handle);
480 alt_phy = fdt_node_offset_by_phandle(initial_boot_params, alt_phandle);
485 if (phy_addr < 0 || phy < 0) {
486 /* Delete the PHY things */
487 fdt_nop_property(initial_boot_params, eth, "phy-handle");
488 /* This one may fail */
489 fdt_nop_property(initial_boot_params, eth, "cavium,alt-phy-handle");
491 fdt_nop_node(initial_boot_params, phy);
493 fdt_nop_node(initial_boot_params, alt_phy);
497 if (phy_addr >= 256 && alt_phy > 0) {
498 const struct fdt_property *phy_prop;
499 struct fdt_property *alt_prop;
502 /* Use the alt phy node instead.*/
503 phy_prop = fdt_get_property(initial_boot_params, eth, "phy-handle", NULL);
504 phy_handle_name = phy_prop->nameoff;
505 fdt_nop_node(initial_boot_params, phy);
506 fdt_nop_property(initial_boot_params, eth, "phy-handle");
507 alt_prop = fdt_get_property_w(initial_boot_params, eth, "cavium,alt-phy-handle", NULL);
508 alt_prop->nameoff = phy_handle_name;
514 if (octeon_has_88e1145()) {
515 fdt_nop_property(initial_boot_params, phy, "marvell,reg-init");
516 memset(new_name, 0, sizeof(new_name));
517 strcpy(new_name, "marvell,88e1145");
518 p = fdt_getprop(initial_boot_params, phy, "compatible",
520 if (p && current_len >= strlen(new_name))
521 fdt_setprop_inplace(initial_boot_params, phy,
522 "compatible", new_name, current_len);
525 reg = fdt_getprop(initial_boot_params, phy, "reg", NULL);
526 if (phy_addr == be32_to_cpup(reg))
529 fdt_setprop_inplace_cell(initial_boot_params, phy, "reg", phy_addr);
531 snprintf(new_name, sizeof(new_name), "ethernet-phy@%x", phy_addr);
533 p = fdt_get_name(initial_boot_params, phy, ¤t_len);
534 if (p && current_len == strlen(new_name))
535 fdt_set_name(initial_boot_params, phy, new_name);
537 pr_err("Error: could not rename ethernet phy: <%s>", p);
540 static void __init octeon_fdt_set_mac_addr(int n, u64 *pmac)
546 new_mac[0] = (mac >> 40) & 0xff;
547 new_mac[1] = (mac >> 32) & 0xff;
548 new_mac[2] = (mac >> 24) & 0xff;
549 new_mac[3] = (mac >> 16) & 0xff;
550 new_mac[4] = (mac >> 8) & 0xff;
551 new_mac[5] = mac & 0xff;
553 r = fdt_setprop_inplace(initial_boot_params, n, "local-mac-address",
554 new_mac, sizeof(new_mac));
557 pr_err("Setting \"local-mac-address\" failed %d", r);
563 static void __init octeon_fdt_rm_ethernet(int node)
565 const __be32 *phy_handle;
567 phy_handle = fdt_getprop(initial_boot_params, node, "phy-handle", NULL);
569 u32 ph = be32_to_cpup(phy_handle);
570 int p = fdt_node_offset_by_phandle(initial_boot_params, ph);
572 fdt_nop_node(initial_boot_params, p);
574 fdt_nop_node(initial_boot_params, node);
577 static void __init octeon_fdt_pip_port(int iface, int i, int p, int max, u64 *pmac)
579 char name_buffer[20];
584 snprintf(name_buffer, sizeof(name_buffer), "ethernet@%x", p);
585 eth = fdt_subnode_offset(initial_boot_params, iface, name_buffer);
589 pr_debug("Deleting port %x:%x\n", i, p);
590 octeon_fdt_rm_ethernet(eth);
593 if (OCTEON_IS_MODEL(OCTEON_CN68XX))
594 ipd_port = (0x100 * i) + (0x10 * p) + 0x800;
596 ipd_port = 16 * i + p;
598 phy_addr = cvmx_helper_board_get_mii_address(ipd_port);
599 octeon_fdt_set_phy(eth, phy_addr);
600 octeon_fdt_set_mac_addr(eth, pmac);
603 static void __init octeon_fdt_pip_iface(int pip, int idx, u64 *pmac)
605 char name_buffer[20];
610 snprintf(name_buffer, sizeof(name_buffer), "interface@%d", idx);
611 iface = fdt_subnode_offset(initial_boot_params, pip, name_buffer);
615 if (cvmx_helper_interface_enumerate(idx) == 0)
616 count = cvmx_helper_ports_on_interface(idx);
618 for (p = 0; p < 16; p++)
619 octeon_fdt_pip_port(iface, idx, p, count - 1, pmac);
622 int __init octeon_prune_device_tree(void)
624 int i, max_port, uart_mask;
625 const char *pip_path;
626 const char *alias_prop;
627 char name_buffer[20];
631 if (fdt_check_header(initial_boot_params))
632 panic("Corrupt Device Tree.");
634 aliases = fdt_path_offset(initial_boot_params, "/aliases");
636 pr_err("Error: No /aliases node in device tree.");
642 ((octeon_bootinfo->mac_addr_base[0] & 0xffull)) << 40 |
643 ((octeon_bootinfo->mac_addr_base[1] & 0xffull)) << 32 |
644 ((octeon_bootinfo->mac_addr_base[2] & 0xffull)) << 24 |
645 ((octeon_bootinfo->mac_addr_base[3] & 0xffull)) << 16 |
646 ((octeon_bootinfo->mac_addr_base[4] & 0xffull)) << 8 |
647 (octeon_bootinfo->mac_addr_base[5] & 0xffull);
649 if (OCTEON_IS_MODEL(OCTEON_CN52XX) || OCTEON_IS_MODEL(OCTEON_CN63XX))
651 else if (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN68XX))
656 if (octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC10E)
659 for (i = 0; i < 2; i++) {
661 snprintf(name_buffer, sizeof(name_buffer),
663 alias_prop = fdt_getprop(initial_boot_params, aliases,
666 mgmt = fdt_path_offset(initial_boot_params, alias_prop);
670 pr_debug("Deleting mix%d\n", i);
671 octeon_fdt_rm_ethernet(mgmt);
672 fdt_nop_property(initial_boot_params, aliases,
675 int phy_addr = cvmx_helper_board_get_mii_address(CVMX_HELPER_BOARD_MGMT_IPD_PORT + i);
676 octeon_fdt_set_phy(mgmt, phy_addr);
677 octeon_fdt_set_mac_addr(mgmt, &mac_addr_base);
682 pip_path = fdt_getprop(initial_boot_params, aliases, "pip", NULL);
684 int pip = fdt_path_offset(initial_boot_params, pip_path);
686 for (i = 0; i <= 4; i++)
687 octeon_fdt_pip_iface(pip, i, &mac_addr_base);
691 if (OCTEON_IS_MODEL(OCTEON_CN52XX) ||
692 OCTEON_IS_MODEL(OCTEON_CN63XX) ||
693 OCTEON_IS_MODEL(OCTEON_CN68XX) ||
694 OCTEON_IS_MODEL(OCTEON_CN56XX))
699 for (i = 0; i < 2; i++) {
701 snprintf(name_buffer, sizeof(name_buffer),
703 alias_prop = fdt_getprop(initial_boot_params, aliases,
707 i2c = fdt_path_offset(initial_boot_params, alias_prop);
711 pr_debug("Deleting twsi%d\n", i);
712 fdt_nop_node(initial_boot_params, i2c);
713 fdt_nop_property(initial_boot_params, aliases,
720 if (OCTEON_IS_MODEL(OCTEON_CN68XX))
722 else if (OCTEON_IS_MODEL(OCTEON_CN52XX) ||
723 OCTEON_IS_MODEL(OCTEON_CN63XX) ||
724 OCTEON_IS_MODEL(OCTEON_CN56XX))
729 for (i = 0; i < 2; i++) {
731 snprintf(name_buffer, sizeof(name_buffer),
733 alias_prop = fdt_getprop(initial_boot_params, aliases,
737 i2c = fdt_path_offset(initial_boot_params, alias_prop);
741 pr_debug("Deleting smi%d\n", i);
742 fdt_nop_node(initial_boot_params, i2c);
743 fdt_nop_property(initial_boot_params, aliases,
752 /* Right now CN52XX is the only chip with a third uart */
753 if (OCTEON_IS_MODEL(OCTEON_CN52XX))
754 uart_mask |= 4; /* uart2 */
756 for (i = 0; i < 3; i++) {
758 snprintf(name_buffer, sizeof(name_buffer),
760 alias_prop = fdt_getprop(initial_boot_params, aliases,
764 uart = fdt_path_offset(initial_boot_params, alias_prop);
765 if (uart_mask & (1 << i)) {
768 f = cpu_to_be32(octeon_get_io_clock_rate());
769 fdt_setprop_inplace(initial_boot_params,
770 uart, "clock-frequency",
774 pr_debug("Deleting uart%d\n", i);
775 fdt_nop_node(initial_boot_params, uart);
776 fdt_nop_property(initial_boot_params, aliases,
782 alias_prop = fdt_getprop(initial_boot_params, aliases,
785 union cvmx_mio_boot_reg_cfgx mio_boot_reg_cfg;
786 unsigned long base_ptr, region_base, region_size;
787 unsigned long region1_base = 0;
788 unsigned long region1_size = 0;
790 bool is_16bit = false;
791 bool is_true_ide = false;
796 int cf = fdt_path_offset(initial_boot_params, alias_prop);
798 if (octeon_bootinfo->major_version == 1
799 && octeon_bootinfo->minor_version >= 1) {
800 if (octeon_bootinfo->compact_flash_common_base_addr)
801 base_ptr = octeon_bootinfo->compact_flash_common_base_addr;
803 base_ptr = 0x1d000800;
809 /* Find CS0 region. */
810 for (cs = 0; cs < 8; cs++) {
811 mio_boot_reg_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs));
812 region_base = mio_boot_reg_cfg.s.base << 16;
813 region_size = (mio_boot_reg_cfg.s.size + 1) << 16;
814 if (mio_boot_reg_cfg.s.en && base_ptr >= region_base
815 && base_ptr < region_base + region_size) {
816 is_16bit = mio_boot_reg_cfg.s.width;
821 /* cs and cs + 1 are CS0 and CS1, both must be less than 8. */
825 if (!(base_ptr & 0xfffful)) {
827 * Boot loader signals availability of DMA (true_ide
828 * mode) by setting low order bits of base_ptr to
832 /* Asume that CS1 immediately follows. */
833 mio_boot_reg_cfg.u64 =
834 cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs + 1));
835 region1_base = mio_boot_reg_cfg.s.base << 16;
836 region1_size = (mio_boot_reg_cfg.s.size + 1) << 16;
837 if (!mio_boot_reg_cfg.s.en)
842 fdt_nop_property(initial_boot_params, cf, "cavium,true-ide");
843 fdt_nop_property(initial_boot_params, cf, "cavium,dma-engine-handle");
845 __be32 width = cpu_to_be32(8);
846 fdt_setprop_inplace(initial_boot_params, cf,
847 "cavium,bus-width", &width, sizeof(width));
850 new_reg[0] = cpu_to_be32(cs);
851 new_reg[1] = cpu_to_be32(0);
852 new_reg[2] = cpu_to_be32(0x10000);
853 new_reg[3] = cpu_to_be32(cs + 1);
854 new_reg[4] = cpu_to_be32(0);
855 new_reg[5] = cpu_to_be32(0x10000);
856 fdt_setprop_inplace(initial_boot_params, cf,
857 "reg", new_reg, sizeof(new_reg));
859 bootbus = fdt_parent_offset(initial_boot_params, cf);
862 ranges = fdt_getprop_w(initial_boot_params, bootbus, "ranges", &len);
863 if (!ranges || len < (5 * 8 * sizeof(__be32)))
866 ranges[(cs * 5) + 2] = cpu_to_be32(region_base >> 32);
867 ranges[(cs * 5) + 3] = cpu_to_be32(region_base & 0xffffffff);
868 ranges[(cs * 5) + 4] = cpu_to_be32(region_size);
871 ranges[(cs * 5) + 2] = cpu_to_be32(region1_base >> 32);
872 ranges[(cs * 5) + 3] = cpu_to_be32(region1_base & 0xffffffff);
873 ranges[(cs * 5) + 4] = cpu_to_be32(region1_size);
877 fdt_nop_node(initial_boot_params, cf);
884 alias_prop = fdt_getprop(initial_boot_params, aliases,
887 union cvmx_mio_boot_reg_cfgx mio_boot_reg_cfg;
888 unsigned long base_ptr, region_base, region_size;
893 int led = fdt_path_offset(initial_boot_params, alias_prop);
895 base_ptr = octeon_bootinfo->led_display_base_addr;
898 /* Find CS0 region. */
899 for (cs = 0; cs < 8; cs++) {
900 mio_boot_reg_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs));
901 region_base = mio_boot_reg_cfg.s.base << 16;
902 region_size = (mio_boot_reg_cfg.s.size + 1) << 16;
903 if (mio_boot_reg_cfg.s.en && base_ptr >= region_base
904 && base_ptr < region_base + region_size)
911 new_reg[0] = cpu_to_be32(cs);
912 new_reg[1] = cpu_to_be32(0x20);
913 new_reg[2] = cpu_to_be32(0x20);
914 new_reg[3] = cpu_to_be32(cs);
915 new_reg[4] = cpu_to_be32(0);
916 new_reg[5] = cpu_to_be32(0x20);
917 fdt_setprop_inplace(initial_boot_params, led,
918 "reg", new_reg, sizeof(new_reg));
920 bootbus = fdt_parent_offset(initial_boot_params, led);
923 ranges = fdt_getprop_w(initial_boot_params, bootbus, "ranges", &len);
924 if (!ranges || len < (5 * 8 * sizeof(__be32)))
927 ranges[(cs * 5) + 2] = cpu_to_be32(region_base >> 32);
928 ranges[(cs * 5) + 3] = cpu_to_be32(region_base & 0xffffffff);
929 ranges[(cs * 5) + 4] = cpu_to_be32(region_size);
933 fdt_nop_node(initial_boot_params, led);
939 alias_prop = fdt_getprop(initial_boot_params, aliases,
942 int uctl = fdt_path_offset(initial_boot_params, alias_prop);
944 if (uctl >= 0 && (!OCTEON_IS_MODEL(OCTEON_CN6XXX) ||
945 octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC2E)) {
946 pr_debug("Deleting uctl\n");
947 fdt_nop_node(initial_boot_params, uctl);
948 fdt_nop_property(initial_boot_params, aliases, "uctl");
949 } else if (octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC10E ||
950 octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC4E) {
951 /* Missing "refclk-type" defaults to crystal. */
952 fdt_nop_property(initial_boot_params, uctl, "refclk-type");
957 alias_prop = fdt_getprop(initial_boot_params, aliases,
960 int usbn = fdt_path_offset(initial_boot_params, alias_prop);
962 if (usbn >= 0 && (current_cpu_type() == CPU_CAVIUM_OCTEON2 ||
963 !octeon_has_feature(OCTEON_FEATURE_USB))) {
964 pr_debug("Deleting usbn\n");
965 fdt_nop_node(initial_boot_params, usbn);
966 fdt_nop_property(initial_boot_params, aliases, "usbn");
969 enum cvmx_helper_board_usb_clock_types c;
970 c = __cvmx_helper_board_usb_get_clock_type();
972 case USB_CLOCK_TYPE_REF_48:
973 new_f[0] = cpu_to_be32(48000000);
974 fdt_setprop_inplace(initial_boot_params, usbn,
975 "refclk-frequency", new_f, sizeof(new_f));
976 /* Fall through ...*/
977 case USB_CLOCK_TYPE_REF_12:
978 /* Missing "refclk-type" defaults to external. */
979 fdt_nop_property(initial_boot_params, usbn, "refclk-type");
990 static int __init octeon_publish_devices(void)
992 return of_platform_bus_probe(NULL, octeon_ids, NULL);
994 device_initcall(octeon_publish_devices);
996 MODULE_AUTHOR("David Daney <ddaney@caviumnetworks.com>");
997 MODULE_LICENSE("GPL");
998 MODULE_DESCRIPTION("Platform driver for Octeon SOC");