···44 * for more details.55 *66 * Copyright (C) 2007 by Ralf Baechle77- * Copyright (C) 2009, 2010 Cavium Networks, Inc.77+ * Copyright (C) 2009, 2012 Cavium, Inc.88 */99#include <linux/clocksource.h>1010#include <linux/export.h>···1818#include <asm/octeon/cvmx-ipd-defs.h>1919#include <asm/octeon/cvmx-mio-defs.h>20202121+2222+static u64 f;2323+static u64 rdiv;2424+static u64 sdiv;2525+static u64 octeon_udelay_factor;2626+static u64 octeon_ndelay_factor;2727+2828+void __init octeon_setup_delays(void)2929+{3030+ octeon_udelay_factor = octeon_get_clock_rate() / 1000000;3131+ /*3232+ * For __ndelay we divide by 2^16, so the factor is multiplied3333+ * by the same amount.3434+ */3535+ octeon_ndelay_factor = (octeon_udelay_factor * 0x10000ull) / 1000ull;3636+3737+ preset_lpj = octeon_get_clock_rate() / HZ;3838+3939+ if (current_cpu_type() == CPU_CAVIUM_OCTEON2) {4040+ union cvmx_mio_rst_boot rst_boot;4141+ rst_boot.u64 = cvmx_read_csr(CVMX_MIO_RST_BOOT);4242+ rdiv = rst_boot.s.c_mul; /* CPU clock */4343+ sdiv = rst_boot.s.pnr_mul; /* I/O clock */4444+ f = (0x8000000000000000ull / sdiv) * 2;4545+ }4646+}4747+2148/*2249 * Set the current core's cvmcount counter to the value of the2350 * IPD_CLK_COUNT. We do this on all cores as they are brought···5730{5831 unsigned long flags;5932 unsigned loops = 2;6060- u64 f = 0;6161- u64 rdiv = 0;6262- u64 sdiv = 0;6363- if (current_cpu_type() == CPU_CAVIUM_OCTEON2) {6464- union cvmx_mio_rst_boot rst_boot;6565- rst_boot.u64 = cvmx_read_csr(CVMX_MIO_RST_BOOT);6666- rdiv = rst_boot.s.c_mul; /* CPU clock */6767- sdiv = rst_boot.s.pnr_mul; /* I/O clock */6868- f = (0x8000000000000000ull / sdiv) * 2;6969- }7070-71337234 /* Clobber loops so GCC will not unroll the following while loop. */7335 asm("" : "+r" (loops));···7357 if (f != 0) {7458 asm("dmultu\t%[cnt],%[f]\n\t"7559 "mfhi\t%[cnt]"7676- : [cnt] "+r" (ipd_clk_count),7777- [f] "=r" (f)7878- : : "hi", "lo");6060+ : [cnt] "+r" (ipd_clk_count)6161+ : [f] "r" (f)6262+ : "hi", "lo");7963 }8064 }8165 write_c0_cvmcount(ipd_clk_count);···125109 clocksource_register_hz(&clocksource_mips, octeon_get_clock_rate());126110}127111128128-static u64 octeon_udelay_factor;129129-static u64 octeon_ndelay_factor;130130-131131-void __init octeon_setup_delays(void)132132-{133133- octeon_udelay_factor = octeon_get_clock_rate() / 1000000;134134- /*135135- * For __ndelay we divide by 2^16, so the factor is multiplied136136- * by the same amount.137137- */138138- octeon_ndelay_factor = (octeon_udelay_factor * 0x10000ull) / 1000ull;139139-140140- preset_lpj = octeon_get_clock_rate() / HZ;141141-}142142-143112void __udelay(unsigned long us)144113{145114 u64 cur, end, inc;···164163 cur = read_c0_cvmcount();165164}166165EXPORT_SYMBOL(__delay);166166+167167+168168+/**169169+ * octeon_io_clk_delay - wait for a given number of io clock cycles to pass.170170+ *171171+ * We scale the wait by the clock ratio, and then wait for the172172+ * corresponding number of core clocks.173173+ *174174+ * @count: The number of clocks to wait.175175+ */176176+void octeon_io_clk_delay(unsigned long count)177177+{178178+ u64 cur, end;179179+180180+ cur = read_c0_cvmcount();181181+ if (rdiv != 0) {182182+ end = count * rdiv;183183+ if (f != 0) {184184+ asm("dmultu\t%[cnt],%[f]\n\t"185185+ "mfhi\t%[cnt]"186186+ : [cnt] "+r" (end)187187+ : [f] "r" (f)188188+ : "hi", "lo");189189+ }190190+ end = cur + end;191191+ } else {192192+ end = cur + count;193193+ }194194+ while (end > cur)195195+ cur = read_c0_cvmcount();196196+}197197+EXPORT_SYMBOL(octeon_io_clk_delay);
+2-1
arch/mips/cavium-octeon/setup.c
···548548 }549549#endif550550551551+ octeon_setup_delays();552552+551553 /*552554 * BIST should always be enabled when doing a soft reset. L2553555 * Cache locking for instance is not cleared unless BIST is···613611 mips_hpt_frequency = octeon_get_clock_rate();614612615613 octeon_init_cvmcount();616616- octeon_setup_delays();617614618615 _machine_restart = octeon_restart;619616 _machine_halt = octeon_halt;