169d88a00SPaul Walmsley /* 269d88a00SPaul Walmsley * OMAP2/3 System Control Module register access 369d88a00SPaul Walmsley * 43e6ece13SPaul Walmsley * Copyright (C) 2007, 2012 Texas Instruments, Inc. 569d88a00SPaul Walmsley * Copyright (C) 2007 Nokia Corporation 669d88a00SPaul Walmsley * 769d88a00SPaul Walmsley * Written by Paul Walmsley 869d88a00SPaul Walmsley * 969d88a00SPaul Walmsley * This program is free software; you can redistribute it and/or modify 1069d88a00SPaul Walmsley * it under the terms of the GNU General Public License version 2 as 1169d88a00SPaul Walmsley * published by the Free Software Foundation. 1269d88a00SPaul Walmsley */ 1369d88a00SPaul Walmsley #undef DEBUG 1469d88a00SPaul Walmsley 1569d88a00SPaul Walmsley #include <linux/kernel.h> 16a58caad1STony Lindgren #include <linux/io.h> 17fe87414fSTero Kristo #include <linux/of_address.h> 18e5b63574STero Kristo #include <linux/regmap.h> 19e5b63574STero Kristo #include <linux/mfd/syscon.h> 2069d88a00SPaul Walmsley 21dbc04161STony Lindgren #include "soc.h" 22ee0839c2STony Lindgren #include "iomap.h" 23ee0839c2STony Lindgren #include "common.h" 2480140786SRajendra Nayak #include "cm-regbits-34xx.h" 2580140786SRajendra Nayak #include "prm-regbits-34xx.h" 26139563adSPaul Walmsley #include "prm3xxx.h" 27ff4ae5d9SPaul Walmsley #include "cm3xxx.h" 2880140786SRajendra Nayak #include "sdrc.h" 2938815733SManjunath Kondaiah G #include "pm.h" 304814ced5SPaul Walmsley #include "control.h" 31fe87414fSTero Kristo #include "clock.h" 3269d88a00SPaul Walmsley 33596efe47SPaul Walmsley /* Used by omap3_ctrl_save_padconf() */ 34596efe47SPaul Walmsley #define START_PADCONF_SAVE 0x2 35596efe47SPaul Walmsley #define PADCONF_SAVE_DONE 0x1 36596efe47SPaul Walmsley 37a58caad1STony Lindgren static void __iomem *omap2_ctrl_base; 38e5b63574STero Kristo static s16 omap2_ctrl_offset; 390c349246SSantosh Shilimkar static void __iomem *omap4_ctrl_pad_base; 40e5b63574STero Kristo static struct regmap *omap2_ctrl_syscon; 4169d88a00SPaul Walmsley 42c96631e1SRajendra Nayak #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM) 4380140786SRajendra Nayak struct omap3_scratchpad { 4480140786SRajendra Nayak u32 boot_config_ptr; 4580140786SRajendra Nayak u32 public_restore_ptr; 4680140786SRajendra Nayak u32 secure_ram_restore_ptr; 4780140786SRajendra Nayak u32 sdrc_module_semaphore; 4880140786SRajendra Nayak u32 prcm_block_offset; 4980140786SRajendra Nayak u32 sdrc_block_offset; 5080140786SRajendra Nayak }; 5180140786SRajendra Nayak 5280140786SRajendra Nayak struct omap3_scratchpad_prcm_block { 537e28b465STero Kristo u32 prm_contents[2]; 54c6a2d839STero Kristo u32 cm_contents[11]; 5580140786SRajendra Nayak u32 prcm_block_size; 5680140786SRajendra Nayak }; 5780140786SRajendra Nayak 5880140786SRajendra Nayak struct omap3_scratchpad_sdrc_block { 5980140786SRajendra Nayak u16 sysconfig; 6080140786SRajendra Nayak u16 cs_cfg; 6180140786SRajendra Nayak u16 sharing; 6280140786SRajendra Nayak u16 err_type; 6380140786SRajendra Nayak u32 dll_a_ctrl; 6480140786SRajendra Nayak u32 dll_b_ctrl; 6580140786SRajendra Nayak u32 power; 6680140786SRajendra Nayak u32 cs_0; 6780140786SRajendra Nayak u32 mcfg_0; 6880140786SRajendra Nayak u16 mr_0; 6980140786SRajendra Nayak u16 emr_1_0; 7080140786SRajendra Nayak u16 emr_2_0; 7180140786SRajendra Nayak u16 emr_3_0; 7280140786SRajendra Nayak u32 actim_ctrla_0; 7380140786SRajendra Nayak u32 actim_ctrlb_0; 7480140786SRajendra Nayak u32 rfr_ctrl_0; 7580140786SRajendra Nayak u32 cs_1; 7680140786SRajendra Nayak u32 mcfg_1; 7780140786SRajendra Nayak u16 mr_1; 7880140786SRajendra Nayak u16 emr_1_1; 7980140786SRajendra Nayak u16 emr_2_1; 8080140786SRajendra Nayak u16 emr_3_1; 8180140786SRajendra Nayak u32 actim_ctrla_1; 8280140786SRajendra Nayak u32 actim_ctrlb_1; 8380140786SRajendra Nayak u32 rfr_ctrl_1; 8480140786SRajendra Nayak u16 dcdl_1_ctrl; 8580140786SRajendra Nayak u16 dcdl_2_ctrl; 8680140786SRajendra Nayak u32 flags; 8780140786SRajendra Nayak u32 block_size; 8880140786SRajendra Nayak }; 8980140786SRajendra Nayak 9027d59a4aSTero Kristo void *omap3_secure_ram_storage; 9127d59a4aSTero Kristo 9280140786SRajendra Nayak /* 9380140786SRajendra Nayak * This is used to store ARM registers in SDRAM before attempting 9480140786SRajendra Nayak * an MPU OFF. The save and restore happens from the SRAM sleep code. 9580140786SRajendra Nayak * The address is stored in scratchpad, so that it can be used 9680140786SRajendra Nayak * during the restore path. 9780140786SRajendra Nayak */ 9880140786SRajendra Nayak u32 omap3_arm_context[128]; 9980140786SRajendra Nayak 100c96631e1SRajendra Nayak struct omap3_control_regs { 101c96631e1SRajendra Nayak u32 sysconfig; 102c96631e1SRajendra Nayak u32 devconf0; 103c96631e1SRajendra Nayak u32 mem_dftrw0; 104c96631e1SRajendra Nayak u32 mem_dftrw1; 105c96631e1SRajendra Nayak u32 msuspendmux_0; 106c96631e1SRajendra Nayak u32 msuspendmux_1; 107c96631e1SRajendra Nayak u32 msuspendmux_2; 108c96631e1SRajendra Nayak u32 msuspendmux_3; 109c96631e1SRajendra Nayak u32 msuspendmux_4; 110c96631e1SRajendra Nayak u32 msuspendmux_5; 111c96631e1SRajendra Nayak u32 sec_ctrl; 112c96631e1SRajendra Nayak u32 devconf1; 113c96631e1SRajendra Nayak u32 csirxfe; 114c96631e1SRajendra Nayak u32 iva2_bootaddr; 115c96631e1SRajendra Nayak u32 iva2_bootmod; 116c96631e1SRajendra Nayak u32 debobs_0; 117c96631e1SRajendra Nayak u32 debobs_1; 118c96631e1SRajendra Nayak u32 debobs_2; 119c96631e1SRajendra Nayak u32 debobs_3; 120c96631e1SRajendra Nayak u32 debobs_4; 121c96631e1SRajendra Nayak u32 debobs_5; 122c96631e1SRajendra Nayak u32 debobs_6; 123c96631e1SRajendra Nayak u32 debobs_7; 124c96631e1SRajendra Nayak u32 debobs_8; 125c96631e1SRajendra Nayak u32 prog_io0; 126c96631e1SRajendra Nayak u32 prog_io1; 127c96631e1SRajendra Nayak u32 dss_dpll_spreading; 128c96631e1SRajendra Nayak u32 core_dpll_spreading; 129c96631e1SRajendra Nayak u32 per_dpll_spreading; 130c96631e1SRajendra Nayak u32 usbhost_dpll_spreading; 131c96631e1SRajendra Nayak u32 pbias_lite; 132c96631e1SRajendra Nayak u32 temp_sensor; 133c96631e1SRajendra Nayak u32 sramldo4; 134c96631e1SRajendra Nayak u32 sramldo5; 135c96631e1SRajendra Nayak u32 csi; 136f5f9d132SPaul Walmsley u32 padconf_sys_nirq; 137c96631e1SRajendra Nayak }; 138c96631e1SRajendra Nayak 139c96631e1SRajendra Nayak static struct omap3_control_regs control_context; 140c96631e1SRajendra Nayak #endif /* CONFIG_ARCH_OMAP3 && CONFIG_PM */ 141c96631e1SRajendra Nayak 14270ba71a2SSantosh Shilimkar #define OMAP4_CTRL_PAD_REGADDR(reg) (omap4_ctrl_pad_base + (reg)) 14369d88a00SPaul Walmsley 144b6a4226cSPaul Walmsley void __init omap2_set_globals_control(void __iomem *ctrl, 145b6a4226cSPaul Walmsley void __iomem *ctrl_pad) 14669d88a00SPaul Walmsley { 147b6a4226cSPaul Walmsley omap2_ctrl_base = ctrl; 148b6a4226cSPaul Walmsley omap4_ctrl_pad_base = ctrl_pad; 14969d88a00SPaul Walmsley } 15069d88a00SPaul Walmsley 15169d88a00SPaul Walmsley u8 omap_ctrl_readb(u16 offset) 15269d88a00SPaul Walmsley { 153e5b63574STero Kristo u32 val; 154e5b63574STero Kristo u8 byte_offset = offset & 0x3; 155e5b63574STero Kristo 156e5b63574STero Kristo val = omap_ctrl_readl(offset); 157e5b63574STero Kristo 158e5b63574STero Kristo return (val >> (byte_offset * 8)) & 0xff; 15969d88a00SPaul Walmsley } 16069d88a00SPaul Walmsley 16169d88a00SPaul Walmsley u16 omap_ctrl_readw(u16 offset) 16269d88a00SPaul Walmsley { 163e5b63574STero Kristo u32 val; 164e5b63574STero Kristo u16 byte_offset = offset & 0x2; 165e5b63574STero Kristo 166e5b63574STero Kristo val = omap_ctrl_readl(offset); 167e5b63574STero Kristo 168e5b63574STero Kristo return (val >> (byte_offset * 8)) & 0xffff; 16969d88a00SPaul Walmsley } 17069d88a00SPaul Walmsley 17169d88a00SPaul Walmsley u32 omap_ctrl_readl(u16 offset) 17269d88a00SPaul Walmsley { 173e5b63574STero Kristo u32 val; 174e5b63574STero Kristo 175e5b63574STero Kristo offset &= 0xfffc; 176e5b63574STero Kristo if (!omap2_ctrl_syscon) 177e5b63574STero Kristo val = readl_relaxed(omap2_ctrl_base + offset); 178e5b63574STero Kristo else 179e5b63574STero Kristo regmap_read(omap2_ctrl_syscon, omap2_ctrl_offset + offset, 180e5b63574STero Kristo &val); 181e5b63574STero Kristo 182e5b63574STero Kristo return val; 18369d88a00SPaul Walmsley } 18469d88a00SPaul Walmsley 18569d88a00SPaul Walmsley void omap_ctrl_writeb(u8 val, u16 offset) 18669d88a00SPaul Walmsley { 187e5b63574STero Kristo u32 tmp; 188e5b63574STero Kristo u8 byte_offset = offset & 0x3; 189e5b63574STero Kristo 190e5b63574STero Kristo tmp = omap_ctrl_readl(offset); 191e5b63574STero Kristo 192e5b63574STero Kristo tmp &= 0xffffffff ^ (0xff << (byte_offset * 8)); 193e5b63574STero Kristo tmp |= val << (byte_offset * 8); 194e5b63574STero Kristo 195e5b63574STero Kristo omap_ctrl_writel(tmp, offset); 19669d88a00SPaul Walmsley } 19769d88a00SPaul Walmsley 19869d88a00SPaul Walmsley void omap_ctrl_writew(u16 val, u16 offset) 19969d88a00SPaul Walmsley { 200e5b63574STero Kristo u32 tmp; 201e5b63574STero Kristo u8 byte_offset = offset & 0x2; 202e5b63574STero Kristo 203e5b63574STero Kristo tmp = omap_ctrl_readl(offset); 204e5b63574STero Kristo 205e5b63574STero Kristo tmp &= 0xffffffff ^ (0xffff << (byte_offset * 8)); 206e5b63574STero Kristo tmp |= val << (byte_offset * 8); 207e5b63574STero Kristo 208e5b63574STero Kristo omap_ctrl_writel(tmp, offset); 20969d88a00SPaul Walmsley } 21069d88a00SPaul Walmsley 21169d88a00SPaul Walmsley void omap_ctrl_writel(u32 val, u16 offset) 21269d88a00SPaul Walmsley { 213e5b63574STero Kristo offset &= 0xfffc; 214e5b63574STero Kristo if (!omap2_ctrl_syscon) 215e5b63574STero Kristo writel_relaxed(val, omap2_ctrl_base + offset); 216e5b63574STero Kristo else 217e5b63574STero Kristo regmap_write(omap2_ctrl_syscon, omap2_ctrl_offset + offset, 218e5b63574STero Kristo val); 21969d88a00SPaul Walmsley } 22069d88a00SPaul Walmsley 22170ba71a2SSantosh Shilimkar /* 22270ba71a2SSantosh Shilimkar * On OMAP4 control pad are not addressable from control 22370ba71a2SSantosh Shilimkar * core base. So the common omap_ctrl_read/write APIs breaks 22470ba71a2SSantosh Shilimkar * Hence export separate APIs to manage the omap4 pad control 22570ba71a2SSantosh Shilimkar * registers. This APIs will work only for OMAP4 22670ba71a2SSantosh Shilimkar */ 22770ba71a2SSantosh Shilimkar 22870ba71a2SSantosh Shilimkar u32 omap4_ctrl_pad_readl(u16 offset) 22970ba71a2SSantosh Shilimkar { 230edfaf05cSVictor Kamensky return readl_relaxed(OMAP4_CTRL_PAD_REGADDR(offset)); 23170ba71a2SSantosh Shilimkar } 23270ba71a2SSantosh Shilimkar 23370ba71a2SSantosh Shilimkar void omap4_ctrl_pad_writel(u32 val, u16 offset) 23470ba71a2SSantosh Shilimkar { 235edfaf05cSVictor Kamensky writel_relaxed(val, OMAP4_CTRL_PAD_REGADDR(offset)); 23670ba71a2SSantosh Shilimkar } 23770ba71a2SSantosh Shilimkar 238166353bdSPaul Walmsley #ifdef CONFIG_ARCH_OMAP3 239166353bdSPaul Walmsley 240166353bdSPaul Walmsley /** 241166353bdSPaul Walmsley * omap3_ctrl_write_boot_mode - set scratchpad boot mode for the next boot 242166353bdSPaul Walmsley * @bootmode: 8-bit value to pass to some boot code 243166353bdSPaul Walmsley * 244166353bdSPaul Walmsley * Set the bootmode in the scratchpad RAM. This is used after the 245166353bdSPaul Walmsley * system restarts. Not sure what actually uses this - it may be the 246166353bdSPaul Walmsley * bootloader, rather than the boot ROM - contrary to the preserved 247166353bdSPaul Walmsley * comment below. No return value. 248166353bdSPaul Walmsley */ 249166353bdSPaul Walmsley void omap3_ctrl_write_boot_mode(u8 bootmode) 250166353bdSPaul Walmsley { 251166353bdSPaul Walmsley u32 l; 252166353bdSPaul Walmsley 253166353bdSPaul Walmsley l = ('B' << 24) | ('M' << 16) | bootmode; 254166353bdSPaul Walmsley 255166353bdSPaul Walmsley /* 256166353bdSPaul Walmsley * Reserve the first word in scratchpad for communicating 257166353bdSPaul Walmsley * with the boot ROM. A pointer to a data structure 258166353bdSPaul Walmsley * describing the boot process can be stored there, 259166353bdSPaul Walmsley * cf. OMAP34xx TRM, Initialization / Software Booting 260166353bdSPaul Walmsley * Configuration. 261166353bdSPaul Walmsley * 262166353bdSPaul Walmsley * XXX This should use some omap_ctrl_writel()-type function 263166353bdSPaul Walmsley */ 264edfaf05cSVictor Kamensky writel_relaxed(l, OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD + 4)); 265166353bdSPaul Walmsley } 266166353bdSPaul Walmsley 267166353bdSPaul Walmsley #endif 268166353bdSPaul Walmsley 26990f1380eSOmar Ramirez Luna /** 27090f1380eSOmar Ramirez Luna * omap_ctrl_write_dsp_boot_addr - set boot address for a remote processor 27190f1380eSOmar Ramirez Luna * @bootaddr: physical address of the boot loader 27290f1380eSOmar Ramirez Luna * 27390f1380eSOmar Ramirez Luna * Set boot address for the boot loader of a supported processor 27490f1380eSOmar Ramirez Luna * when a power ON sequence occurs. 27590f1380eSOmar Ramirez Luna */ 27690f1380eSOmar Ramirez Luna void omap_ctrl_write_dsp_boot_addr(u32 bootaddr) 27790f1380eSOmar Ramirez Luna { 27890f1380eSOmar Ramirez Luna u32 offset = cpu_is_omap243x() ? OMAP243X_CONTROL_IVA2_BOOTADDR : 27990f1380eSOmar Ramirez Luna cpu_is_omap34xx() ? OMAP343X_CONTROL_IVA2_BOOTADDR : 28090f1380eSOmar Ramirez Luna cpu_is_omap44xx() ? OMAP4_CTRL_MODULE_CORE_DSP_BOOTADDR : 281668468b1SSuman Anna soc_is_omap54xx() ? OMAP4_CTRL_MODULE_CORE_DSP_BOOTADDR : 28290f1380eSOmar Ramirez Luna 0; 28390f1380eSOmar Ramirez Luna 28490f1380eSOmar Ramirez Luna if (!offset) { 28590f1380eSOmar Ramirez Luna pr_err("%s: unsupported omap type\n", __func__); 28690f1380eSOmar Ramirez Luna return; 28790f1380eSOmar Ramirez Luna } 28890f1380eSOmar Ramirez Luna 28990f1380eSOmar Ramirez Luna omap_ctrl_writel(bootaddr, offset); 29090f1380eSOmar Ramirez Luna } 29190f1380eSOmar Ramirez Luna 29290f1380eSOmar Ramirez Luna /** 29390f1380eSOmar Ramirez Luna * omap_ctrl_write_dsp_boot_mode - set boot mode for a remote processor 29490f1380eSOmar Ramirez Luna * @bootmode: 8-bit value to pass to some boot code 29590f1380eSOmar Ramirez Luna * 29690f1380eSOmar Ramirez Luna * Sets boot mode for the boot loader of a supported processor 29790f1380eSOmar Ramirez Luna * when a power ON sequence occurs. 29890f1380eSOmar Ramirez Luna */ 29990f1380eSOmar Ramirez Luna void omap_ctrl_write_dsp_boot_mode(u8 bootmode) 30090f1380eSOmar Ramirez Luna { 30190f1380eSOmar Ramirez Luna u32 offset = cpu_is_omap243x() ? OMAP243X_CONTROL_IVA2_BOOTMOD : 30290f1380eSOmar Ramirez Luna cpu_is_omap34xx() ? OMAP343X_CONTROL_IVA2_BOOTMOD : 30390f1380eSOmar Ramirez Luna 0; 30490f1380eSOmar Ramirez Luna 30590f1380eSOmar Ramirez Luna if (!offset) { 30690f1380eSOmar Ramirez Luna pr_err("%s: unsupported omap type\n", __func__); 30790f1380eSOmar Ramirez Luna return; 30890f1380eSOmar Ramirez Luna } 30990f1380eSOmar Ramirez Luna 31090f1380eSOmar Ramirez Luna omap_ctrl_writel(bootmode, offset); 31190f1380eSOmar Ramirez Luna } 31290f1380eSOmar Ramirez Luna 313c96631e1SRajendra Nayak #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM) 31480140786SRajendra Nayak /* 31580140786SRajendra Nayak * Clears the scratchpad contents in case of cold boot- 31680140786SRajendra Nayak * called during bootup 31780140786SRajendra Nayak */ 31880140786SRajendra Nayak void omap3_clear_scratchpad_contents(void) 31980140786SRajendra Nayak { 32080140786SRajendra Nayak u32 max_offset = OMAP343X_SCRATCHPAD_ROM_OFFSET; 3214d63bc1dSManjunath Kondaiah G void __iomem *v_addr; 32280140786SRajendra Nayak u32 offset = 0; 323ae21e618SJeremy Vial 32480140786SRajendra Nayak v_addr = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD_ROM); 3259efcea09STero Kristo if (omap3xxx_prm_clear_global_cold_reset()) { 32680140786SRajendra Nayak for ( ; offset <= max_offset; offset += 0x4) 327edfaf05cSVictor Kamensky writel_relaxed(0x0, (v_addr + offset)); 32880140786SRajendra Nayak } 32980140786SRajendra Nayak } 33080140786SRajendra Nayak 33180140786SRajendra Nayak /* Populate the scratchpad structure with restore structure */ 33280140786SRajendra Nayak void omap3_save_scratchpad_contents(void) 33380140786SRajendra Nayak { 3344d63bc1dSManjunath Kondaiah G void __iomem *scratchpad_address; 33580140786SRajendra Nayak u32 arm_context_addr; 33680140786SRajendra Nayak struct omap3_scratchpad scratchpad_contents; 33780140786SRajendra Nayak struct omap3_scratchpad_prcm_block prcm_block_contents; 33880140786SRajendra Nayak struct omap3_scratchpad_sdrc_block sdrc_block_contents; 33980140786SRajendra Nayak 340f7dfe3d8SJean Pihet /* 341f7dfe3d8SJean Pihet * Populate the Scratchpad contents 342f7dfe3d8SJean Pihet * 343f7dfe3d8SJean Pihet * The "get_*restore_pointer" functions are used to provide a 344f7dfe3d8SJean Pihet * physical restore address where the ROM code jumps while waking 345f7dfe3d8SJean Pihet * up from MPU OFF/OSWR state. 346f7dfe3d8SJean Pihet * The restore pointer is stored into the scratchpad. 347f7dfe3d8SJean Pihet */ 34880140786SRajendra Nayak scratchpad_contents.boot_config_ptr = 0x0; 349458e999eSNishanth Menon if (cpu_is_omap3630()) 350458e999eSNishanth Menon scratchpad_contents.public_restore_ptr = 35114c79bbeSKevin Hilman virt_to_phys(omap3_restore_3630); 352458e999eSNishanth Menon else if (omap_rev() != OMAP3430_REV_ES3_0 && 3539b5f7428SJeremy Vial omap_rev() != OMAP3430_REV_ES3_1 && 3549b5f7428SJeremy Vial omap_rev() != OMAP3430_REV_ES3_1_2) 35580140786SRajendra Nayak scratchpad_contents.public_restore_ptr = 35614c79bbeSKevin Hilman virt_to_phys(omap3_restore); 3570795a75aSTero Kristo else 3580795a75aSTero Kristo scratchpad_contents.public_restore_ptr = 35914c79bbeSKevin Hilman virt_to_phys(omap3_restore_es3); 36014c79bbeSKevin Hilman 36127d59a4aSTero Kristo if (omap_type() == OMAP2_DEVICE_TYPE_GP) 36280140786SRajendra Nayak scratchpad_contents.secure_ram_restore_ptr = 0x0; 36327d59a4aSTero Kristo else 36427d59a4aSTero Kristo scratchpad_contents.secure_ram_restore_ptr = 36527d59a4aSTero Kristo (u32) __pa(omap3_secure_ram_storage); 36680140786SRajendra Nayak scratchpad_contents.sdrc_module_semaphore = 0x0; 36780140786SRajendra Nayak scratchpad_contents.prcm_block_offset = 0x2C; 36880140786SRajendra Nayak scratchpad_contents.sdrc_block_offset = 0x64; 36980140786SRajendra Nayak 37080140786SRajendra Nayak /* Populate the PRCM block contents */ 3717e28b465STero Kristo omap3_prm_save_scratchpad_contents(prcm_block_contents.prm_contents); 372c6a2d839STero Kristo omap3_cm_save_scratchpad_contents(prcm_block_contents.cm_contents); 373c6a2d839STero Kristo 37480140786SRajendra Nayak prcm_block_contents.prcm_block_size = 0x0; 37580140786SRajendra Nayak 37680140786SRajendra Nayak /* Populate the SDRC block contents */ 37780140786SRajendra Nayak sdrc_block_contents.sysconfig = 37880140786SRajendra Nayak (sdrc_read_reg(SDRC_SYSCONFIG) & 0xFFFF); 37980140786SRajendra Nayak sdrc_block_contents.cs_cfg = 38080140786SRajendra Nayak (sdrc_read_reg(SDRC_CS_CFG) & 0xFFFF); 38180140786SRajendra Nayak sdrc_block_contents.sharing = 38280140786SRajendra Nayak (sdrc_read_reg(SDRC_SHARING) & 0xFFFF); 38380140786SRajendra Nayak sdrc_block_contents.err_type = 38480140786SRajendra Nayak (sdrc_read_reg(SDRC_ERR_TYPE) & 0xFFFF); 38580140786SRajendra Nayak sdrc_block_contents.dll_a_ctrl = sdrc_read_reg(SDRC_DLLA_CTRL); 38680140786SRajendra Nayak sdrc_block_contents.dll_b_ctrl = 0x0; 387f265dc4cSRajendra Nayak /* 388f265dc4cSRajendra Nayak * Due to a OMAP3 errata (1.142), on EMU/HS devices SRDC should 389f265dc4cSRajendra Nayak * be programed to issue automatic self refresh on timeout 390f265dc4cSRajendra Nayak * of AUTO_CNT = 1 prior to any transition to OFF mode. 391f265dc4cSRajendra Nayak */ 392f265dc4cSRajendra Nayak if ((omap_type() != OMAP2_DEVICE_TYPE_GP) 393f265dc4cSRajendra Nayak && (omap_rev() >= OMAP3430_REV_ES3_0)) 394f265dc4cSRajendra Nayak sdrc_block_contents.power = (sdrc_read_reg(SDRC_POWER) & 395f265dc4cSRajendra Nayak ~(SDRC_POWER_AUTOCOUNT_MASK| 396f265dc4cSRajendra Nayak SDRC_POWER_CLKCTRL_MASK)) | 397f265dc4cSRajendra Nayak (1 << SDRC_POWER_AUTOCOUNT_SHIFT) | 398f265dc4cSRajendra Nayak SDRC_SELF_REFRESH_ON_AUTOCOUNT; 399f265dc4cSRajendra Nayak else 40080140786SRajendra Nayak sdrc_block_contents.power = sdrc_read_reg(SDRC_POWER); 401f265dc4cSRajendra Nayak 40280140786SRajendra Nayak sdrc_block_contents.cs_0 = 0x0; 40380140786SRajendra Nayak sdrc_block_contents.mcfg_0 = sdrc_read_reg(SDRC_MCFG_0); 40480140786SRajendra Nayak sdrc_block_contents.mr_0 = (sdrc_read_reg(SDRC_MR_0) & 0xFFFF); 40580140786SRajendra Nayak sdrc_block_contents.emr_1_0 = 0x0; 40680140786SRajendra Nayak sdrc_block_contents.emr_2_0 = 0x0; 40780140786SRajendra Nayak sdrc_block_contents.emr_3_0 = 0x0; 40880140786SRajendra Nayak sdrc_block_contents.actim_ctrla_0 = 40980140786SRajendra Nayak sdrc_read_reg(SDRC_ACTIM_CTRL_A_0); 41080140786SRajendra Nayak sdrc_block_contents.actim_ctrlb_0 = 41180140786SRajendra Nayak sdrc_read_reg(SDRC_ACTIM_CTRL_B_0); 41280140786SRajendra Nayak sdrc_block_contents.rfr_ctrl_0 = 41380140786SRajendra Nayak sdrc_read_reg(SDRC_RFR_CTRL_0); 41480140786SRajendra Nayak sdrc_block_contents.cs_1 = 0x0; 41580140786SRajendra Nayak sdrc_block_contents.mcfg_1 = sdrc_read_reg(SDRC_MCFG_1); 41680140786SRajendra Nayak sdrc_block_contents.mr_1 = sdrc_read_reg(SDRC_MR_1) & 0xFFFF; 41780140786SRajendra Nayak sdrc_block_contents.emr_1_1 = 0x0; 41880140786SRajendra Nayak sdrc_block_contents.emr_2_1 = 0x0; 41980140786SRajendra Nayak sdrc_block_contents.emr_3_1 = 0x0; 42080140786SRajendra Nayak sdrc_block_contents.actim_ctrla_1 = 42180140786SRajendra Nayak sdrc_read_reg(SDRC_ACTIM_CTRL_A_1); 42280140786SRajendra Nayak sdrc_block_contents.actim_ctrlb_1 = 42380140786SRajendra Nayak sdrc_read_reg(SDRC_ACTIM_CTRL_B_1); 42480140786SRajendra Nayak sdrc_block_contents.rfr_ctrl_1 = 42580140786SRajendra Nayak sdrc_read_reg(SDRC_RFR_CTRL_1); 42680140786SRajendra Nayak sdrc_block_contents.dcdl_1_ctrl = 0x0; 42780140786SRajendra Nayak sdrc_block_contents.dcdl_2_ctrl = 0x0; 42880140786SRajendra Nayak sdrc_block_contents.flags = 0x0; 42980140786SRajendra Nayak sdrc_block_contents.block_size = 0x0; 43080140786SRajendra Nayak 43180140786SRajendra Nayak arm_context_addr = virt_to_phys(omap3_arm_context); 43280140786SRajendra Nayak 43380140786SRajendra Nayak /* Copy all the contents to the scratchpad location */ 43480140786SRajendra Nayak scratchpad_address = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD); 43580140786SRajendra Nayak memcpy_toio(scratchpad_address, &scratchpad_contents, 43680140786SRajendra Nayak sizeof(scratchpad_contents)); 43780140786SRajendra Nayak /* Scratchpad contents being 32 bits, a divide by 4 done here */ 43880140786SRajendra Nayak memcpy_toio(scratchpad_address + 43980140786SRajendra Nayak scratchpad_contents.prcm_block_offset, 44080140786SRajendra Nayak &prcm_block_contents, sizeof(prcm_block_contents)); 44180140786SRajendra Nayak memcpy_toio(scratchpad_address + 44280140786SRajendra Nayak scratchpad_contents.sdrc_block_offset, 44380140786SRajendra Nayak &sdrc_block_contents, sizeof(sdrc_block_contents)); 44480140786SRajendra Nayak /* 44580140786SRajendra Nayak * Copies the address of the location in SDRAM where ARM 44680140786SRajendra Nayak * registers get saved during a MPU OFF transition. 44780140786SRajendra Nayak */ 44880140786SRajendra Nayak memcpy_toio(scratchpad_address + 44980140786SRajendra Nayak scratchpad_contents.sdrc_block_offset + 45080140786SRajendra Nayak sizeof(sdrc_block_contents), &arm_context_addr, 4); 45180140786SRajendra Nayak } 45280140786SRajendra Nayak 453c96631e1SRajendra Nayak void omap3_control_save_context(void) 454c96631e1SRajendra Nayak { 455c96631e1SRajendra Nayak control_context.sysconfig = omap_ctrl_readl(OMAP2_CONTROL_SYSCONFIG); 456c96631e1SRajendra Nayak control_context.devconf0 = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0); 457c96631e1SRajendra Nayak control_context.mem_dftrw0 = 458c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_MEM_DFTRW0); 459c96631e1SRajendra Nayak control_context.mem_dftrw1 = 460c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_MEM_DFTRW1); 461c96631e1SRajendra Nayak control_context.msuspendmux_0 = 462c96631e1SRajendra Nayak omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_0); 463c96631e1SRajendra Nayak control_context.msuspendmux_1 = 464c96631e1SRajendra Nayak omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_1); 465c96631e1SRajendra Nayak control_context.msuspendmux_2 = 466c96631e1SRajendra Nayak omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_2); 467c96631e1SRajendra Nayak control_context.msuspendmux_3 = 468c96631e1SRajendra Nayak omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_3); 469c96631e1SRajendra Nayak control_context.msuspendmux_4 = 470c96631e1SRajendra Nayak omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_4); 471c96631e1SRajendra Nayak control_context.msuspendmux_5 = 472c96631e1SRajendra Nayak omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_5); 473c96631e1SRajendra Nayak control_context.sec_ctrl = omap_ctrl_readl(OMAP2_CONTROL_SEC_CTRL); 474c96631e1SRajendra Nayak control_context.devconf1 = omap_ctrl_readl(OMAP343X_CONTROL_DEVCONF1); 475c96631e1SRajendra Nayak control_context.csirxfe = omap_ctrl_readl(OMAP343X_CONTROL_CSIRXFE); 476c96631e1SRajendra Nayak control_context.iva2_bootaddr = 477c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_IVA2_BOOTADDR); 478c96631e1SRajendra Nayak control_context.iva2_bootmod = 479c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_IVA2_BOOTMOD); 480c96631e1SRajendra Nayak control_context.debobs_0 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(0)); 481c96631e1SRajendra Nayak control_context.debobs_1 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(1)); 482c96631e1SRajendra Nayak control_context.debobs_2 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(2)); 483c96631e1SRajendra Nayak control_context.debobs_3 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(3)); 484c96631e1SRajendra Nayak control_context.debobs_4 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(4)); 485c96631e1SRajendra Nayak control_context.debobs_5 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(5)); 486c96631e1SRajendra Nayak control_context.debobs_6 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(6)); 487c96631e1SRajendra Nayak control_context.debobs_7 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(7)); 488c96631e1SRajendra Nayak control_context.debobs_8 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(8)); 489c96631e1SRajendra Nayak control_context.prog_io0 = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO0); 490c96631e1SRajendra Nayak control_context.prog_io1 = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO1); 491c96631e1SRajendra Nayak control_context.dss_dpll_spreading = 492c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_DSS_DPLL_SPREADING); 493c96631e1SRajendra Nayak control_context.core_dpll_spreading = 494c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_CORE_DPLL_SPREADING); 495c96631e1SRajendra Nayak control_context.per_dpll_spreading = 496c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_PER_DPLL_SPREADING); 497c96631e1SRajendra Nayak control_context.usbhost_dpll_spreading = 498c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_USBHOST_DPLL_SPREADING); 499c96631e1SRajendra Nayak control_context.pbias_lite = 500c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_PBIAS_LITE); 501c96631e1SRajendra Nayak control_context.temp_sensor = 502c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_TEMP_SENSOR); 503c96631e1SRajendra Nayak control_context.sramldo4 = omap_ctrl_readl(OMAP343X_CONTROL_SRAMLDO4); 504c96631e1SRajendra Nayak control_context.sramldo5 = omap_ctrl_readl(OMAP343X_CONTROL_SRAMLDO5); 505c96631e1SRajendra Nayak control_context.csi = omap_ctrl_readl(OMAP343X_CONTROL_CSI); 506f5f9d132SPaul Walmsley control_context.padconf_sys_nirq = 507f5f9d132SPaul Walmsley omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_SYSNIRQ); 508c96631e1SRajendra Nayak } 509c96631e1SRajendra Nayak 510c96631e1SRajendra Nayak void omap3_control_restore_context(void) 511c96631e1SRajendra Nayak { 512c96631e1SRajendra Nayak omap_ctrl_writel(control_context.sysconfig, OMAP2_CONTROL_SYSCONFIG); 513c96631e1SRajendra Nayak omap_ctrl_writel(control_context.devconf0, OMAP2_CONTROL_DEVCONF0); 514c96631e1SRajendra Nayak omap_ctrl_writel(control_context.mem_dftrw0, 515c96631e1SRajendra Nayak OMAP343X_CONTROL_MEM_DFTRW0); 516c96631e1SRajendra Nayak omap_ctrl_writel(control_context.mem_dftrw1, 517c96631e1SRajendra Nayak OMAP343X_CONTROL_MEM_DFTRW1); 518c96631e1SRajendra Nayak omap_ctrl_writel(control_context.msuspendmux_0, 519c96631e1SRajendra Nayak OMAP2_CONTROL_MSUSPENDMUX_0); 520c96631e1SRajendra Nayak omap_ctrl_writel(control_context.msuspendmux_1, 521c96631e1SRajendra Nayak OMAP2_CONTROL_MSUSPENDMUX_1); 522c96631e1SRajendra Nayak omap_ctrl_writel(control_context.msuspendmux_2, 523c96631e1SRajendra Nayak OMAP2_CONTROL_MSUSPENDMUX_2); 524c96631e1SRajendra Nayak omap_ctrl_writel(control_context.msuspendmux_3, 525c96631e1SRajendra Nayak OMAP2_CONTROL_MSUSPENDMUX_3); 526c96631e1SRajendra Nayak omap_ctrl_writel(control_context.msuspendmux_4, 527c96631e1SRajendra Nayak OMAP2_CONTROL_MSUSPENDMUX_4); 528c96631e1SRajendra Nayak omap_ctrl_writel(control_context.msuspendmux_5, 529c96631e1SRajendra Nayak OMAP2_CONTROL_MSUSPENDMUX_5); 530c96631e1SRajendra Nayak omap_ctrl_writel(control_context.sec_ctrl, OMAP2_CONTROL_SEC_CTRL); 531c96631e1SRajendra Nayak omap_ctrl_writel(control_context.devconf1, OMAP343X_CONTROL_DEVCONF1); 532c96631e1SRajendra Nayak omap_ctrl_writel(control_context.csirxfe, OMAP343X_CONTROL_CSIRXFE); 533c96631e1SRajendra Nayak omap_ctrl_writel(control_context.iva2_bootaddr, 534c96631e1SRajendra Nayak OMAP343X_CONTROL_IVA2_BOOTADDR); 535c96631e1SRajendra Nayak omap_ctrl_writel(control_context.iva2_bootmod, 536c96631e1SRajendra Nayak OMAP343X_CONTROL_IVA2_BOOTMOD); 537c96631e1SRajendra Nayak omap_ctrl_writel(control_context.debobs_0, OMAP343X_CONTROL_DEBOBS(0)); 538c96631e1SRajendra Nayak omap_ctrl_writel(control_context.debobs_1, OMAP343X_CONTROL_DEBOBS(1)); 539c96631e1SRajendra Nayak omap_ctrl_writel(control_context.debobs_2, OMAP343X_CONTROL_DEBOBS(2)); 540c96631e1SRajendra Nayak omap_ctrl_writel(control_context.debobs_3, OMAP343X_CONTROL_DEBOBS(3)); 541c96631e1SRajendra Nayak omap_ctrl_writel(control_context.debobs_4, OMAP343X_CONTROL_DEBOBS(4)); 542c96631e1SRajendra Nayak omap_ctrl_writel(control_context.debobs_5, OMAP343X_CONTROL_DEBOBS(5)); 543c96631e1SRajendra Nayak omap_ctrl_writel(control_context.debobs_6, OMAP343X_CONTROL_DEBOBS(6)); 544c96631e1SRajendra Nayak omap_ctrl_writel(control_context.debobs_7, OMAP343X_CONTROL_DEBOBS(7)); 545c96631e1SRajendra Nayak omap_ctrl_writel(control_context.debobs_8, OMAP343X_CONTROL_DEBOBS(8)); 546c96631e1SRajendra Nayak omap_ctrl_writel(control_context.prog_io0, OMAP343X_CONTROL_PROG_IO0); 547c96631e1SRajendra Nayak omap_ctrl_writel(control_context.prog_io1, OMAP343X_CONTROL_PROG_IO1); 548c96631e1SRajendra Nayak omap_ctrl_writel(control_context.dss_dpll_spreading, 549c96631e1SRajendra Nayak OMAP343X_CONTROL_DSS_DPLL_SPREADING); 550c96631e1SRajendra Nayak omap_ctrl_writel(control_context.core_dpll_spreading, 551c96631e1SRajendra Nayak OMAP343X_CONTROL_CORE_DPLL_SPREADING); 552c96631e1SRajendra Nayak omap_ctrl_writel(control_context.per_dpll_spreading, 553c96631e1SRajendra Nayak OMAP343X_CONTROL_PER_DPLL_SPREADING); 554c96631e1SRajendra Nayak omap_ctrl_writel(control_context.usbhost_dpll_spreading, 555c96631e1SRajendra Nayak OMAP343X_CONTROL_USBHOST_DPLL_SPREADING); 556c96631e1SRajendra Nayak omap_ctrl_writel(control_context.pbias_lite, 557c96631e1SRajendra Nayak OMAP343X_CONTROL_PBIAS_LITE); 558c96631e1SRajendra Nayak omap_ctrl_writel(control_context.temp_sensor, 559c96631e1SRajendra Nayak OMAP343X_CONTROL_TEMP_SENSOR); 560c96631e1SRajendra Nayak omap_ctrl_writel(control_context.sramldo4, OMAP343X_CONTROL_SRAMLDO4); 561c96631e1SRajendra Nayak omap_ctrl_writel(control_context.sramldo5, OMAP343X_CONTROL_SRAMLDO5); 562c96631e1SRajendra Nayak omap_ctrl_writel(control_context.csi, OMAP343X_CONTROL_CSI); 563f5f9d132SPaul Walmsley omap_ctrl_writel(control_context.padconf_sys_nirq, 564f5f9d132SPaul Walmsley OMAP343X_CONTROL_PADCONF_SYSNIRQ); 565c96631e1SRajendra Nayak } 566458e999eSNishanth Menon 567458e999eSNishanth Menon void omap3630_ctrl_disable_rta(void) 568458e999eSNishanth Menon { 569458e999eSNishanth Menon if (!cpu_is_omap3630()) 570458e999eSNishanth Menon return; 571458e999eSNishanth Menon omap_ctrl_writel(OMAP36XX_RTA_DISABLE, OMAP36XX_CONTROL_MEM_RTA_CTRL); 572458e999eSNishanth Menon } 573458e999eSNishanth Menon 574596efe47SPaul Walmsley /** 575596efe47SPaul Walmsley * omap3_ctrl_save_padconf - save padconf registers to scratchpad RAM 576596efe47SPaul Walmsley * 577596efe47SPaul Walmsley * Tell the SCM to start saving the padconf registers, then wait for 578596efe47SPaul Walmsley * the process to complete. Returns 0 unconditionally, although it 579596efe47SPaul Walmsley * should also eventually be able to return -ETIMEDOUT, if the save 580596efe47SPaul Walmsley * does not complete. 581596efe47SPaul Walmsley * 582596efe47SPaul Walmsley * XXX This function is missing a timeout. What should it be? 583596efe47SPaul Walmsley */ 584596efe47SPaul Walmsley int omap3_ctrl_save_padconf(void) 585596efe47SPaul Walmsley { 586596efe47SPaul Walmsley u32 cpo; 587596efe47SPaul Walmsley 588596efe47SPaul Walmsley /* Save the padconf registers */ 589596efe47SPaul Walmsley cpo = omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_OFF); 590596efe47SPaul Walmsley cpo |= START_PADCONF_SAVE; 591596efe47SPaul Walmsley omap_ctrl_writel(cpo, OMAP343X_CONTROL_PADCONF_OFF); 592596efe47SPaul Walmsley 593596efe47SPaul Walmsley /* wait for the save to complete */ 594596efe47SPaul Walmsley while (!(omap_ctrl_readl(OMAP343X_CONTROL_GENERAL_PURPOSE_STATUS) 595596efe47SPaul Walmsley & PADCONF_SAVE_DONE)) 596596efe47SPaul Walmsley udelay(1); 597596efe47SPaul Walmsley 598596efe47SPaul Walmsley return 0; 599596efe47SPaul Walmsley } 600596efe47SPaul Walmsley 60149e03402STero Kristo /** 60249e03402STero Kristo * omap3_ctrl_set_iva_bootmode_idle - sets the IVA2 bootmode to idle 60349e03402STero Kristo * 60449e03402STero Kristo * Sets the bootmode for IVA2 to idle. This is needed by the PM code to 60549e03402STero Kristo * force disable IVA2 so that it does not prevent any low-power states. 60649e03402STero Kristo */ 607ba12c242STero Kristo static void __init omap3_ctrl_set_iva_bootmode_idle(void) 60849e03402STero Kristo { 60949e03402STero Kristo omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE, 61049e03402STero Kristo OMAP343X_CONTROL_IVA2_BOOTMOD); 61149e03402STero Kristo } 612bbd36f9fSTero Kristo 613bbd36f9fSTero Kristo /** 614bbd36f9fSTero Kristo * omap3_ctrl_setup_d2d_padconf - setup stacked modem pads for idle 615bbd36f9fSTero Kristo * 616bbd36f9fSTero Kristo * Sets up the pads controlling the stacked modem in such way that the 617bbd36f9fSTero Kristo * device can enter idle. 618bbd36f9fSTero Kristo */ 619ba12c242STero Kristo static void __init omap3_ctrl_setup_d2d_padconf(void) 620bbd36f9fSTero Kristo { 621bbd36f9fSTero Kristo u16 mask, padconf; 622bbd36f9fSTero Kristo 623bbd36f9fSTero Kristo /* 624bbd36f9fSTero Kristo * In a stand alone OMAP3430 where there is not a stacked 625bbd36f9fSTero Kristo * modem for the D2D Idle Ack and D2D MStandby must be pulled 626bbd36f9fSTero Kristo * high. S CONTROL_PADCONF_SAD2D_IDLEACK and 627bbd36f9fSTero Kristo * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up. 628bbd36f9fSTero Kristo */ 629bbd36f9fSTero Kristo mask = (1 << 4) | (1 << 3); /* pull-up, enabled */ 630bbd36f9fSTero Kristo padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY); 631bbd36f9fSTero Kristo padconf |= mask; 632bbd36f9fSTero Kristo omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_MSTANDBY); 633bbd36f9fSTero Kristo 634bbd36f9fSTero Kristo padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK); 635bbd36f9fSTero Kristo padconf |= mask; 636bbd36f9fSTero Kristo omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_IDLEACK); 637bbd36f9fSTero Kristo } 638ba12c242STero Kristo 639ba12c242STero Kristo /** 640ba12c242STero Kristo * omap3_ctrl_init - does static initializations for control module 641ba12c242STero Kristo * 642ba12c242STero Kristo * Initializes system control module. This sets up the sysconfig autoidle, 643ba12c242STero Kristo * and sets up modem and iva2 so that they can be idled properly. 644ba12c242STero Kristo */ 645ba12c242STero Kristo void __init omap3_ctrl_init(void) 646ba12c242STero Kristo { 647ba12c242STero Kristo omap_ctrl_writel(OMAP3430_AUTOIDLE_MASK, OMAP2_CONTROL_SYSCONFIG); 648ba12c242STero Kristo 649ba12c242STero Kristo omap3_ctrl_set_iva_bootmode_idle(); 650ba12c242STero Kristo 651ba12c242STero Kristo omap3_ctrl_setup_d2d_padconf(); 652ba12c242STero Kristo } 653c96631e1SRajendra Nayak #endif /* CONFIG_ARCH_OMAP3 && CONFIG_PM */ 654fe87414fSTero Kristo 655fe87414fSTero Kristo struct control_init_data { 656fe87414fSTero Kristo int index; 657e5b63574STero Kristo s16 offset; 658fe87414fSTero Kristo }; 659fe87414fSTero Kristo 660fe87414fSTero Kristo static struct control_init_data ctrl_data = { 661fe87414fSTero Kristo .index = TI_CLKM_CTRL, 662fe87414fSTero Kristo }; 663fe87414fSTero Kristo 66472b10ac0STero Kristo static const struct control_init_data omap2_ctrl_data = { 66572b10ac0STero Kristo .index = TI_CLKM_CTRL, 66672b10ac0STero Kristo .offset = -OMAP2_CONTROL_GENERAL, 66772b10ac0STero Kristo }; 66872b10ac0STero Kristo 669fe87414fSTero Kristo static const struct of_device_id omap_scrm_dt_match_table[] = { 670fe87414fSTero Kristo { .compatible = "ti,am3-scrm", .data = &ctrl_data }, 671fe87414fSTero Kristo { .compatible = "ti,am4-scrm", .data = &ctrl_data }, 67272b10ac0STero Kristo { .compatible = "ti,omap2-scm", .data = &omap2_ctrl_data }, 673*b8845074STero Kristo { .compatible = "ti,omap3-scm", .data = &omap2_ctrl_data }, 6742208bf11STero Kristo { .compatible = "ti,dm816-scrm", .data = &ctrl_data }, 675fe87414fSTero Kristo { } 676fe87414fSTero Kristo }; 677fe87414fSTero Kristo 678fe87414fSTero Kristo /** 6792208bf11STero Kristo * omap2_control_base_init - initialize iomappings for the control driver 6802208bf11STero Kristo * 6812208bf11STero Kristo * Detects and initializes the iomappings for the control driver, based 6822208bf11STero Kristo * on the DT data. Returns 0 in success, negative error value 6832208bf11STero Kristo * otherwise. 6842208bf11STero Kristo */ 6852208bf11STero Kristo int __init omap2_control_base_init(void) 6862208bf11STero Kristo { 6872208bf11STero Kristo struct device_node *np; 6882208bf11STero Kristo const struct of_device_id *match; 6892208bf11STero Kristo struct control_init_data *data; 6902208bf11STero Kristo 6912208bf11STero Kristo for_each_matching_node_and_match(np, omap_scrm_dt_match_table, &match) { 6922208bf11STero Kristo data = (struct control_init_data *)match->data; 6932208bf11STero Kristo 694e5b63574STero Kristo omap2_ctrl_base = of_iomap(np, 0); 695e5b63574STero Kristo if (!omap2_ctrl_base) 6962208bf11STero Kristo return -ENOMEM; 6972208bf11STero Kristo 698e5b63574STero Kristo omap2_ctrl_offset = data->offset; 6992208bf11STero Kristo } 7002208bf11STero Kristo 7012208bf11STero Kristo return 0; 7022208bf11STero Kristo } 7032208bf11STero Kristo 7042208bf11STero Kristo /** 705fe87414fSTero Kristo * omap_control_init - low level init for the control driver 706fe87414fSTero Kristo * 707fe87414fSTero Kristo * Initializes the low level clock infrastructure for control driver. 708fe87414fSTero Kristo * Returns 0 in success, negative error value in failure. 709fe87414fSTero Kristo */ 710fe87414fSTero Kristo int __init omap_control_init(void) 711fe87414fSTero Kristo { 712e5b63574STero Kristo struct device_node *np, *scm_conf; 713fe87414fSTero Kristo const struct of_device_id *match; 714fe87414fSTero Kristo const struct omap_prcm_init_data *data; 715fe87414fSTero Kristo int ret; 716e5b63574STero Kristo struct regmap *syscon; 717fe87414fSTero Kristo 718fe87414fSTero Kristo for_each_matching_node_and_match(np, omap_scrm_dt_match_table, &match) { 719fe87414fSTero Kristo data = match->data; 720fe87414fSTero Kristo 721e5b63574STero Kristo /* 722e5b63574STero Kristo * Check if we have scm_conf node, if yes, use this to 723e5b63574STero Kristo * access clock registers. 724e5b63574STero Kristo */ 725e5b63574STero Kristo scm_conf = of_get_child_by_name(np, "scm_conf"); 726e5b63574STero Kristo 727e5b63574STero Kristo if (scm_conf) { 728e5b63574STero Kristo syscon = syscon_node_to_regmap(scm_conf); 729e5b63574STero Kristo 730e5b63574STero Kristo if (IS_ERR(syscon)) 731e5b63574STero Kristo return PTR_ERR(syscon); 732e5b63574STero Kristo 733e5b63574STero Kristo omap2_ctrl_syscon = syscon; 734e5b63574STero Kristo 735e5b63574STero Kristo if (of_get_child_by_name(scm_conf, "clocks")) { 736e5b63574STero Kristo ret = omap2_clk_provider_init(scm_conf, 737e5b63574STero Kristo data->index, 738e5b63574STero Kristo syscon, NULL); 739fe87414fSTero Kristo if (ret) 740fe87414fSTero Kristo return ret; 741fe87414fSTero Kristo } 742fe87414fSTero Kristo 743e5b63574STero Kristo iounmap(omap2_ctrl_base); 744e5b63574STero Kristo omap2_ctrl_base = NULL; 745e5b63574STero Kristo } else { 746e5b63574STero Kristo /* No scm_conf found, direct access */ 747e5b63574STero Kristo ret = omap2_clk_provider_init(np, data->index, NULL, 748e5b63574STero Kristo omap2_ctrl_base); 749e5b63574STero Kristo if (ret) 750e5b63574STero Kristo return ret; 751e5b63574STero Kristo } 752e5b63574STero Kristo } 753e5b63574STero Kristo 754fe87414fSTero Kristo return 0; 755fe87414fSTero Kristo } 7562208bf11STero Kristo 7572208bf11STero Kristo /** 7582208bf11STero Kristo * omap3_control_legacy_iomap_init - legacy iomap init for clock providers 7592208bf11STero Kristo * 7602208bf11STero Kristo * Legacy iomap init for clock provider. Needed only by legacy boot mode, 7612208bf11STero Kristo * where the base addresses are not parsed from DT, but still required 7622208bf11STero Kristo * by the clock driver to be setup properly. 7632208bf11STero Kristo */ 7642208bf11STero Kristo void __init omap3_control_legacy_iomap_init(void) 7652208bf11STero Kristo { 7662208bf11STero Kristo omap2_clk_legacy_provider_init(TI_CLKM_SCRM, omap2_ctrl_base); 7672208bf11STero Kristo } 768