prm3xxx.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /*
  2. * OMAP3xxx PRM module functions
  3. *
  4. * Copyright (C) 2010-2012 Texas Instruments, Inc.
  5. * Copyright (C) 2010 Nokia Corporation
  6. * Benoît Cousson
  7. * Paul Walmsley
  8. * Rajendra Nayak <rnayak@ti.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/errno.h>
  16. #include <linux/err.h>
  17. #include <linux/io.h>
  18. #include <linux/irq.h>
  19. #include <linux/of_irq.h>
  20. #include "soc.h"
  21. #include "common.h"
  22. #include "vp.h"
  23. #include "powerdomain.h"
  24. #include "prm3xxx.h"
  25. #include "prm2xxx_3xxx.h"
  26. #include "cm2xxx_3xxx.h"
  27. #include "prm-regbits-34xx.h"
  28. #include "cm3xxx.h"
  29. #include "cm-regbits-34xx.h"
  30. #include "clock.h"
  31. static void omap3xxx_prm_read_pending_irqs(unsigned long *events);
  32. static void omap3xxx_prm_ocp_barrier(void);
  33. static void omap3xxx_prm_save_and_clear_irqen(u32 *saved_mask);
  34. static void omap3xxx_prm_restore_irqen(u32 *saved_mask);
  35. static const struct omap_prcm_irq omap3_prcm_irqs[] = {
  36. OMAP_PRCM_IRQ("wkup", 0, 0),
  37. OMAP_PRCM_IRQ("io", 9, 1),
  38. };
  39. static struct omap_prcm_irq_setup omap3_prcm_irq_setup = {
  40. .ack = OMAP3_PRM_IRQSTATUS_MPU_OFFSET,
  41. .mask = OMAP3_PRM_IRQENABLE_MPU_OFFSET,
  42. .nr_regs = 1,
  43. .irqs = omap3_prcm_irqs,
  44. .nr_irqs = ARRAY_SIZE(omap3_prcm_irqs),
  45. .irq = 11 + OMAP_INTC_START,
  46. .read_pending_irqs = &omap3xxx_prm_read_pending_irqs,
  47. .ocp_barrier = &omap3xxx_prm_ocp_barrier,
  48. .save_and_clear_irqen = &omap3xxx_prm_save_and_clear_irqen,
  49. .restore_irqen = &omap3xxx_prm_restore_irqen,
  50. .reconfigure_io_chain = NULL,
  51. };
  52. /*
  53. * omap3_prm_reset_src_map - map from bits in the PRM_RSTST hardware
  54. * register (which are specific to OMAP3xxx SoCs) to reset source ID
  55. * bit shifts (which is an OMAP SoC-independent enumeration)
  56. */
  57. static struct prm_reset_src_map omap3xxx_prm_reset_src_map[] = {
  58. { OMAP3430_GLOBAL_COLD_RST_SHIFT, OMAP_GLOBAL_COLD_RST_SRC_ID_SHIFT },
  59. { OMAP3430_GLOBAL_SW_RST_SHIFT, OMAP_GLOBAL_WARM_RST_SRC_ID_SHIFT },
  60. { OMAP3430_SECURITY_VIOL_RST_SHIFT, OMAP_SECU_VIOL_RST_SRC_ID_SHIFT },
  61. { OMAP3430_MPU_WD_RST_SHIFT, OMAP_MPU_WD_RST_SRC_ID_SHIFT },
  62. { OMAP3430_SECURE_WD_RST_SHIFT, OMAP_MPU_WD_RST_SRC_ID_SHIFT },
  63. { OMAP3430_EXTERNAL_WARM_RST_SHIFT, OMAP_EXTWARM_RST_SRC_ID_SHIFT },
  64. { OMAP3430_VDD1_VOLTAGE_MANAGER_RST_SHIFT,
  65. OMAP_VDD_MPU_VM_RST_SRC_ID_SHIFT },
  66. { OMAP3430_VDD2_VOLTAGE_MANAGER_RST_SHIFT,
  67. OMAP_VDD_CORE_VM_RST_SRC_ID_SHIFT },
  68. { OMAP3430_ICEPICK_RST_SHIFT, OMAP_ICEPICK_RST_SRC_ID_SHIFT },
  69. { OMAP3430_ICECRUSHER_RST_SHIFT, OMAP_ICECRUSHER_RST_SRC_ID_SHIFT },
  70. { -1, -1 },
  71. };
  72. /* PRM VP */
  73. /*
  74. * struct omap3_vp - OMAP3 VP register access description.
  75. * @tranxdone_status: VP_TRANXDONE_ST bitmask in PRM_IRQSTATUS_MPU reg
  76. */
  77. struct omap3_vp {
  78. u32 tranxdone_status;
  79. };
  80. static struct omap3_vp omap3_vp[] = {
  81. [OMAP3_VP_VDD_MPU_ID] = {
  82. .tranxdone_status = OMAP3430_VP1_TRANXDONE_ST_MASK,
  83. },
  84. [OMAP3_VP_VDD_CORE_ID] = {
  85. .tranxdone_status = OMAP3430_VP2_TRANXDONE_ST_MASK,
  86. },
  87. };
  88. #define MAX_VP_ID ARRAY_SIZE(omap3_vp);
  89. static u32 omap3_prm_vp_check_txdone(u8 vp_id)
  90. {
  91. struct omap3_vp *vp = &omap3_vp[vp_id];
  92. u32 irqstatus;
  93. irqstatus = omap2_prm_read_mod_reg(OCP_MOD,
  94. OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
  95. return irqstatus & vp->tranxdone_status;
  96. }
  97. static void omap3_prm_vp_clear_txdone(u8 vp_id)
  98. {
  99. struct omap3_vp *vp = &omap3_vp[vp_id];
  100. omap2_prm_write_mod_reg(vp->tranxdone_status,
  101. OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
  102. }
  103. u32 omap3_prm_vcvp_read(u8 offset)
  104. {
  105. return omap2_prm_read_mod_reg(OMAP3430_GR_MOD, offset);
  106. }
  107. void omap3_prm_vcvp_write(u32 val, u8 offset)
  108. {
  109. omap2_prm_write_mod_reg(val, OMAP3430_GR_MOD, offset);
  110. }
  111. u32 omap3_prm_vcvp_rmw(u32 mask, u32 bits, u8 offset)
  112. {
  113. return omap2_prm_rmw_mod_reg_bits(mask, bits, OMAP3430_GR_MOD, offset);
  114. }
  115. /**
  116. * omap3xxx_prm_dpll3_reset - use DPLL3 reset to reboot the OMAP SoC
  117. *
  118. * Set the DPLL3 reset bit, which should reboot the SoC. This is the
  119. * recommended way to restart the SoC, considering Errata i520. No
  120. * return value.
  121. */
  122. static void omap3xxx_prm_dpll3_reset(void)
  123. {
  124. omap2_prm_set_mod_reg_bits(OMAP_RST_DPLL3_MASK, OMAP3430_GR_MOD,
  125. OMAP2_RM_RSTCTRL);
  126. /* OCP barrier */
  127. omap2_prm_read_mod_reg(OMAP3430_GR_MOD, OMAP2_RM_RSTCTRL);
  128. }
  129. /**
  130. * omap3xxx_prm_read_pending_irqs - read pending PRM MPU IRQs into @events
  131. * @events: ptr to a u32, preallocated by caller
  132. *
  133. * Read PRM_IRQSTATUS_MPU bits, AND'ed with the currently-enabled PRM
  134. * MPU IRQs, and store the result into the u32 pointed to by @events.
  135. * No return value.
  136. */
  137. static void omap3xxx_prm_read_pending_irqs(unsigned long *events)
  138. {
  139. u32 mask, st;
  140. /* XXX Can the mask read be avoided (e.g., can it come from RAM?) */
  141. mask = omap2_prm_read_mod_reg(OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET);
  142. st = omap2_prm_read_mod_reg(OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
  143. events[0] = mask & st;
  144. }
  145. /**
  146. * omap3xxx_prm_ocp_barrier - force buffered MPU writes to the PRM to complete
  147. *
  148. * Force any buffered writes to the PRM IP block to complete. Needed
  149. * by the PRM IRQ handler, which reads and writes directly to the IP
  150. * block, to avoid race conditions after acknowledging or clearing IRQ
  151. * bits. No return value.
  152. */
  153. static void omap3xxx_prm_ocp_barrier(void)
  154. {
  155. omap2_prm_read_mod_reg(OCP_MOD, OMAP3_PRM_REVISION_OFFSET);
  156. }
  157. /**
  158. * omap3xxx_prm_save_and_clear_irqen - save/clear PRM_IRQENABLE_MPU reg
  159. * @saved_mask: ptr to a u32 array to save IRQENABLE bits
  160. *
  161. * Save the PRM_IRQENABLE_MPU register to @saved_mask. @saved_mask
  162. * must be allocated by the caller. Intended to be used in the PRM
  163. * interrupt handler suspend callback. The OCP barrier is needed to
  164. * ensure the write to disable PRM interrupts reaches the PRM before
  165. * returning; otherwise, spurious interrupts might occur. No return
  166. * value.
  167. */
  168. static void omap3xxx_prm_save_and_clear_irqen(u32 *saved_mask)
  169. {
  170. saved_mask[0] = omap2_prm_read_mod_reg(OCP_MOD,
  171. OMAP3_PRM_IRQENABLE_MPU_OFFSET);
  172. omap2_prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET);
  173. /* OCP barrier */
  174. omap2_prm_read_mod_reg(OCP_MOD, OMAP3_PRM_REVISION_OFFSET);
  175. }
  176. /**
  177. * omap3xxx_prm_restore_irqen - set PRM_IRQENABLE_MPU register from args
  178. * @saved_mask: ptr to a u32 array of IRQENABLE bits saved previously
  179. *
  180. * Restore the PRM_IRQENABLE_MPU register from @saved_mask. Intended
  181. * to be used in the PRM interrupt handler resume callback to restore
  182. * values saved by omap3xxx_prm_save_and_clear_irqen(). No OCP
  183. * barrier should be needed here; any pending PRM interrupts will fire
  184. * once the writes reach the PRM. No return value.
  185. */
  186. static void omap3xxx_prm_restore_irqen(u32 *saved_mask)
  187. {
  188. omap2_prm_write_mod_reg(saved_mask[0], OCP_MOD,
  189. OMAP3_PRM_IRQENABLE_MPU_OFFSET);
  190. }
  191. /**
  192. * omap3xxx_prm_clear_mod_irqs - clear wake-up events from PRCM interrupt
  193. * @module: PRM module to clear wakeups from
  194. * @regs: register set to clear, 1 or 3
  195. * @wkst_mask: wkst bits to clear
  196. *
  197. * The purpose of this function is to clear any wake-up events latched
  198. * in the PRCM PM_WKST_x registers. It is possible that a wake-up event
  199. * may occur whilst attempting to clear a PM_WKST_x register and thus
  200. * set another bit in this register. A while loop is used to ensure
  201. * that any peripheral wake-up events occurring while attempting to
  202. * clear the PM_WKST_x are detected and cleared.
  203. */
  204. static int omap3xxx_prm_clear_mod_irqs(s16 module, u8 regs, u32 wkst_mask)
  205. {
  206. u32 wkst, fclk, iclk, clken;
  207. u16 wkst_off = (regs == 3) ? OMAP3430ES2_PM_WKST3 : PM_WKST1;
  208. u16 fclk_off = (regs == 3) ? OMAP3430ES2_CM_FCLKEN3 : CM_FCLKEN1;
  209. u16 iclk_off = (regs == 3) ? CM_ICLKEN3 : CM_ICLKEN1;
  210. u16 grpsel_off = (regs == 3) ?
  211. OMAP3430ES2_PM_MPUGRPSEL3 : OMAP3430_PM_MPUGRPSEL;
  212. int c = 0;
  213. wkst = omap2_prm_read_mod_reg(module, wkst_off);
  214. wkst &= omap2_prm_read_mod_reg(module, grpsel_off);
  215. wkst &= wkst_mask;
  216. if (wkst) {
  217. iclk = omap2_cm_read_mod_reg(module, iclk_off);
  218. fclk = omap2_cm_read_mod_reg(module, fclk_off);
  219. while (wkst) {
  220. clken = wkst;
  221. omap2_cm_set_mod_reg_bits(clken, module, iclk_off);
  222. /*
  223. * For USBHOST, we don't know whether HOST1 or
  224. * HOST2 woke us up, so enable both f-clocks
  225. */
  226. if (module == OMAP3430ES2_USBHOST_MOD)
  227. clken |= 1 << OMAP3430ES2_EN_USBHOST2_SHIFT;
  228. omap2_cm_set_mod_reg_bits(clken, module, fclk_off);
  229. omap2_prm_write_mod_reg(wkst, module, wkst_off);
  230. wkst = omap2_prm_read_mod_reg(module, wkst_off);
  231. wkst &= wkst_mask;
  232. c++;
  233. }
  234. omap2_cm_write_mod_reg(iclk, module, iclk_off);
  235. omap2_cm_write_mod_reg(fclk, module, fclk_off);
  236. }
  237. return c;
  238. }
  239. /**
  240. * omap3_prm_reset_modem - toggle reset signal for modem
  241. *
  242. * Toggles the reset signal to modem IP block. Required to allow
  243. * OMAP3430 without stacked modem to idle properly.
  244. */
  245. void __init omap3_prm_reset_modem(void)
  246. {
  247. omap2_prm_write_mod_reg(
  248. OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RSTPWRON_MASK |
  249. OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RST_MASK,
  250. CORE_MOD, OMAP2_RM_RSTCTRL);
  251. omap2_prm_write_mod_reg(0, CORE_MOD, OMAP2_RM_RSTCTRL);
  252. }
  253. /**
  254. * omap3_prm_init_pm - initialize PM related registers for PRM
  255. * @has_uart4: SoC has UART4
  256. * @has_iva: SoC has IVA
  257. *
  258. * Initializes PRM registers for PM use. Called from PM init.
  259. */
  260. void __init omap3_prm_init_pm(bool has_uart4, bool has_iva)
  261. {
  262. u32 en_uart4_mask;
  263. u32 grpsel_uart4_mask;
  264. /*
  265. * Enable control of expternal oscillator through
  266. * sys_clkreq. In the long run clock framework should
  267. * take care of this.
  268. */
  269. omap2_prm_rmw_mod_reg_bits(OMAP_AUTOEXTCLKMODE_MASK,
  270. 1 << OMAP_AUTOEXTCLKMODE_SHIFT,
  271. OMAP3430_GR_MOD,
  272. OMAP3_PRM_CLKSRC_CTRL_OFFSET);
  273. /* setup wakup source */
  274. omap2_prm_write_mod_reg(OMAP3430_EN_IO_MASK | OMAP3430_EN_GPIO1_MASK |
  275. OMAP3430_EN_GPT1_MASK | OMAP3430_EN_GPT12_MASK,
  276. WKUP_MOD, PM_WKEN);
  277. /* No need to write EN_IO, that is always enabled */
  278. omap2_prm_write_mod_reg(OMAP3430_GRPSEL_GPIO1_MASK |
  279. OMAP3430_GRPSEL_GPT1_MASK |
  280. OMAP3430_GRPSEL_GPT12_MASK,
  281. WKUP_MOD, OMAP3430_PM_MPUGRPSEL);
  282. /* Enable PM_WKEN to support DSS LPR */
  283. omap2_prm_write_mod_reg(OMAP3430_PM_WKEN_DSS_EN_DSS_MASK,
  284. OMAP3430_DSS_MOD, PM_WKEN);
  285. if (has_uart4) {
  286. en_uart4_mask = OMAP3630_EN_UART4_MASK;
  287. grpsel_uart4_mask = OMAP3630_GRPSEL_UART4_MASK;
  288. } else {
  289. en_uart4_mask = 0;
  290. grpsel_uart4_mask = 0;
  291. }
  292. /* Enable wakeups in PER */
  293. omap2_prm_write_mod_reg(en_uart4_mask |
  294. OMAP3430_EN_GPIO2_MASK |
  295. OMAP3430_EN_GPIO3_MASK |
  296. OMAP3430_EN_GPIO4_MASK |
  297. OMAP3430_EN_GPIO5_MASK |
  298. OMAP3430_EN_GPIO6_MASK |
  299. OMAP3430_EN_UART3_MASK |
  300. OMAP3430_EN_MCBSP2_MASK |
  301. OMAP3430_EN_MCBSP3_MASK |
  302. OMAP3430_EN_MCBSP4_MASK,
  303. OMAP3430_PER_MOD, PM_WKEN);
  304. /* and allow them to wake up MPU */
  305. omap2_prm_write_mod_reg(grpsel_uart4_mask |
  306. OMAP3430_GRPSEL_GPIO2_MASK |
  307. OMAP3430_GRPSEL_GPIO3_MASK |
  308. OMAP3430_GRPSEL_GPIO4_MASK |
  309. OMAP3430_GRPSEL_GPIO5_MASK |
  310. OMAP3430_GRPSEL_GPIO6_MASK |
  311. OMAP3430_GRPSEL_UART3_MASK |
  312. OMAP3430_GRPSEL_MCBSP2_MASK |
  313. OMAP3430_GRPSEL_MCBSP3_MASK |
  314. OMAP3430_GRPSEL_MCBSP4_MASK,
  315. OMAP3430_PER_MOD, OMAP3430_PM_MPUGRPSEL);
  316. /* Don't attach IVA interrupts */
  317. if (has_iva) {
  318. omap2_prm_write_mod_reg(0, WKUP_MOD, OMAP3430_PM_IVAGRPSEL);
  319. omap2_prm_write_mod_reg(0, CORE_MOD, OMAP3430_PM_IVAGRPSEL1);
  320. omap2_prm_write_mod_reg(0, CORE_MOD, OMAP3430ES2_PM_IVAGRPSEL3);
  321. omap2_prm_write_mod_reg(0, OMAP3430_PER_MOD,
  322. OMAP3430_PM_IVAGRPSEL);
  323. }
  324. /* Clear any pending 'reset' flags */
  325. omap2_prm_write_mod_reg(0xffffffff, MPU_MOD, OMAP2_RM_RSTST);
  326. omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP2_RM_RSTST);
  327. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD, OMAP2_RM_RSTST);
  328. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD, OMAP2_RM_RSTST);
  329. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD, OMAP2_RM_RSTST);
  330. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD, OMAP2_RM_RSTST);
  331. omap2_prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD,
  332. OMAP2_RM_RSTST);
  333. /* Clear any pending PRCM interrupts */
  334. omap2_prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
  335. /* We need to idle iva2_pwrdm even on am3703 with no iva2. */
  336. omap3xxx_prm_iva_idle();
  337. omap3_prm_reset_modem();
  338. }
  339. /**
  340. * omap3430_pre_es3_1_reconfigure_io_chain - restart wake-up daisy chain
  341. *
  342. * The ST_IO_CHAIN bit does not exist in 3430 before es3.1. The only
  343. * thing we can do is toggle EN_IO bit for earlier omaps.
  344. */
  345. static void omap3430_pre_es3_1_reconfigure_io_chain(void)
  346. {
  347. omap2_prm_clear_mod_reg_bits(OMAP3430_EN_IO_MASK, WKUP_MOD,
  348. PM_WKEN);
  349. omap2_prm_set_mod_reg_bits(OMAP3430_EN_IO_MASK, WKUP_MOD,
  350. PM_WKEN);
  351. omap2_prm_read_mod_reg(WKUP_MOD, PM_WKEN);
  352. }
  353. /**
  354. * omap3_prm_reconfigure_io_chain - clear latches and reconfigure I/O chain
  355. *
  356. * Clear any previously-latched I/O wakeup events and ensure that the
  357. * I/O wakeup gates are aligned with the current mux settings. Works
  358. * by asserting WUCLKIN, waiting for WUCLKOUT to be asserted, and then
  359. * deasserting WUCLKIN and clearing the ST_IO_CHAIN WKST bit. No
  360. * return value. These registers are only available in 3430 es3.1 and later.
  361. */
  362. static void omap3_prm_reconfigure_io_chain(void)
  363. {
  364. int i = 0;
  365. omap2_prm_set_mod_reg_bits(OMAP3430_EN_IO_CHAIN_MASK, WKUP_MOD,
  366. PM_WKEN);
  367. omap_test_timeout(omap2_prm_read_mod_reg(WKUP_MOD, PM_WKST) &
  368. OMAP3430_ST_IO_CHAIN_MASK,
  369. MAX_IOPAD_LATCH_TIME, i);
  370. if (i == MAX_IOPAD_LATCH_TIME)
  371. pr_warn("PRM: I/O chain clock line assertion timed out\n");
  372. omap2_prm_clear_mod_reg_bits(OMAP3430_EN_IO_CHAIN_MASK, WKUP_MOD,
  373. PM_WKEN);
  374. omap2_prm_set_mod_reg_bits(OMAP3430_ST_IO_CHAIN_MASK, WKUP_MOD,
  375. PM_WKST);
  376. omap2_prm_read_mod_reg(WKUP_MOD, PM_WKST);
  377. }
  378. /**
  379. * omap3xxx_prm_enable_io_wakeup - enable wakeup events from I/O wakeup latches
  380. *
  381. * Activates the I/O wakeup event latches and allows events logged by
  382. * those latches to signal a wakeup event to the PRCM. For I/O
  383. * wakeups to occur, WAKEUPENABLE bits must be set in the pad mux
  384. * registers, and omap3xxx_prm_reconfigure_io_chain() must be called.
  385. * No return value.
  386. */
  387. static void __init omap3xxx_prm_enable_io_wakeup(void)
  388. {
  389. if (prm_features & PRM_HAS_IO_WAKEUP)
  390. omap2_prm_set_mod_reg_bits(OMAP3430_EN_IO_MASK, WKUP_MOD,
  391. PM_WKEN);
  392. }
  393. /**
  394. * omap3xxx_prm_read_reset_sources - return the last SoC reset source
  395. *
  396. * Return a u32 representing the last reset sources of the SoC. The
  397. * returned reset source bits are standardized across OMAP SoCs.
  398. */
  399. static u32 omap3xxx_prm_read_reset_sources(void)
  400. {
  401. struct prm_reset_src_map *p;
  402. u32 r = 0;
  403. u32 v;
  404. v = omap2_prm_read_mod_reg(WKUP_MOD, OMAP2_RM_RSTST);
  405. p = omap3xxx_prm_reset_src_map;
  406. while (p->reg_shift >= 0 && p->std_shift >= 0) {
  407. if (v & (1 << p->reg_shift))
  408. r |= 1 << p->std_shift;
  409. p++;
  410. }
  411. return r;
  412. }
  413. /**
  414. * omap3xxx_prm_iva_idle - ensure IVA is in idle so it can be put into retention
  415. *
  416. * In cases where IVA2 is activated by bootcode, it may prevent
  417. * full-chip retention or off-mode because it is not idle. This
  418. * function forces the IVA2 into idle state so it can go
  419. * into retention/off and thus allow full-chip retention/off.
  420. */
  421. void omap3xxx_prm_iva_idle(void)
  422. {
  423. /* ensure IVA2 clock is disabled */
  424. omap2_cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
  425. /* if no clock activity, nothing else to do */
  426. if (!(omap2_cm_read_mod_reg(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSTST) &
  427. OMAP3430_CLKACTIVITY_IVA2_MASK))
  428. return;
  429. /* Reset IVA2 */
  430. omap2_prm_write_mod_reg(OMAP3430_RST1_IVA2_MASK |
  431. OMAP3430_RST2_IVA2_MASK |
  432. OMAP3430_RST3_IVA2_MASK,
  433. OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
  434. /* Enable IVA2 clock */
  435. omap2_cm_write_mod_reg(OMAP3430_CM_FCLKEN_IVA2_EN_IVA2_MASK,
  436. OMAP3430_IVA2_MOD, CM_FCLKEN);
  437. /* Un-reset IVA2 */
  438. omap2_prm_write_mod_reg(0, OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
  439. /* Disable IVA2 clock */
  440. omap2_cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
  441. /* Reset IVA2 */
  442. omap2_prm_write_mod_reg(OMAP3430_RST1_IVA2_MASK |
  443. OMAP3430_RST2_IVA2_MASK |
  444. OMAP3430_RST3_IVA2_MASK,
  445. OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
  446. }
  447. /**
  448. * omap3xxx_prm_clear_global_cold_reset - checks the global cold reset status
  449. * and clears it if asserted
  450. *
  451. * Checks if cold-reset has occurred and clears the status bit if yes. Returns
  452. * 1 if cold-reset has occurred, 0 otherwise.
  453. */
  454. int omap3xxx_prm_clear_global_cold_reset(void)
  455. {
  456. if (omap2_prm_read_mod_reg(OMAP3430_GR_MOD, OMAP3_PRM_RSTST_OFFSET) &
  457. OMAP3430_GLOBAL_COLD_RST_MASK) {
  458. omap2_prm_set_mod_reg_bits(OMAP3430_GLOBAL_COLD_RST_MASK,
  459. OMAP3430_GR_MOD,
  460. OMAP3_PRM_RSTST_OFFSET);
  461. return 1;
  462. }
  463. return 0;
  464. }
  465. void omap3_prm_save_scratchpad_contents(u32 *ptr)
  466. {
  467. *ptr++ = omap2_prm_read_mod_reg(OMAP3430_GR_MOD,
  468. OMAP3_PRM_CLKSRC_CTRL_OFFSET);
  469. *ptr++ = omap2_prm_read_mod_reg(OMAP3430_GR_MOD,
  470. OMAP3_PRM_CLKSEL_OFFSET);
  471. }
  472. /* Powerdomain low-level functions */
  473. static int omap3_pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst)
  474. {
  475. omap2_prm_rmw_mod_reg_bits(OMAP_POWERSTATE_MASK,
  476. (pwrst << OMAP_POWERSTATE_SHIFT),
  477. pwrdm->prcm_offs, OMAP2_PM_PWSTCTRL);
  478. return 0;
  479. }
  480. static int omap3_pwrdm_read_next_pwrst(struct powerdomain *pwrdm)
  481. {
  482. return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
  483. OMAP2_PM_PWSTCTRL,
  484. OMAP_POWERSTATE_MASK);
  485. }
  486. static int omap3_pwrdm_read_pwrst(struct powerdomain *pwrdm)
  487. {
  488. return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
  489. OMAP2_PM_PWSTST,
  490. OMAP_POWERSTATEST_MASK);
  491. }
  492. /* Applicable only for OMAP3. Not supported on OMAP2 */
  493. static int omap3_pwrdm_read_prev_pwrst(struct powerdomain *pwrdm)
  494. {
  495. return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
  496. OMAP3430_PM_PREPWSTST,
  497. OMAP3430_LASTPOWERSTATEENTERED_MASK);
  498. }
  499. static int omap3_pwrdm_read_logic_pwrst(struct powerdomain *pwrdm)
  500. {
  501. return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
  502. OMAP2_PM_PWSTST,
  503. OMAP3430_LOGICSTATEST_MASK);
  504. }
  505. static int omap3_pwrdm_read_logic_retst(struct powerdomain *pwrdm)
  506. {
  507. return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
  508. OMAP2_PM_PWSTCTRL,
  509. OMAP3430_LOGICSTATEST_MASK);
  510. }
  511. static int omap3_pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm)
  512. {
  513. return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
  514. OMAP3430_PM_PREPWSTST,
  515. OMAP3430_LASTLOGICSTATEENTERED_MASK);
  516. }
  517. static int omap3_get_mem_bank_lastmemst_mask(u8 bank)
  518. {
  519. switch (bank) {
  520. case 0:
  521. return OMAP3430_LASTMEM1STATEENTERED_MASK;
  522. case 1:
  523. return OMAP3430_LASTMEM2STATEENTERED_MASK;
  524. case 2:
  525. return OMAP3430_LASTSHAREDL2CACHEFLATSTATEENTERED_MASK;
  526. case 3:
  527. return OMAP3430_LASTL2FLATMEMSTATEENTERED_MASK;
  528. default:
  529. WARN_ON(1); /* should never happen */
  530. return -EEXIST;
  531. }
  532. return 0;
  533. }
  534. static int omap3_pwrdm_read_prev_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
  535. {
  536. u32 m;
  537. m = omap3_get_mem_bank_lastmemst_mask(bank);
  538. return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
  539. OMAP3430_PM_PREPWSTST, m);
  540. }
  541. static int omap3_pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm)
  542. {
  543. omap2_prm_write_mod_reg(0, pwrdm->prcm_offs, OMAP3430_PM_PREPWSTST);
  544. return 0;
  545. }
  546. static int omap3_pwrdm_enable_hdwr_sar(struct powerdomain *pwrdm)
  547. {
  548. return omap2_prm_rmw_mod_reg_bits(0,
  549. 1 << OMAP3430ES2_SAVEANDRESTORE_SHIFT,
  550. pwrdm->prcm_offs, OMAP2_PM_PWSTCTRL);
  551. }
  552. static int omap3_pwrdm_disable_hdwr_sar(struct powerdomain *pwrdm)
  553. {
  554. return omap2_prm_rmw_mod_reg_bits(1 << OMAP3430ES2_SAVEANDRESTORE_SHIFT,
  555. 0, pwrdm->prcm_offs,
  556. OMAP2_PM_PWSTCTRL);
  557. }
  558. struct pwrdm_ops omap3_pwrdm_operations = {
  559. .pwrdm_set_next_pwrst = omap3_pwrdm_set_next_pwrst,
  560. .pwrdm_read_next_pwrst = omap3_pwrdm_read_next_pwrst,
  561. .pwrdm_read_pwrst = omap3_pwrdm_read_pwrst,
  562. .pwrdm_read_prev_pwrst = omap3_pwrdm_read_prev_pwrst,
  563. .pwrdm_set_logic_retst = omap2_pwrdm_set_logic_retst,
  564. .pwrdm_read_logic_pwrst = omap3_pwrdm_read_logic_pwrst,
  565. .pwrdm_read_logic_retst = omap3_pwrdm_read_logic_retst,
  566. .pwrdm_read_prev_logic_pwrst = omap3_pwrdm_read_prev_logic_pwrst,
  567. .pwrdm_set_mem_onst = omap2_pwrdm_set_mem_onst,
  568. .pwrdm_set_mem_retst = omap2_pwrdm_set_mem_retst,
  569. .pwrdm_read_mem_pwrst = omap2_pwrdm_read_mem_pwrst,
  570. .pwrdm_read_mem_retst = omap2_pwrdm_read_mem_retst,
  571. .pwrdm_read_prev_mem_pwrst = omap3_pwrdm_read_prev_mem_pwrst,
  572. .pwrdm_clear_all_prev_pwrst = omap3_pwrdm_clear_all_prev_pwrst,
  573. .pwrdm_enable_hdwr_sar = omap3_pwrdm_enable_hdwr_sar,
  574. .pwrdm_disable_hdwr_sar = omap3_pwrdm_disable_hdwr_sar,
  575. .pwrdm_wait_transition = omap2_pwrdm_wait_transition,
  576. };
  577. /*
  578. *
  579. */
  580. static int omap3xxx_prm_late_init(void);
  581. static struct prm_ll_data omap3xxx_prm_ll_data = {
  582. .read_reset_sources = &omap3xxx_prm_read_reset_sources,
  583. .late_init = &omap3xxx_prm_late_init,
  584. .assert_hardreset = &omap2_prm_assert_hardreset,
  585. .deassert_hardreset = &omap2_prm_deassert_hardreset,
  586. .is_hardreset_asserted = &omap2_prm_is_hardreset_asserted,
  587. .reset_system = &omap3xxx_prm_dpll3_reset,
  588. .clear_mod_irqs = &omap3xxx_prm_clear_mod_irqs,
  589. .vp_check_txdone = &omap3_prm_vp_check_txdone,
  590. .vp_clear_txdone = &omap3_prm_vp_clear_txdone,
  591. };
  592. int __init omap3xxx_prm_init(const struct omap_prcm_init_data *data)
  593. {
  594. omap2_clk_legacy_provider_init(TI_CLKM_PRM,
  595. prm_base + OMAP3430_IVA2_MOD);
  596. if (omap3_has_io_wakeup())
  597. prm_features |= PRM_HAS_IO_WAKEUP;
  598. return prm_register(&omap3xxx_prm_ll_data);
  599. }
  600. static const struct of_device_id omap3_prm_dt_match_table[] = {
  601. { .compatible = "ti,omap3-prm" },
  602. { }
  603. };
  604. static int omap3xxx_prm_late_init(void)
  605. {
  606. int ret;
  607. if (!(prm_features & PRM_HAS_IO_WAKEUP))
  608. return 0;
  609. if (omap3_has_io_chain_ctrl())
  610. omap3_prcm_irq_setup.reconfigure_io_chain =
  611. omap3_prm_reconfigure_io_chain;
  612. else
  613. omap3_prcm_irq_setup.reconfigure_io_chain =
  614. omap3430_pre_es3_1_reconfigure_io_chain;
  615. if (of_have_populated_dt()) {
  616. struct device_node *np;
  617. int irq_num;
  618. np = of_find_matching_node(NULL, omap3_prm_dt_match_table);
  619. if (np) {
  620. irq_num = of_irq_get(np, 0);
  621. if (irq_num >= 0)
  622. omap3_prcm_irq_setup.irq = irq_num;
  623. }
  624. }
  625. omap3xxx_prm_enable_io_wakeup();
  626. ret = omap_prcm_register_chain_handler(&omap3_prcm_irq_setup);
  627. if (!ret)
  628. irq_set_status_flags(omap_prcm_event_to_irq("io"),
  629. IRQ_NOAUTOEN);
  630. return ret;
  631. }
  632. static void __exit omap3xxx_prm_exit(void)
  633. {
  634. prm_unregister(&omap3xxx_prm_ll_data);
  635. }
  636. __exitcall(omap3xxx_prm_exit);