control.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. /*
  2. * OMAP2/3 System Control Module register access
  3. *
  4. * Copyright (C) 2007, 2012 Texas Instruments, Inc.
  5. * Copyright (C) 2007 Nokia Corporation
  6. *
  7. * Written by Paul Walmsley
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #undef DEBUG
  14. #include <linux/kernel.h>
  15. #include <linux/io.h>
  16. #include <linux/of_address.h>
  17. #include <linux/regmap.h>
  18. #include <linux/mfd/syscon.h>
  19. #include "soc.h"
  20. #include "iomap.h"
  21. #include "common.h"
  22. #include "cm-regbits-34xx.h"
  23. #include "prm-regbits-34xx.h"
  24. #include "prm3xxx.h"
  25. #include "cm3xxx.h"
  26. #include "sdrc.h"
  27. #include "pm.h"
  28. #include "control.h"
  29. #include "clock.h"
  30. /* Used by omap3_ctrl_save_padconf() */
  31. #define START_PADCONF_SAVE 0x2
  32. #define PADCONF_SAVE_DONE 0x1
  33. static void __iomem *omap2_ctrl_base;
  34. static s16 omap2_ctrl_offset;
  35. #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
  36. struct omap3_scratchpad {
  37. u32 boot_config_ptr;
  38. u32 public_restore_ptr;
  39. u32 secure_ram_restore_ptr;
  40. u32 sdrc_module_semaphore;
  41. u32 prcm_block_offset;
  42. u32 sdrc_block_offset;
  43. };
  44. struct omap3_scratchpad_prcm_block {
  45. u32 prm_contents[2];
  46. u32 cm_contents[11];
  47. u32 prcm_block_size;
  48. };
  49. struct omap3_scratchpad_sdrc_block {
  50. u16 sysconfig;
  51. u16 cs_cfg;
  52. u16 sharing;
  53. u16 err_type;
  54. u32 dll_a_ctrl;
  55. u32 dll_b_ctrl;
  56. u32 power;
  57. u32 cs_0;
  58. u32 mcfg_0;
  59. u16 mr_0;
  60. u16 emr_1_0;
  61. u16 emr_2_0;
  62. u16 emr_3_0;
  63. u32 actim_ctrla_0;
  64. u32 actim_ctrlb_0;
  65. u32 rfr_ctrl_0;
  66. u32 cs_1;
  67. u32 mcfg_1;
  68. u16 mr_1;
  69. u16 emr_1_1;
  70. u16 emr_2_1;
  71. u16 emr_3_1;
  72. u32 actim_ctrla_1;
  73. u32 actim_ctrlb_1;
  74. u32 rfr_ctrl_1;
  75. u16 dcdl_1_ctrl;
  76. u16 dcdl_2_ctrl;
  77. u32 flags;
  78. u32 block_size;
  79. };
  80. void *omap3_secure_ram_storage;
  81. /*
  82. * This is used to store ARM registers in SDRAM before attempting
  83. * an MPU OFF. The save and restore happens from the SRAM sleep code.
  84. * The address is stored in scratchpad, so that it can be used
  85. * during the restore path.
  86. */
  87. u32 omap3_arm_context[128];
  88. struct omap3_control_regs {
  89. u32 sysconfig;
  90. u32 devconf0;
  91. u32 mem_dftrw0;
  92. u32 mem_dftrw1;
  93. u32 msuspendmux_0;
  94. u32 msuspendmux_1;
  95. u32 msuspendmux_2;
  96. u32 msuspendmux_3;
  97. u32 msuspendmux_4;
  98. u32 msuspendmux_5;
  99. u32 sec_ctrl;
  100. u32 devconf1;
  101. u32 csirxfe;
  102. u32 iva2_bootaddr;
  103. u32 iva2_bootmod;
  104. u32 wkup_ctrl;
  105. u32 debobs_0;
  106. u32 debobs_1;
  107. u32 debobs_2;
  108. u32 debobs_3;
  109. u32 debobs_4;
  110. u32 debobs_5;
  111. u32 debobs_6;
  112. u32 debobs_7;
  113. u32 debobs_8;
  114. u32 prog_io0;
  115. u32 prog_io1;
  116. u32 dss_dpll_spreading;
  117. u32 core_dpll_spreading;
  118. u32 per_dpll_spreading;
  119. u32 usbhost_dpll_spreading;
  120. u32 pbias_lite;
  121. u32 temp_sensor;
  122. u32 sramldo4;
  123. u32 sramldo5;
  124. u32 csi;
  125. u32 padconf_sys_nirq;
  126. };
  127. static struct omap3_control_regs control_context;
  128. #endif /* CONFIG_ARCH_OMAP3 && CONFIG_PM */
  129. void __init omap2_set_globals_control(void __iomem *ctrl)
  130. {
  131. omap2_ctrl_base = ctrl;
  132. }
  133. u8 omap_ctrl_readb(u16 offset)
  134. {
  135. u32 val;
  136. u8 byte_offset = offset & 0x3;
  137. val = omap_ctrl_readl(offset);
  138. return (val >> (byte_offset * 8)) & 0xff;
  139. }
  140. u16 omap_ctrl_readw(u16 offset)
  141. {
  142. u32 val;
  143. u16 byte_offset = offset & 0x2;
  144. val = omap_ctrl_readl(offset);
  145. return (val >> (byte_offset * 8)) & 0xffff;
  146. }
  147. u32 omap_ctrl_readl(u16 offset)
  148. {
  149. offset &= 0xfffc;
  150. return readl_relaxed(omap2_ctrl_base + offset);
  151. }
  152. void omap_ctrl_writeb(u8 val, u16 offset)
  153. {
  154. u32 tmp;
  155. u8 byte_offset = offset & 0x3;
  156. tmp = omap_ctrl_readl(offset);
  157. tmp &= 0xffffffff ^ (0xff << (byte_offset * 8));
  158. tmp |= val << (byte_offset * 8);
  159. omap_ctrl_writel(tmp, offset);
  160. }
  161. void omap_ctrl_writew(u16 val, u16 offset)
  162. {
  163. u32 tmp;
  164. u8 byte_offset = offset & 0x2;
  165. tmp = omap_ctrl_readl(offset);
  166. tmp &= 0xffffffff ^ (0xffff << (byte_offset * 8));
  167. tmp |= val << (byte_offset * 8);
  168. omap_ctrl_writel(tmp, offset);
  169. }
  170. void omap_ctrl_writel(u32 val, u16 offset)
  171. {
  172. offset &= 0xfffc;
  173. writel_relaxed(val, omap2_ctrl_base + offset);
  174. }
  175. #ifdef CONFIG_ARCH_OMAP3
  176. /**
  177. * omap3_ctrl_write_boot_mode - set scratchpad boot mode for the next boot
  178. * @bootmode: 8-bit value to pass to some boot code
  179. *
  180. * Set the bootmode in the scratchpad RAM. This is used after the
  181. * system restarts. Not sure what actually uses this - it may be the
  182. * bootloader, rather than the boot ROM - contrary to the preserved
  183. * comment below. No return value.
  184. */
  185. void omap3_ctrl_write_boot_mode(u8 bootmode)
  186. {
  187. u32 l;
  188. l = ('B' << 24) | ('M' << 16) | bootmode;
  189. /*
  190. * Reserve the first word in scratchpad for communicating
  191. * with the boot ROM. A pointer to a data structure
  192. * describing the boot process can be stored there,
  193. * cf. OMAP34xx TRM, Initialization / Software Booting
  194. * Configuration.
  195. *
  196. * XXX This should use some omap_ctrl_writel()-type function
  197. */
  198. writel_relaxed(l, OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD + 4));
  199. }
  200. #endif
  201. /**
  202. * omap_ctrl_write_dsp_boot_addr - set boot address for a remote processor
  203. * @bootaddr: physical address of the boot loader
  204. *
  205. * Set boot address for the boot loader of a supported processor
  206. * when a power ON sequence occurs.
  207. */
  208. void omap_ctrl_write_dsp_boot_addr(u32 bootaddr)
  209. {
  210. u32 offset = cpu_is_omap243x() ? OMAP243X_CONTROL_IVA2_BOOTADDR :
  211. cpu_is_omap34xx() ? OMAP343X_CONTROL_IVA2_BOOTADDR :
  212. cpu_is_omap44xx() ? OMAP4_CTRL_MODULE_CORE_DSP_BOOTADDR :
  213. soc_is_omap54xx() ? OMAP4_CTRL_MODULE_CORE_DSP_BOOTADDR :
  214. 0;
  215. if (!offset) {
  216. pr_err("%s: unsupported omap type\n", __func__);
  217. return;
  218. }
  219. omap_ctrl_writel(bootaddr, offset);
  220. }
  221. /**
  222. * omap_ctrl_write_dsp_boot_mode - set boot mode for a remote processor
  223. * @bootmode: 8-bit value to pass to some boot code
  224. *
  225. * Sets boot mode for the boot loader of a supported processor
  226. * when a power ON sequence occurs.
  227. */
  228. void omap_ctrl_write_dsp_boot_mode(u8 bootmode)
  229. {
  230. u32 offset = cpu_is_omap243x() ? OMAP243X_CONTROL_IVA2_BOOTMOD :
  231. cpu_is_omap34xx() ? OMAP343X_CONTROL_IVA2_BOOTMOD :
  232. 0;
  233. if (!offset) {
  234. pr_err("%s: unsupported omap type\n", __func__);
  235. return;
  236. }
  237. omap_ctrl_writel(bootmode, offset);
  238. }
  239. #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
  240. /*
  241. * Clears the scratchpad contents in case of cold boot-
  242. * called during bootup
  243. */
  244. void omap3_clear_scratchpad_contents(void)
  245. {
  246. u32 max_offset = OMAP343X_SCRATCHPAD_ROM_OFFSET;
  247. void __iomem *v_addr;
  248. u32 offset = 0;
  249. v_addr = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD_ROM);
  250. if (omap3xxx_prm_clear_global_cold_reset()) {
  251. for ( ; offset <= max_offset; offset += 0x4)
  252. writel_relaxed(0x0, (v_addr + offset));
  253. }
  254. }
  255. /* Populate the scratchpad structure with restore structure */
  256. void omap3_save_scratchpad_contents(void)
  257. {
  258. void __iomem *scratchpad_address;
  259. u32 arm_context_addr;
  260. struct omap3_scratchpad scratchpad_contents;
  261. struct omap3_scratchpad_prcm_block prcm_block_contents;
  262. struct omap3_scratchpad_sdrc_block sdrc_block_contents;
  263. /*
  264. * Populate the Scratchpad contents
  265. *
  266. * The "get_*restore_pointer" functions are used to provide a
  267. * physical restore address where the ROM code jumps while waking
  268. * up from MPU OFF/OSWR state.
  269. * The restore pointer is stored into the scratchpad.
  270. */
  271. scratchpad_contents.boot_config_ptr = 0x0;
  272. if (cpu_is_omap3630())
  273. scratchpad_contents.public_restore_ptr =
  274. virt_to_phys(omap3_restore_3630);
  275. else if (omap_rev() != OMAP3430_REV_ES3_0 &&
  276. omap_rev() != OMAP3430_REV_ES3_1 &&
  277. omap_rev() != OMAP3430_REV_ES3_1_2)
  278. scratchpad_contents.public_restore_ptr =
  279. virt_to_phys(omap3_restore);
  280. else
  281. scratchpad_contents.public_restore_ptr =
  282. virt_to_phys(omap3_restore_es3);
  283. if (omap_type() == OMAP2_DEVICE_TYPE_GP)
  284. scratchpad_contents.secure_ram_restore_ptr = 0x0;
  285. else
  286. scratchpad_contents.secure_ram_restore_ptr =
  287. (u32) __pa(omap3_secure_ram_storage);
  288. scratchpad_contents.sdrc_module_semaphore = 0x0;
  289. scratchpad_contents.prcm_block_offset = 0x2C;
  290. scratchpad_contents.sdrc_block_offset = 0x64;
  291. /* Populate the PRCM block contents */
  292. omap3_prm_save_scratchpad_contents(prcm_block_contents.prm_contents);
  293. omap3_cm_save_scratchpad_contents(prcm_block_contents.cm_contents);
  294. prcm_block_contents.prcm_block_size = 0x0;
  295. /* Populate the SDRC block contents */
  296. sdrc_block_contents.sysconfig =
  297. (sdrc_read_reg(SDRC_SYSCONFIG) & 0xFFFF);
  298. sdrc_block_contents.cs_cfg =
  299. (sdrc_read_reg(SDRC_CS_CFG) & 0xFFFF);
  300. sdrc_block_contents.sharing =
  301. (sdrc_read_reg(SDRC_SHARING) & 0xFFFF);
  302. sdrc_block_contents.err_type =
  303. (sdrc_read_reg(SDRC_ERR_TYPE) & 0xFFFF);
  304. sdrc_block_contents.dll_a_ctrl = sdrc_read_reg(SDRC_DLLA_CTRL);
  305. sdrc_block_contents.dll_b_ctrl = 0x0;
  306. /*
  307. * Due to a OMAP3 errata (1.142), on EMU/HS devices SRDC should
  308. * be programed to issue automatic self refresh on timeout
  309. * of AUTO_CNT = 1 prior to any transition to OFF mode.
  310. */
  311. if ((omap_type() != OMAP2_DEVICE_TYPE_GP)
  312. && (omap_rev() >= OMAP3430_REV_ES3_0))
  313. sdrc_block_contents.power = (sdrc_read_reg(SDRC_POWER) &
  314. ~(SDRC_POWER_AUTOCOUNT_MASK|
  315. SDRC_POWER_CLKCTRL_MASK)) |
  316. (1 << SDRC_POWER_AUTOCOUNT_SHIFT) |
  317. SDRC_SELF_REFRESH_ON_AUTOCOUNT;
  318. else
  319. sdrc_block_contents.power = sdrc_read_reg(SDRC_POWER);
  320. sdrc_block_contents.cs_0 = 0x0;
  321. sdrc_block_contents.mcfg_0 = sdrc_read_reg(SDRC_MCFG_0);
  322. sdrc_block_contents.mr_0 = (sdrc_read_reg(SDRC_MR_0) & 0xFFFF);
  323. sdrc_block_contents.emr_1_0 = 0x0;
  324. sdrc_block_contents.emr_2_0 = 0x0;
  325. sdrc_block_contents.emr_3_0 = 0x0;
  326. sdrc_block_contents.actim_ctrla_0 =
  327. sdrc_read_reg(SDRC_ACTIM_CTRL_A_0);
  328. sdrc_block_contents.actim_ctrlb_0 =
  329. sdrc_read_reg(SDRC_ACTIM_CTRL_B_0);
  330. sdrc_block_contents.rfr_ctrl_0 =
  331. sdrc_read_reg(SDRC_RFR_CTRL_0);
  332. sdrc_block_contents.cs_1 = 0x0;
  333. sdrc_block_contents.mcfg_1 = sdrc_read_reg(SDRC_MCFG_1);
  334. sdrc_block_contents.mr_1 = sdrc_read_reg(SDRC_MR_1) & 0xFFFF;
  335. sdrc_block_contents.emr_1_1 = 0x0;
  336. sdrc_block_contents.emr_2_1 = 0x0;
  337. sdrc_block_contents.emr_3_1 = 0x0;
  338. sdrc_block_contents.actim_ctrla_1 =
  339. sdrc_read_reg(SDRC_ACTIM_CTRL_A_1);
  340. sdrc_block_contents.actim_ctrlb_1 =
  341. sdrc_read_reg(SDRC_ACTIM_CTRL_B_1);
  342. sdrc_block_contents.rfr_ctrl_1 =
  343. sdrc_read_reg(SDRC_RFR_CTRL_1);
  344. sdrc_block_contents.dcdl_1_ctrl = 0x0;
  345. sdrc_block_contents.dcdl_2_ctrl = 0x0;
  346. sdrc_block_contents.flags = 0x0;
  347. sdrc_block_contents.block_size = 0x0;
  348. arm_context_addr = virt_to_phys(omap3_arm_context);
  349. /* Copy all the contents to the scratchpad location */
  350. scratchpad_address = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD);
  351. memcpy_toio(scratchpad_address, &scratchpad_contents,
  352. sizeof(scratchpad_contents));
  353. /* Scratchpad contents being 32 bits, a divide by 4 done here */
  354. memcpy_toio(scratchpad_address +
  355. scratchpad_contents.prcm_block_offset,
  356. &prcm_block_contents, sizeof(prcm_block_contents));
  357. memcpy_toio(scratchpad_address +
  358. scratchpad_contents.sdrc_block_offset,
  359. &sdrc_block_contents, sizeof(sdrc_block_contents));
  360. /*
  361. * Copies the address of the location in SDRAM where ARM
  362. * registers get saved during a MPU OFF transition.
  363. */
  364. memcpy_toio(scratchpad_address +
  365. scratchpad_contents.sdrc_block_offset +
  366. sizeof(sdrc_block_contents), &arm_context_addr, 4);
  367. }
  368. void omap3_control_save_context(void)
  369. {
  370. control_context.sysconfig = omap_ctrl_readl(OMAP2_CONTROL_SYSCONFIG);
  371. control_context.devconf0 = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
  372. control_context.mem_dftrw0 =
  373. omap_ctrl_readl(OMAP343X_CONTROL_MEM_DFTRW0);
  374. control_context.mem_dftrw1 =
  375. omap_ctrl_readl(OMAP343X_CONTROL_MEM_DFTRW1);
  376. control_context.msuspendmux_0 =
  377. omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_0);
  378. control_context.msuspendmux_1 =
  379. omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_1);
  380. control_context.msuspendmux_2 =
  381. omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_2);
  382. control_context.msuspendmux_3 =
  383. omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_3);
  384. control_context.msuspendmux_4 =
  385. omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_4);
  386. control_context.msuspendmux_5 =
  387. omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_5);
  388. control_context.sec_ctrl = omap_ctrl_readl(OMAP2_CONTROL_SEC_CTRL);
  389. control_context.devconf1 = omap_ctrl_readl(OMAP343X_CONTROL_DEVCONF1);
  390. control_context.csirxfe = omap_ctrl_readl(OMAP343X_CONTROL_CSIRXFE);
  391. control_context.iva2_bootaddr =
  392. omap_ctrl_readl(OMAP343X_CONTROL_IVA2_BOOTADDR);
  393. control_context.iva2_bootmod =
  394. omap_ctrl_readl(OMAP343X_CONTROL_IVA2_BOOTMOD);
  395. control_context.wkup_ctrl = omap_ctrl_readl(OMAP34XX_CONTROL_WKUP_CTRL);
  396. control_context.debobs_0 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(0));
  397. control_context.debobs_1 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(1));
  398. control_context.debobs_2 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(2));
  399. control_context.debobs_3 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(3));
  400. control_context.debobs_4 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(4));
  401. control_context.debobs_5 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(5));
  402. control_context.debobs_6 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(6));
  403. control_context.debobs_7 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(7));
  404. control_context.debobs_8 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(8));
  405. control_context.prog_io0 = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO0);
  406. control_context.prog_io1 = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO1);
  407. control_context.dss_dpll_spreading =
  408. omap_ctrl_readl(OMAP343X_CONTROL_DSS_DPLL_SPREADING);
  409. control_context.core_dpll_spreading =
  410. omap_ctrl_readl(OMAP343X_CONTROL_CORE_DPLL_SPREADING);
  411. control_context.per_dpll_spreading =
  412. omap_ctrl_readl(OMAP343X_CONTROL_PER_DPLL_SPREADING);
  413. control_context.usbhost_dpll_spreading =
  414. omap_ctrl_readl(OMAP343X_CONTROL_USBHOST_DPLL_SPREADING);
  415. control_context.pbias_lite =
  416. omap_ctrl_readl(OMAP343X_CONTROL_PBIAS_LITE);
  417. control_context.temp_sensor =
  418. omap_ctrl_readl(OMAP343X_CONTROL_TEMP_SENSOR);
  419. control_context.sramldo4 = omap_ctrl_readl(OMAP343X_CONTROL_SRAMLDO4);
  420. control_context.sramldo5 = omap_ctrl_readl(OMAP343X_CONTROL_SRAMLDO5);
  421. control_context.csi = omap_ctrl_readl(OMAP343X_CONTROL_CSI);
  422. control_context.padconf_sys_nirq =
  423. omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_SYSNIRQ);
  424. }
  425. void omap3_control_restore_context(void)
  426. {
  427. omap_ctrl_writel(control_context.sysconfig, OMAP2_CONTROL_SYSCONFIG);
  428. omap_ctrl_writel(control_context.devconf0, OMAP2_CONTROL_DEVCONF0);
  429. omap_ctrl_writel(control_context.mem_dftrw0,
  430. OMAP343X_CONTROL_MEM_DFTRW0);
  431. omap_ctrl_writel(control_context.mem_dftrw1,
  432. OMAP343X_CONTROL_MEM_DFTRW1);
  433. omap_ctrl_writel(control_context.msuspendmux_0,
  434. OMAP2_CONTROL_MSUSPENDMUX_0);
  435. omap_ctrl_writel(control_context.msuspendmux_1,
  436. OMAP2_CONTROL_MSUSPENDMUX_1);
  437. omap_ctrl_writel(control_context.msuspendmux_2,
  438. OMAP2_CONTROL_MSUSPENDMUX_2);
  439. omap_ctrl_writel(control_context.msuspendmux_3,
  440. OMAP2_CONTROL_MSUSPENDMUX_3);
  441. omap_ctrl_writel(control_context.msuspendmux_4,
  442. OMAP2_CONTROL_MSUSPENDMUX_4);
  443. omap_ctrl_writel(control_context.msuspendmux_5,
  444. OMAP2_CONTROL_MSUSPENDMUX_5);
  445. omap_ctrl_writel(control_context.sec_ctrl, OMAP2_CONTROL_SEC_CTRL);
  446. omap_ctrl_writel(control_context.devconf1, OMAP343X_CONTROL_DEVCONF1);
  447. omap_ctrl_writel(control_context.csirxfe, OMAP343X_CONTROL_CSIRXFE);
  448. omap_ctrl_writel(control_context.iva2_bootaddr,
  449. OMAP343X_CONTROL_IVA2_BOOTADDR);
  450. omap_ctrl_writel(control_context.iva2_bootmod,
  451. OMAP343X_CONTROL_IVA2_BOOTMOD);
  452. omap_ctrl_writel(control_context.wkup_ctrl, OMAP34XX_CONTROL_WKUP_CTRL);
  453. omap_ctrl_writel(control_context.debobs_0, OMAP343X_CONTROL_DEBOBS(0));
  454. omap_ctrl_writel(control_context.debobs_1, OMAP343X_CONTROL_DEBOBS(1));
  455. omap_ctrl_writel(control_context.debobs_2, OMAP343X_CONTROL_DEBOBS(2));
  456. omap_ctrl_writel(control_context.debobs_3, OMAP343X_CONTROL_DEBOBS(3));
  457. omap_ctrl_writel(control_context.debobs_4, OMAP343X_CONTROL_DEBOBS(4));
  458. omap_ctrl_writel(control_context.debobs_5, OMAP343X_CONTROL_DEBOBS(5));
  459. omap_ctrl_writel(control_context.debobs_6, OMAP343X_CONTROL_DEBOBS(6));
  460. omap_ctrl_writel(control_context.debobs_7, OMAP343X_CONTROL_DEBOBS(7));
  461. omap_ctrl_writel(control_context.debobs_8, OMAP343X_CONTROL_DEBOBS(8));
  462. omap_ctrl_writel(control_context.prog_io0, OMAP343X_CONTROL_PROG_IO0);
  463. omap_ctrl_writel(control_context.prog_io1, OMAP343X_CONTROL_PROG_IO1);
  464. omap_ctrl_writel(control_context.dss_dpll_spreading,
  465. OMAP343X_CONTROL_DSS_DPLL_SPREADING);
  466. omap_ctrl_writel(control_context.core_dpll_spreading,
  467. OMAP343X_CONTROL_CORE_DPLL_SPREADING);
  468. omap_ctrl_writel(control_context.per_dpll_spreading,
  469. OMAP343X_CONTROL_PER_DPLL_SPREADING);
  470. omap_ctrl_writel(control_context.usbhost_dpll_spreading,
  471. OMAP343X_CONTROL_USBHOST_DPLL_SPREADING);
  472. omap_ctrl_writel(control_context.pbias_lite,
  473. OMAP343X_CONTROL_PBIAS_LITE);
  474. omap_ctrl_writel(control_context.temp_sensor,
  475. OMAP343X_CONTROL_TEMP_SENSOR);
  476. omap_ctrl_writel(control_context.sramldo4, OMAP343X_CONTROL_SRAMLDO4);
  477. omap_ctrl_writel(control_context.sramldo5, OMAP343X_CONTROL_SRAMLDO5);
  478. omap_ctrl_writel(control_context.csi, OMAP343X_CONTROL_CSI);
  479. omap_ctrl_writel(control_context.padconf_sys_nirq,
  480. OMAP343X_CONTROL_PADCONF_SYSNIRQ);
  481. }
  482. void omap3630_ctrl_disable_rta(void)
  483. {
  484. if (!cpu_is_omap3630())
  485. return;
  486. omap_ctrl_writel(OMAP36XX_RTA_DISABLE, OMAP36XX_CONTROL_MEM_RTA_CTRL);
  487. }
  488. /**
  489. * omap3_ctrl_save_padconf - save padconf registers to scratchpad RAM
  490. *
  491. * Tell the SCM to start saving the padconf registers, then wait for
  492. * the process to complete. Returns 0 unconditionally, although it
  493. * should also eventually be able to return -ETIMEDOUT, if the save
  494. * does not complete.
  495. *
  496. * XXX This function is missing a timeout. What should it be?
  497. */
  498. int omap3_ctrl_save_padconf(void)
  499. {
  500. u32 cpo;
  501. /* Save the padconf registers */
  502. cpo = omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_OFF);
  503. cpo |= START_PADCONF_SAVE;
  504. omap_ctrl_writel(cpo, OMAP343X_CONTROL_PADCONF_OFF);
  505. /* wait for the save to complete */
  506. while (!(omap_ctrl_readl(OMAP343X_CONTROL_GENERAL_PURPOSE_STATUS)
  507. & PADCONF_SAVE_DONE))
  508. udelay(1);
  509. return 0;
  510. }
  511. /**
  512. * omap3_ctrl_set_iva_bootmode_idle - sets the IVA2 bootmode to idle
  513. *
  514. * Sets the bootmode for IVA2 to idle. This is needed by the PM code to
  515. * force disable IVA2 so that it does not prevent any low-power states.
  516. */
  517. static void __init omap3_ctrl_set_iva_bootmode_idle(void)
  518. {
  519. omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE,
  520. OMAP343X_CONTROL_IVA2_BOOTMOD);
  521. }
  522. /**
  523. * omap3_ctrl_setup_d2d_padconf - setup stacked modem pads for idle
  524. *
  525. * Sets up the pads controlling the stacked modem in such way that the
  526. * device can enter idle.
  527. */
  528. static void __init omap3_ctrl_setup_d2d_padconf(void)
  529. {
  530. u16 mask, padconf;
  531. /*
  532. * In a stand alone OMAP3430 where there is not a stacked
  533. * modem for the D2D Idle Ack and D2D MStandby must be pulled
  534. * high. S CONTROL_PADCONF_SAD2D_IDLEACK and
  535. * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up.
  536. */
  537. mask = (1 << 4) | (1 << 3); /* pull-up, enabled */
  538. padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY);
  539. padconf |= mask;
  540. omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_MSTANDBY);
  541. padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK);
  542. padconf |= mask;
  543. omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_IDLEACK);
  544. }
  545. /**
  546. * omap3_ctrl_init - does static initializations for control module
  547. *
  548. * Initializes system control module. This sets up the sysconfig autoidle,
  549. * and sets up modem and iva2 so that they can be idled properly.
  550. */
  551. void __init omap3_ctrl_init(void)
  552. {
  553. omap_ctrl_writel(OMAP3430_AUTOIDLE_MASK, OMAP2_CONTROL_SYSCONFIG);
  554. omap3_ctrl_set_iva_bootmode_idle();
  555. omap3_ctrl_setup_d2d_padconf();
  556. }
  557. #endif /* CONFIG_ARCH_OMAP3 && CONFIG_PM */
  558. struct control_init_data {
  559. int index;
  560. s16 offset;
  561. };
  562. static struct control_init_data ctrl_data = {
  563. .index = TI_CLKM_CTRL,
  564. };
  565. static const struct control_init_data omap2_ctrl_data = {
  566. .index = TI_CLKM_CTRL,
  567. .offset = -OMAP2_CONTROL_GENERAL,
  568. };
  569. static const struct of_device_id omap_scrm_dt_match_table[] = {
  570. { .compatible = "ti,am3-scm", .data = &ctrl_data },
  571. { .compatible = "ti,am4-scm", .data = &ctrl_data },
  572. { .compatible = "ti,omap2-scm", .data = &omap2_ctrl_data },
  573. { .compatible = "ti,omap3-scm", .data = &omap2_ctrl_data },
  574. { .compatible = "ti,dm814-scm", .data = &ctrl_data },
  575. { .compatible = "ti,dm816-scrm", .data = &ctrl_data },
  576. { .compatible = "ti,omap4-scm-core", .data = &ctrl_data },
  577. { .compatible = "ti,omap5-scm-core", .data = &ctrl_data },
  578. { .compatible = "ti,dra7-scm-core", .data = &ctrl_data },
  579. { }
  580. };
  581. /**
  582. * omap2_control_base_init - initialize iomappings for the control driver
  583. *
  584. * Detects and initializes the iomappings for the control driver, based
  585. * on the DT data. Returns 0 in success, negative error value
  586. * otherwise.
  587. */
  588. int __init omap2_control_base_init(void)
  589. {
  590. struct device_node *np;
  591. const struct of_device_id *match;
  592. struct control_init_data *data;
  593. for_each_matching_node_and_match(np, omap_scrm_dt_match_table, &match) {
  594. data = (struct control_init_data *)match->data;
  595. omap2_ctrl_base = of_iomap(np, 0);
  596. if (!omap2_ctrl_base)
  597. return -ENOMEM;
  598. omap2_ctrl_offset = data->offset;
  599. }
  600. return 0;
  601. }
  602. /**
  603. * omap_control_init - low level init for the control driver
  604. *
  605. * Initializes the low level clock infrastructure for control driver.
  606. * Returns 0 in success, negative error value in failure.
  607. */
  608. int __init omap_control_init(void)
  609. {
  610. struct device_node *np, *scm_conf;
  611. const struct of_device_id *match;
  612. const struct omap_prcm_init_data *data;
  613. int ret;
  614. struct regmap *syscon;
  615. for_each_matching_node_and_match(np, omap_scrm_dt_match_table, &match) {
  616. data = match->data;
  617. /*
  618. * Check if we have scm_conf node, if yes, use this to
  619. * access clock registers.
  620. */
  621. scm_conf = of_get_child_by_name(np, "scm_conf");
  622. if (scm_conf) {
  623. syscon = syscon_node_to_regmap(scm_conf);
  624. if (IS_ERR(syscon))
  625. return PTR_ERR(syscon);
  626. if (of_get_child_by_name(scm_conf, "clocks")) {
  627. ret = omap2_clk_provider_init(scm_conf,
  628. data->index,
  629. syscon, NULL);
  630. if (ret)
  631. return ret;
  632. }
  633. } else {
  634. /* No scm_conf found, direct access */
  635. ret = omap2_clk_provider_init(np, data->index, NULL,
  636. omap2_ctrl_base);
  637. if (ret)
  638. return ret;
  639. }
  640. }
  641. return 0;
  642. }
  643. /**
  644. * omap3_control_legacy_iomap_init - legacy iomap init for clock providers
  645. *
  646. * Legacy iomap init for clock provider. Needed only by legacy boot mode,
  647. * where the base addresses are not parsed from DT, but still required
  648. * by the clock driver to be setup properly.
  649. */
  650. void __init omap3_control_legacy_iomap_init(void)
  651. {
  652. omap2_clk_legacy_provider_init(TI_CLKM_SCRM, omap2_ctrl_base);
  653. }