connectTheSignalSlot.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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 "soc.h"
  17. #include "iomap.h"
  18. #include "common.h"
  19. #include "cm-regbits-34xx.h"
  20. #include "prm-regbits-34xx.h"
  21. #include "prm3xxx.h"
  22. #include "cm3xxx.h"
  23. #include "sdrc.h"
  24. #include "pm.h"
  25. #include "control.h"
  26. /* Used by omap3_ctrl_save_padconf() */
  27. #define START_PADCONF_SAVE 0x2
  28. #define PADCONF_SAVE_DONE 0x1
  29. static void __iomem *omap2_ctrl_base;
  30. static void __iomem *omap4_ctrl_pad_base;
  31. #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
  32. struct omap3_scratchpad {
  33. u32 boot_config_ptr;
  34. u32 public_restore_ptr;
  35. u32 secure_ram_restore_ptr;
  36. u32 sdrc_module_semaphore;
  37. u32 prcm_block_offset;
  38. u32 sdrc_block_offset;
  39. };
  40. struct omap3_scratchpad_prcm_block {
  41. u32 prm_clksrc_ctrl;
  42. u32 prm_clksel;
  43. u32 cm_clksel_core;
  44. u32 cm_clksel_wkup;
  45. u32 cm_clken_pll;
  46. u32 cm_autoidle_pll;
  47. u32 cm_clksel1_pll;
  48. u32 cm_clksel2_pll;
  49. u32 cm_clksel3_pll;
  50. u32 cm_clken_pll_mpu;
  51. u32 cm_autoidle_pll_mpu;
  52. u32 cm_clksel1_pll_mpu;
  53. u32 cm_clksel2_pll_mpu;
  54. u32 prcm_block_size;
  55. };
  56. struct omap3_scratchpad_sdrc_block {
  57. u16 sysconfig;
  58. u16 cs_cfg;
  59. u16 sharing;
  60. u16 err_type;
  61. u32 dll_a_ctrl;
  62. u32 dll_b_ctrl;
  63. u32 power;
  64. u32 cs_0;
  65. u32 mcfg_0;
  66. u16 mr_0;
  67. u16 emr_1_0;
  68. u16 emr_2_0;
  69. u16 emr_3_0;
  70. u32 actim_ctrla_0;
  71. u32 actim_ctrlb_0;
  72. u32 rfr_ctrl_0;
  73. u32 cs_1;
  74. u32 mcfg_1;
  75. u16 mr_1;
  76. u16 emr_1_1;
  77. u16 emr_2_1;
  78. u16 emr_3_1;
  79. u32 actim_ctrla_1;
  80. u32 actim_ctrlb_1;
  81. u32 rfr_ctrl_1;
  82. u16 dcdl_1_ctrl;
  83. u16 dcdl_2_ctrl;
  84. u32 flags;
  85. u32 block_size;
  86. };
  87. void *omap3_secure_ram_storage;
  88. /*
  89. * This is used to store ARM registers in SDRAM before attempting
  90. * an MPU OFF. The save and restore happens from the SRAM sleep code.
  91. * The address is stored in scratchpad, so that it can be used
  92. * during the restore path.
  93. */
  94. u32 omap3_arm_context[128];
  95. struct omap3_control_regs {
  96. u32 sysconfig;
  97. u32 devconf0;
  98. u32 mem_dftrw0;
  99. u32 mem_dftrw1;
  100. u32 msuspendmux_0;
  101. u32 msuspendmux_1;
  102. u32 msuspendmux_2;
  103. u32 msuspendmux_3;
  104. u32 msuspendmux_4;
  105. u32 msuspendmux_5;
  106. u32 sec_ctrl;
  107. u32 devconf1;
  108. u32 csirxfe;
  109. u32 iva2_bootaddr;
  110. u32 iva2_bootmod;
  111. u32 debobs_0;
  112. u32 debobs_1;
  113. u32 debobs_2;
  114. u32 debobs_3;
  115. u32 debobs_4;
  116. u32 debobs_5;
  117. u32 debobs_6;
  118. u32 debobs_7;
  119. u32 debobs_8;
  120. u32 prog_io0;
  121. u32 prog_io1;
  122. u32 dss_dpll_spreading;
  123. u32 core_dpll_spreading;
  124. u32 per_dpll_spreading;
  125. u32 usbhost_dpll_spreading;
  126. u32 pbias_lite;
  127. u32 temp_sensor;
  128. u32 sramldo4;
  129. u32 sramldo5;
  130. u32 csi;
  131. u32 padconf_sys_nirq;
  132. };
  133. static struct omap3_control_regs control_context;
  134. #endif /* CONFIG_ARCH_OMAP3 && CONFIG_PM */
  135. #define OMAP_CTRL_REGADDR(reg) (omap2_ctrl_base + (reg))
  136. #define OMAP4_CTRL_PAD_REGADDR(reg) (omap4_ctrl_pad_base + (reg))
  137. void __init omap2_set_globals_control(void __iomem *ctrl,
  138. void __iomem *ctrl_pad)
  139. {
  140. omap2_ctrl_base = ctrl;
  141. omap4_ctrl_pad_base = ctrl_pad;
  142. }
  143. void __iomem *omap_ctrl_base_get(void)
  144. {
  145. return omap2_ctrl_base;
  146. }
  147. u8 omap_ctrl_readb(u16 offset)
  148. {
  149. return __raw_readb(OMAP_CTRL_REGADDR(offset));
  150. }
  151. u16 omap_ctrl_readw(u16 offset)
  152. {
  153. return __raw_readw(OMAP_CTRL_REGADDR(offset));
  154. }
  155. u32 omap_ctrl_readl(u16 offset)
  156. {
  157. return __raw_readl(OMAP_CTRL_REGADDR(offset));
  158. }
  159. void omap_ctrl_writeb(u8 val, u16 offset)
  160. {
  161. __raw_writeb(val, OMAP_CTRL_REGADDR(offset));
  162. }
  163. void omap_ctrl_writew(u16 val, u16 offset)
  164. {
  165. __raw_writew(val, OMAP_CTRL_REGADDR(offset));
  166. }
  167. void omap_ctrl_writel(u32 val, u16 offset)
  168. {
  169. __raw_writel(val, OMAP_CTRL_REGADDR(offset));
  170. }
  171. /*
  172. * On OMAP4 control pad are not addressable from control
  173. * core base. So the common omap_ctrl_read/write APIs breaks
  174. * Hence export separate APIs to manage the omap4 pad control
  175. * registers. This APIs will work only for OMAP4
  176. */
  177. u32 omap4_ctrl_pad_readl(u16 offset)
  178. {
  179. return __raw_readl(OMAP4_CTRL_PAD_REGADDR(offset));
  180. }
  181. void omap4_ctrl_pad_writel(u32 val, u16 offset)
  182. {
  183. __raw_writel(val, OMAP4_CTRL_PAD_REGADDR(offset));
  184. }
  185. #ifdef CONFIG_ARCH_OMAP3
  186. /**
  187. * omap3_ctrl_write_boot_mode - set scratchpad boot mode for the next boot
  188. * @bootmode: 8-bit value to pass to some boot code
  189. *
  190. * Set the bootmode in the scratchpad RAM. This is used after the
  191. * system restarts. Not sure what actually uses this - it may be the
  192. * bootloader, rather than the boot ROM - contrary to the preserved
  193. * comment below. No return value.
  194. */
  195. void omap3_ctrl_write_boot_mode(u8 bootmode)
  196. {
  197. u32 l;
  198. l = ('B' << 24) | ('M' << 16) | bootmode;
  199. /*
  200. * Reserve the first word in scratchpad for communicating
  201. * with the boot ROM. A pointer to a data structure
  202. * describing the boot process can be stored there,
  203. * cf. OMAP34xx TRM, Initialization / Software Booting
  204. * Configuration.
  205. *
  206. * XXX This should use some omap_ctrl_writel()-type function
  207. */
  208. __raw_writel(l, OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD + 4));
  209. }
  210. #endif
  211. /**
  212. * omap_ctrl_write_dsp_boot_addr - set boot address for a remote processor
  213. * @bootaddr: physical address of the boot loader
  214. *
  215. * Set boot address for the boot loader of a supported processor
  216. * when a power ON sequence occurs.
  217. */
  218. void omap_ctrl_write_dsp_boot_addr(u32 bootaddr)
  219. {
  220. u32 offset = cpu_is_omap243x() ? OMAP243X_CONTROL_IVA2_BOOTADDR :
  221. cpu_is_omap34xx() ? OMAP343X_CONTROL_IVA2_BOOTADDR :
  222. cpu_is_omap44xx() ? OMAP4_CTRL_MODULE_CORE_DSP_BOOTADDR :
  223. 0;
  224. if (!offset) {
  225. pr_err("%s: unsupported omap type\n", __func__);
  226. return;
  227. }
  228. omap_ctrl_writel(bootaddr, offset);
  229. }
  230. /**
  231. * omap_ctrl_write_dsp_boot_mode - set boot mode for a remote processor
  232. * @bootmode: 8-bit value to pass to some boot code
  233. *
  234. * Sets boot mode for the boot loader of a supported processor
  235. * when a power ON sequence occurs.
  236. */
  237. void omap_ctrl_write_dsp_boot_mode(u8 bootmode)
  238. {
  239. u32 offset = cpu_is_omap243x() ? OMAP243X_CONTROL_IVA2_BOOTMOD :
  240. cpu_is_omap34xx() ? OMAP343X_CONTROL_IVA2_BOOTMOD :
  241. 0;
  242. if (!offset) {
  243. pr_err("%s: unsupported omap type\n", __func__);
  244. return;
  245. }
  246. omap_ctrl_writel(bootmode, offset);
  247. }
  248. #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
  249. /*
  250. * Clears the scratchpad contents in case of cold boot-
  251. * called during bootup
  252. */
  253. void omap3_clear_scratchpad_contents(void)
  254. {
  255. u32 max_offset = OMAP343X_SCRATCHPAD_ROM_OFFSET;
  256. void __iomem *v_addr;
  257. u32 offset = 0;
  258. v_addr = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD_ROM);
  259. if (omap2_prm_read_mod_reg(OMAP3430_GR_MOD, OMAP3_PRM_RSTST_OFFSET) &
  260. OMAP3430_GLOBAL_COLD_RST_MASK) {
  261. for ( ; offset <= max_offset; offset += 0x4)
  262. __raw_writel(0x0, (v_addr + offset));
  263. omap2_prm_set_mod_reg_bits(OMAP3430_GLOBAL_COLD_RST_MASK,
  264. OMAP3430_GR_MOD,
  265. OMAP3_PRM_RSTST_OFFSET);
  266. }
  267. }
  268. /* Populate the scratchpad structure with restore structure */
  269. void omap3_save_scratchpad_contents(void)
  270. {
  271. void __iomem *scratchpad_address;
  272. u32 arm_context_addr;
  273. struct omap3_scratchpad scratchpad_contents;
  274. struct omap3_scratchpad_prcm_block prcm_block_contents;
  275. struct omap3_scratchpad_sdrc_block sdrc_block_contents;
  276. /*
  277. * Populate the Scratchpad contents
  278. *
  279. * The "get_*restore_pointer" functions are used to provide a
  280. * physical restore address where the ROM code jumps while waking
  281. * up from MPU OFF/OSWR state.
  282. * The restore pointer is stored into the scratchpad.
  283. */
  284. scratchpad_contents.boot_config_ptr = 0x0;
  285. if (cpu_is_omap3630())
  286. scratchpad_contents.public_restore_ptr =
  287. virt_to_phys(omap3_restore_3630);
  288. else if (omap_rev() != OMAP3430_REV_ES3_0 &&
  289. omap_rev() != OMAP3430_REV_ES3_1)
  290. scratchpad_contents.public_restore_ptr =
  291. virt_to_phys(omap3_restore);
  292. else
  293. scratchpad_contents.public_restore_ptr =
  294. virt_to_phys(omap3_restore_es3);
  295. if (omap_type() == OMAP2_DEVICE_TYPE_GP)
  296. scratchpad_contents.secure_ram_restore_ptr = 0x0;
  297. else
  298. scratchpad_contents.secure_ram_restore_ptr =
  299. (u32) __pa(omap3_secure_ram_storage);
  300. scratchpad_contents.sdrc_module_semaphore = 0x0;
  301. scratchpad_contents.prcm_block_offset = 0x2C;
  302. scratchpad_contents.sdrc_block_offset = 0x64;
  303. /* Populate the PRCM block contents */
  304. prcm_block_contents.prm_clksrc_ctrl =
  305. omap2_prm_read_mod_reg(OMAP3430_GR_MOD,
  306. OMAP3_PRM_CLKSRC_CTRL_OFFSET);
  307. prcm_block_contents.prm_clksel =
  308. omap2_prm_read_mod_reg(OMAP3430_CCR_MOD,
  309. OMAP3_PRM_CLKSEL_OFFSET);
  310. prcm_block_contents.cm_clksel_core =
  311. omap2_cm_read_mod_reg(CORE_MOD, CM_CLKSEL);
  312. prcm_block_contents.cm_clksel_wkup =
  313. omap2_cm_read_mod_reg(WKUP_MOD, CM_CLKSEL);
  314. prcm_block_contents.cm_clken_pll =
  315. omap2_cm_read_mod_reg(PLL_MOD, CM_CLKEN);
  316. /*
  317. * As per erratum i671, ROM code does not respect the PER DPLL
  318. * programming scheme if CM_AUTOIDLE_PLL..AUTO_PERIPH_DPLL == 1.
  319. * Then, in anycase, clear these bits to avoid extra latencies.
  320. */
  321. prcm_block_contents.cm_autoidle_pll =
  322. omap2_cm_read_mod_reg(PLL_MOD, CM_AUTOIDLE) &
  323. ~OMAP3430_AUTO_PERIPH_DPLL_MASK;
  324. prcm_block_contents.cm_clksel1_pll =
  325. omap2_cm_read_mod_reg(PLL_MOD, OMAP3430_CM_CLKSEL1_PLL);
  326. prcm_block_contents.cm_clksel2_pll =
  327. omap2_cm_read_mod_reg(PLL_MOD, OMAP3430_CM_CLKSEL2_PLL);
  328. prcm_block_contents.cm_clksel3_pll =
  329. omap2_cm_read_mod_reg(PLL_MOD, OMAP3430_CM_CLKSEL3);
  330. prcm_block_contents.cm_clken_pll_mpu =
  331. omap2_cm_read_mod_reg(MPU_MOD, OMAP3430_CM_CLKEN_PLL);
  332. prcm_block_contents.cm_autoidle_pll_mpu =
  333. omap2_cm_read_mod_reg(MPU_MOD, OMAP3430_CM_AUTOIDLE_PLL);
  334. prcm_block_contents.cm_clksel1_pll_mpu =
  335. omap2_cm_read_mod_reg(MPU_MOD, OMAP3430_CM_CLKSEL1_PLL);
  336. prcm_block_contents.cm_clksel2_pll_mpu =
  337. omap2_cm_read_mod_reg(MPU_MOD, OMAP3430_CM_CLKSEL2_PLL);
  338. prcm_block_contents.prcm_block_size = 0x0;
  339. /* Populate the SDRC block contents */
  340. sdrc_block_contents.sysconfig =
  341. (sdrc_read_reg(SDRC_SYSCONFIG) & 0xFFFF);
  342. sdrc_block_contents.cs_cfg =
  343. (sdrc_read_reg(SDRC_CS_CFG) & 0xFFFF);
  344. sdrc_block_contents.sharing =
  345. (sdrc_read_reg(SDRC_SHARING) & 0xFFFF);
  346. sdrc_block_contents.err_type =
  347. (sdrc_read_reg(SDRC_ERR_TYPE) & 0xFFFF);
  348. sdrc_block_contents.dll_a_ctrl = sdrc_read_reg(SDRC_DLLA_CTRL);
  349. sdrc_block_contents.dll_b_ctrl = 0x0;
  350. /*
  351. * Due to a OMAP3 errata (1.142), on EMU/HS devices SRDC should
  352. * be programed to issue automatic self refresh on timeout
  353. * of AUTO_CNT = 1 prior to any transition to OFF mode.
  354. */
  355. if ((omap_type() != OMAP2_DEVICE_TYPE_GP)
  356. && (omap_rev() >= OMAP3430_REV_ES3_0))
  357. sdrc_block_contents.power = (sdrc_read_reg(SDRC_POWER) &
  358. ~(SDRC_POWER_AUTOCOUNT_MASK|
  359. SDRC_POWER_CLKCTRL_MASK)) |
  360. (1 << SDRC_POWER_AUTOCOUNT_SHIFT) |
  361. SDRC_SELF_REFRESH_ON_AUTOCOUNT;
  362. else
  363. sdrc_block_contents.power = sdrc_read_reg(SDRC_POWER);
  364. sdrc_block_contents.cs_0 = 0x0;
  365. sdrc_block_contents.mcfg_0 = sdrc_read_reg(SDRC_MCFG_0);
  366. sdrc_block_contents.mr_0 = (sdrc_read_reg(SDRC_MR_0) & 0xFFFF);
  367. sdrc_block_contents.emr_1_0 = 0x0;
  368. sdrc_block_contents.emr_2_0 = 0x0;
  369. sdrc_block_contents.emr_3_0 = 0x0;
  370. sdrc_block_contents.actim_ctrla_0 =
  371. sdrc_read_reg(SDRC_ACTIM_CTRL_A_0);
  372. sdrc_block_contents.actim_ctrlb_0 =
  373. sdrc_read_reg(SDRC_ACTIM_CTRL_B_0);
  374. sdrc_block_contents.rfr_ctrl_0 =
  375. sdrc_read_reg(SDRC_RFR_CTRL_0);
  376. sdrc_block_contents.cs_1 = 0x0;
  377. sdrc_block_contents.mcfg_1 = sdrc_read_reg(SDRC_MCFG_1);
  378. sdrc_block_contents.mr_1 = sdrc_read_reg(SDRC_MR_1) & 0xFFFF;
  379. sdrc_block_contents.emr_1_1 = 0x0;
  380. sdrc_block_contents.emr_2_1 = 0x0;
  381. sdrc_block_contents.emr_3_1 = 0x0;
  382. sdrc_block_contents.actim_ctrla_1 =
  383. sdrc_read_reg(SDRC_ACTIM_CTRL_A_1);
  384. sdrc_block_contents.actim_ctrlb_1 =
  385. sdrc_read_reg(SDRC_ACTIM_CTRL_B_1);
  386. sdrc_block_contents.rfr_ctrl_1 =