18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci#ifndef __ARCH_ARM_MACH_OMAP2_SDRC_H 38c2ecf20Sopenharmony_ci#define __ARCH_ARM_MACH_OMAP2_SDRC_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci/* 68c2ecf20Sopenharmony_ci * OMAP2/3 SDRC/SMS macros and prototypes 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Copyright (C) 2007-2008, 2012 Texas Instruments, Inc. 98c2ecf20Sopenharmony_ci * Copyright (C) 2007-2008 Nokia Corporation 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * Paul Walmsley 128c2ecf20Sopenharmony_ci * Tony Lindgren 138c2ecf20Sopenharmony_ci * Richard Woodruff 148c2ecf20Sopenharmony_ci */ 158c2ecf20Sopenharmony_ci#undef DEBUG 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#ifndef __ASSEMBLER__ 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#include <linux/io.h> 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ciextern void __iomem *omap2_sdrc_base; 228c2ecf20Sopenharmony_ciextern void __iomem *omap2_sms_base; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#define OMAP_SDRC_REGADDR(reg) (omap2_sdrc_base + (reg)) 258c2ecf20Sopenharmony_ci#define OMAP_SMS_REGADDR(reg) (omap2_sms_base + (reg)) 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci/* SDRC global register get/set */ 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistatic inline void sdrc_write_reg(u32 val, u16 reg) 308c2ecf20Sopenharmony_ci{ 318c2ecf20Sopenharmony_ci writel_relaxed(val, OMAP_SDRC_REGADDR(reg)); 328c2ecf20Sopenharmony_ci} 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cistatic inline u32 sdrc_read_reg(u16 reg) 358c2ecf20Sopenharmony_ci{ 368c2ecf20Sopenharmony_ci return readl_relaxed(OMAP_SDRC_REGADDR(reg)); 378c2ecf20Sopenharmony_ci} 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/* SMS global register get/set */ 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cistatic inline void sms_write_reg(u32 val, u16 reg) 428c2ecf20Sopenharmony_ci{ 438c2ecf20Sopenharmony_ci writel_relaxed(val, OMAP_SMS_REGADDR(reg)); 448c2ecf20Sopenharmony_ci} 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistatic inline u32 sms_read_reg(u16 reg) 478c2ecf20Sopenharmony_ci{ 488c2ecf20Sopenharmony_ci return readl_relaxed(OMAP_SMS_REGADDR(reg)); 498c2ecf20Sopenharmony_ci} 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ciextern void omap2_set_globals_sdrc(void __iomem *sdrc, void __iomem *sms); 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci/** 558c2ecf20Sopenharmony_ci * struct omap_sdrc_params - SDRC parameters for a given SDRC clock rate 568c2ecf20Sopenharmony_ci * @rate: SDRC clock rate (in Hz) 578c2ecf20Sopenharmony_ci * @actim_ctrla: Value to program to SDRC_ACTIM_CTRLA for this rate 588c2ecf20Sopenharmony_ci * @actim_ctrlb: Value to program to SDRC_ACTIM_CTRLB for this rate 598c2ecf20Sopenharmony_ci * @rfr_ctrl: Value to program to SDRC_RFR_CTRL for this rate 608c2ecf20Sopenharmony_ci * @mr: Value to program to SDRC_MR for this rate 618c2ecf20Sopenharmony_ci * 628c2ecf20Sopenharmony_ci * This structure holds a pre-computed set of register values for the 638c2ecf20Sopenharmony_ci * SDRC for a given SDRC clock rate and SDRAM chip. These are 648c2ecf20Sopenharmony_ci * intended to be pre-computed and specified in an array in the board-*.c 658c2ecf20Sopenharmony_ci * files. The structure is keyed off the 'rate' field. 668c2ecf20Sopenharmony_ci */ 678c2ecf20Sopenharmony_cistruct omap_sdrc_params { 688c2ecf20Sopenharmony_ci unsigned long rate; 698c2ecf20Sopenharmony_ci u32 actim_ctrla; 708c2ecf20Sopenharmony_ci u32 actim_ctrlb; 718c2ecf20Sopenharmony_ci u32 rfr_ctrl; 728c2ecf20Sopenharmony_ci u32 mr; 738c2ecf20Sopenharmony_ci}; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci#ifdef CONFIG_SOC_HAS_OMAP2_SDRC 768c2ecf20Sopenharmony_civoid omap2_sdrc_init(struct omap_sdrc_params *sdrc_cs0, 778c2ecf20Sopenharmony_ci struct omap_sdrc_params *sdrc_cs1); 788c2ecf20Sopenharmony_ci#else 798c2ecf20Sopenharmony_cistatic inline void __init omap2_sdrc_init(struct omap_sdrc_params *sdrc_cs0, 808c2ecf20Sopenharmony_ci struct omap_sdrc_params *sdrc_cs1) {}; 818c2ecf20Sopenharmony_ci#endif 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ciint omap2_sdrc_get_params(unsigned long r, 848c2ecf20Sopenharmony_ci struct omap_sdrc_params **sdrc_cs0, 858c2ecf20Sopenharmony_ci struct omap_sdrc_params **sdrc_cs1); 868c2ecf20Sopenharmony_civoid omap2_sms_save_context(void); 878c2ecf20Sopenharmony_civoid omap2_sms_restore_context(void); 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_cistruct memory_timings { 908c2ecf20Sopenharmony_ci u32 m_type; /* ddr = 1, sdr = 0 */ 918c2ecf20Sopenharmony_ci u32 dll_mode; /* use lock mode = 1, unlock mode = 0 */ 928c2ecf20Sopenharmony_ci u32 slow_dll_ctrl; /* unlock mode, dll value for slow speed */ 938c2ecf20Sopenharmony_ci u32 fast_dll_ctrl; /* unlock mode, dll value for fast speed */ 948c2ecf20Sopenharmony_ci u32 base_cs; /* base chip select to use for calculations */ 958c2ecf20Sopenharmony_ci}; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ciextern void omap2xxx_sdrc_init_params(u32 force_lock_to_unlock_mode); 988c2ecf20Sopenharmony_cistruct omap_sdrc_params *rx51_get_sdram_timings(void); 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ciu32 omap2xxx_sdrc_dll_is_unlocked(void); 1018c2ecf20Sopenharmony_ciu32 omap2xxx_sdrc_reprogram(u32 level, u32 force); 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci#else 1058c2ecf20Sopenharmony_ci#define OMAP242X_SDRC_REGADDR(reg) \ 1068c2ecf20Sopenharmony_ci OMAP2_L3_IO_ADDRESS(OMAP2420_SDRC_BASE + (reg)) 1078c2ecf20Sopenharmony_ci#define OMAP243X_SDRC_REGADDR(reg) \ 1088c2ecf20Sopenharmony_ci OMAP2_L3_IO_ADDRESS(OMAP243X_SDRC_BASE + (reg)) 1098c2ecf20Sopenharmony_ci#define OMAP34XX_SDRC_REGADDR(reg) \ 1108c2ecf20Sopenharmony_ci OMAP2_L3_IO_ADDRESS(OMAP343X_SDRC_BASE + (reg)) 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci#endif /* __ASSEMBLER__ */ 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci/* Minimum frequency that the SDRC DLL can lock at */ 1158c2ecf20Sopenharmony_ci#define MIN_SDRC_DLL_LOCK_FREQ 83000000 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci/* Scale factor for fixed-point arith in omap3_core_dpll_m2_set_rate() */ 1188c2ecf20Sopenharmony_ci#define SDRC_MPURATE_SCALE 8 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci/* 2^SDRC_MPURATE_BASE_SHIFT: MPU MHz that SDRC_MPURATE_LOOPS is defined for */ 1218c2ecf20Sopenharmony_ci#define SDRC_MPURATE_BASE_SHIFT 9 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci/* 1248c2ecf20Sopenharmony_ci * SDRC_MPURATE_LOOPS: Number of MPU loops to execute at 1258c2ecf20Sopenharmony_ci * 2^MPURATE_BASE_SHIFT MHz for SDRC to stabilize 1268c2ecf20Sopenharmony_ci */ 1278c2ecf20Sopenharmony_ci#define SDRC_MPURATE_LOOPS 96 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci/* SDRC register offsets - read/write with sdrc_{read,write}_reg() */ 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci#define SDRC_SYSCONFIG 0x010 1328c2ecf20Sopenharmony_ci#define SDRC_CS_CFG 0x040 1338c2ecf20Sopenharmony_ci#define SDRC_SHARING 0x044 1348c2ecf20Sopenharmony_ci#define SDRC_ERR_TYPE 0x04C 1358c2ecf20Sopenharmony_ci#define SDRC_DLLA_CTRL 0x060 1368c2ecf20Sopenharmony_ci#define SDRC_DLLA_STATUS 0x064 1378c2ecf20Sopenharmony_ci#define SDRC_DLLB_CTRL 0x068 1388c2ecf20Sopenharmony_ci#define SDRC_DLLB_STATUS 0x06C 1398c2ecf20Sopenharmony_ci#define SDRC_POWER 0x070 1408c2ecf20Sopenharmony_ci#define SDRC_MCFG_0 0x080 1418c2ecf20Sopenharmony_ci#define SDRC_MR_0 0x084 1428c2ecf20Sopenharmony_ci#define SDRC_EMR2_0 0x08c 1438c2ecf20Sopenharmony_ci#define SDRC_ACTIM_CTRL_A_0 0x09c 1448c2ecf20Sopenharmony_ci#define SDRC_ACTIM_CTRL_B_0 0x0a0 1458c2ecf20Sopenharmony_ci#define SDRC_RFR_CTRL_0 0x0a4 1468c2ecf20Sopenharmony_ci#define SDRC_MANUAL_0 0x0a8 1478c2ecf20Sopenharmony_ci#define SDRC_MCFG_1 0x0B0 1488c2ecf20Sopenharmony_ci#define SDRC_MR_1 0x0B4 1498c2ecf20Sopenharmony_ci#define SDRC_EMR2_1 0x0BC 1508c2ecf20Sopenharmony_ci#define SDRC_ACTIM_CTRL_A_1 0x0C4 1518c2ecf20Sopenharmony_ci#define SDRC_ACTIM_CTRL_B_1 0x0C8 1528c2ecf20Sopenharmony_ci#define SDRC_RFR_CTRL_1 0x0D4 1538c2ecf20Sopenharmony_ci#define SDRC_MANUAL_1 0x0D8 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci#define SDRC_POWER_AUTOCOUNT_SHIFT 8 1568c2ecf20Sopenharmony_ci#define SDRC_POWER_AUTOCOUNT_MASK (0xffff << SDRC_POWER_AUTOCOUNT_SHIFT) 1578c2ecf20Sopenharmony_ci#define SDRC_POWER_CLKCTRL_SHIFT 4 1588c2ecf20Sopenharmony_ci#define SDRC_POWER_CLKCTRL_MASK (0x3 << SDRC_POWER_CLKCTRL_SHIFT) 1598c2ecf20Sopenharmony_ci#define SDRC_SELF_REFRESH_ON_AUTOCOUNT (0x2 << SDRC_POWER_CLKCTRL_SHIFT) 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci/* 1628c2ecf20Sopenharmony_ci * These values represent the number of memory clock cycles between 1638c2ecf20Sopenharmony_ci * autorefresh initiation. They assume 1 refresh per 64 ms (JEDEC), 8192 1648c2ecf20Sopenharmony_ci * rows per device, and include a subtraction of a 50 cycle window in the 1658c2ecf20Sopenharmony_ci * event that the autorefresh command is delayed due to other SDRC activity. 1668c2ecf20Sopenharmony_ci * The '| 1' sets the ARE field to send one autorefresh when the autorefresh 1678c2ecf20Sopenharmony_ci * counter reaches 0. 1688c2ecf20Sopenharmony_ci * 1698c2ecf20Sopenharmony_ci * These represent optimal values for common parts, it won't work for all. 1708c2ecf20Sopenharmony_ci * As long as you scale down, most parameters are still work, they just 1718c2ecf20Sopenharmony_ci * become sub-optimal. The RFR value goes in the opposite direction. If you 1728c2ecf20Sopenharmony_ci * don't adjust it down as your clock period increases the refresh interval 1738c2ecf20Sopenharmony_ci * will not be met. Setting all parameters for complete worst case may work, 1748c2ecf20Sopenharmony_ci * but may cut memory performance by 2x. Due to errata the DLLs need to be 1758c2ecf20Sopenharmony_ci * unlocked and their value needs run time calibration. A dynamic call is 1768c2ecf20Sopenharmony_ci * need for that as no single right value exists across production samples. 1778c2ecf20Sopenharmony_ci * 1788c2ecf20Sopenharmony_ci * Only the FULL speed values are given. Current code is such that rate 1798c2ecf20Sopenharmony_ci * changes must be made at DPLLoutx2. The actual value adjustment for low 1808c2ecf20Sopenharmony_ci * frequency operation will be handled by omap_set_performance() 1818c2ecf20Sopenharmony_ci * 1828c2ecf20Sopenharmony_ci * By having the boot loader boot up in the fastest L4 speed available likely 1838c2ecf20Sopenharmony_ci * will result in something which you can switch between. 1848c2ecf20Sopenharmony_ci */ 1858c2ecf20Sopenharmony_ci#define SDRC_RFR_CTRL_165MHz (0x00044c00 | 1) 1868c2ecf20Sopenharmony_ci#define SDRC_RFR_CTRL_133MHz (0x0003de00 | 1) 1878c2ecf20Sopenharmony_ci#define SDRC_RFR_CTRL_100MHz (0x0002da01 | 1) 1888c2ecf20Sopenharmony_ci#define SDRC_RFR_CTRL_110MHz (0x0002da01 | 1) /* Need to calc */ 1898c2ecf20Sopenharmony_ci#define SDRC_RFR_CTRL_BYPASS (0x00005000 | 1) /* Need to calc */ 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci/* 1938c2ecf20Sopenharmony_ci * SMS register access 1948c2ecf20Sopenharmony_ci */ 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci#define OMAP242X_SMS_REGADDR(reg) \ 1978c2ecf20Sopenharmony_ci (void __iomem *)OMAP2_L3_IO_ADDRESS(OMAP2420_SMS_BASE + reg) 1988c2ecf20Sopenharmony_ci#define OMAP243X_SMS_REGADDR(reg) \ 1998c2ecf20Sopenharmony_ci (void __iomem *)OMAP2_L3_IO_ADDRESS(OMAP243X_SMS_BASE + reg) 2008c2ecf20Sopenharmony_ci#define OMAP343X_SMS_REGADDR(reg) \ 2018c2ecf20Sopenharmony_ci (void __iomem *)OMAP2_L3_IO_ADDRESS(OMAP343X_SMS_BASE + reg) 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci/* SMS register offsets - read/write with sms_{read,write}_reg() */ 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci#define SMS_SYSCONFIG 0x010 2068c2ecf20Sopenharmony_ci/* REVISIT: fill in other SMS registers here */ 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci#endif 211