2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-01-28 10:00:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015
|
|
|
|
* Purna Chandra Mandal <purna.mandal@microchip.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
2016-01-28 10:00:16 +00:00
|
|
|
#include <clk.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <mach/pic32.h>
|
|
|
|
#include <mach/ddr.h>
|
|
|
|
#include <dt-bindings/clock/microchip,clock.h>
|
2016-01-28 10:00:10 +00:00
|
|
|
|
2016-01-28 10:00:16 +00:00
|
|
|
/* Flash prefetch */
|
|
|
|
#define PRECON 0x00
|
|
|
|
|
|
|
|
/* Flash ECCCON */
|
|
|
|
#define ECC_MASK 0x03
|
|
|
|
#define ECC_SHIFT 4
|
|
|
|
|
|
|
|
#define CLK_MHZ(x) ((x) / 1000000)
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2016-06-17 15:44:00 +00:00
|
|
|
static ulong rate(int id)
|
2016-01-28 10:00:16 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct udevice *dev;
|
2016-06-17 15:44:00 +00:00
|
|
|
struct clk clk;
|
|
|
|
ulong rate;
|
2016-01-28 10:00:16 +00:00
|
|
|
|
|
|
|
ret = uclass_get_device(UCLASS_CLK, 0, &dev);
|
|
|
|
if (ret) {
|
2016-06-17 15:44:00 +00:00
|
|
|
printf("clk-uclass not found\n");
|
2016-01-28 10:00:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-17 15:44:00 +00:00
|
|
|
clk.id = id;
|
|
|
|
ret = clk_request(dev, &clk);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
rate = clk_get_rate(&clk);
|
|
|
|
|
|
|
|
clk_free(&clk);
|
|
|
|
|
|
|
|
return rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ulong clk_get_cpu_rate(void)
|
|
|
|
{
|
|
|
|
return rate(PB7CLK);
|
2016-01-28 10:00:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize prefetch module related to cpu_clk */
|
|
|
|
static void prefetch_init(void)
|
|
|
|
{
|
|
|
|
struct pic32_reg_atomic *regs;
|
|
|
|
const void __iomem *base;
|
|
|
|
int v, nr_waits;
|
|
|
|
ulong rate;
|
|
|
|
|
|
|
|
/* cpu frequency in MHZ */
|
|
|
|
rate = clk_get_cpu_rate() / 1000000;
|
|
|
|
|
|
|
|
/* get flash ECC type */
|
|
|
|
base = pic32_get_syscfg_base();
|
|
|
|
v = (readl(base + CFGCON) >> ECC_SHIFT) & ECC_MASK;
|
|
|
|
|
|
|
|
if (v < 2) {
|
|
|
|
if (rate < 66)
|
|
|
|
nr_waits = 0;
|
|
|
|
else if (rate < 133)
|
|
|
|
nr_waits = 1;
|
|
|
|
else
|
|
|
|
nr_waits = 2;
|
|
|
|
} else {
|
|
|
|
if (rate <= 83)
|
|
|
|
nr_waits = 0;
|
|
|
|
else if (rate <= 166)
|
|
|
|
nr_waits = 1;
|
|
|
|
else
|
|
|
|
nr_waits = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
regs = ioremap(PREFETCH_BASE + PRECON, sizeof(*regs));
|
|
|
|
writel(nr_waits, ®s->raw);
|
|
|
|
|
|
|
|
/* Enable prefetch for all */
|
|
|
|
writel(0x30, ®s->set);
|
|
|
|
iounmap(regs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* arch specific CPU init after DM */
|
|
|
|
int arch_cpu_init_dm(void)
|
|
|
|
{
|
|
|
|
/* flash prefetch */
|
|
|
|
prefetch_init();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Un-gate DDR2 modules (gated by default) */
|
|
|
|
static void ddr2_pmd_ungate(void)
|
|
|
|
{
|
|
|
|
void __iomem *regs;
|
|
|
|
|
|
|
|
regs = pic32_get_syscfg_base();
|
|
|
|
writel(0, regs + PMD7);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize the DDR2 Controller and DDR2 PHY */
|
2017-04-06 18:47:05 +00:00
|
|
|
int dram_init(void)
|
2016-01-28 10:00:10 +00:00
|
|
|
{
|
2016-01-28 10:00:16 +00:00
|
|
|
ddr2_pmd_ungate();
|
|
|
|
ddr2_phy_init();
|
|
|
|
ddr2_ctrl_init();
|
2017-03-31 14:40:25 +00:00
|
|
|
gd->ram_size = ddr2_calculate_size();
|
|
|
|
|
|
|
|
return 0;
|
2016-01-28 10:00:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int misc_init_r(void)
|
|
|
|
{
|
|
|
|
set_io_port_base(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_DISPLAY_BOARDINFO
|
|
|
|
const char *get_core_name(void)
|
|
|
|
{
|
|
|
|
u32 proc_id;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
proc_id = read_c0_prid();
|
|
|
|
switch (proc_id) {
|
|
|
|
case 0x19e28:
|
|
|
|
str = "PIC32MZ[DA]";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "UNKNOWN";
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_CMD_CLK
|
2016-06-17 15:44:00 +00:00
|
|
|
|
2016-01-28 10:00:16 +00:00
|
|
|
int soc_clk_dump(void)
|
|
|
|
{
|
2016-06-17 15:44:00 +00:00
|
|
|
int i;
|
2016-01-28 10:00:16 +00:00
|
|
|
|
|
|
|
printf("PLL Speed: %lu MHz\n",
|
2016-06-17 15:44:00 +00:00
|
|
|
CLK_MHZ(rate(PLLCLK)));
|
|
|
|
|
|
|
|
printf("CPU Speed: %lu MHz\n", CLK_MHZ(rate(PB7CLK)));
|
|
|
|
|
|
|
|
printf("MPLL Speed: %lu MHz\n", CLK_MHZ(rate(MPLL)));
|
2016-01-28 10:00:16 +00:00
|
|
|
|
|
|
|
for (i = PB1CLK; i <= PB7CLK; i++)
|
|
|
|
printf("PB%d Clock Speed: %lu MHz\n", i - PB1CLK + 1,
|
2016-06-17 15:44:00 +00:00
|
|
|
CLK_MHZ(rate(i)));
|
2016-01-28 10:00:16 +00:00
|
|
|
|
|
|
|
for (i = REF1CLK; i <= REF5CLK; i++)
|
|
|
|
printf("REFO%d Clock Speed: %lu MHz\n", i - REF1CLK + 1,
|
2016-06-17 15:44:00 +00:00
|
|
|
CLK_MHZ(rate(i)));
|
2016-01-28 10:00:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2016-01-28 10:00:16 +00:00
|
|
|
#endif
|