prm44xx.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. /*
  2. * OMAP4 PRM module functions
  3. *
  4. * Copyright (C) 2011-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/delay.h>
  16. #include <linux/errno.h>
  17. #include <linux/err.h>
  18. #include <linux/io.h>
  19. #include <linux/of_irq.h>
  20. #include <linux/of.h>
  21. #include "soc.h"
  22. #include "iomap.h"
  23. #include "common.h"
  24. #include "vp.h"
  25. #include "prm44xx.h"
  26. #include "prcm43xx.h"
  27. #include "prm-regbits-44xx.h"
  28. #include "prcm44xx.h"
  29. #include "prminst44xx.h"
  30. #include "powerdomain.h"
  31. /* Static data */
  32. static void omap44xx_prm_read_pending_irqs(unsigned long *events);
  33. static void omap44xx_prm_ocp_barrier(void);
  34. static void omap44xx_prm_save_and_clear_irqen(u32 *saved_mask);
  35. static void omap44xx_prm_restore_irqen(u32 *saved_mask);
  36. static void omap44xx_prm_reconfigure_io_chain(void);
  37. static const struct omap_prcm_irq omap4_prcm_irqs[] = {
  38. OMAP_PRCM_IRQ("io", 9, 1),
  39. };
  40. static struct omap_prcm_irq_setup omap4_prcm_irq_setup = {
  41. .ack = OMAP4_PRM_IRQSTATUS_MPU_OFFSET,
  42. .mask = OMAP4_PRM_IRQENABLE_MPU_OFFSET,
  43. .pm_ctrl = OMAP4_PRM_IO_PMCTRL_OFFSET,
  44. .nr_regs = 2,
  45. .irqs = omap4_prcm_irqs,
  46. .nr_irqs = ARRAY_SIZE(omap4_prcm_irqs),
  47. .irq = 11 + OMAP44XX_IRQ_GIC_START,
  48. .xlate_irq = omap4_xlate_irq,
  49. .read_pending_irqs = &omap44xx_prm_read_pending_irqs,
  50. .ocp_barrier = &omap44xx_prm_ocp_barrier,
  51. .save_and_clear_irqen = &omap44xx_prm_save_and_clear_irqen,
  52. .restore_irqen = &omap44xx_prm_restore_irqen,
  53. .reconfigure_io_chain = &omap44xx_prm_reconfigure_io_chain,
  54. };
  55. /*
  56. * omap44xx_prm_reset_src_map - map from bits in the PRM_RSTST
  57. * hardware register (which are specific to OMAP44xx SoCs) to reset
  58. * source ID bit shifts (which is an OMAP SoC-independent
  59. * enumeration)
  60. */
  61. static struct prm_reset_src_map omap44xx_prm_reset_src_map[] = {
  62. { OMAP4430_GLOBAL_WARM_SW_RST_SHIFT,
  63. OMAP_GLOBAL_WARM_RST_SRC_ID_SHIFT },
  64. { OMAP4430_GLOBAL_COLD_RST_SHIFT,
  65. OMAP_GLOBAL_COLD_RST_SRC_ID_SHIFT },
  66. { OMAP4430_MPU_SECURITY_VIOL_RST_SHIFT,
  67. OMAP_SECU_VIOL_RST_SRC_ID_SHIFT },
  68. { OMAP4430_MPU_WDT_RST_SHIFT, OMAP_MPU_WD_RST_SRC_ID_SHIFT },
  69. { OMAP4430_SECURE_WDT_RST_SHIFT, OMAP_SECU_WD_RST_SRC_ID_SHIFT },
  70. { OMAP4430_EXTERNAL_WARM_RST_SHIFT, OMAP_EXTWARM_RST_SRC_ID_SHIFT },
  71. { OMAP4430_VDD_MPU_VOLT_MGR_RST_SHIFT,
  72. OMAP_VDD_MPU_VM_RST_SRC_ID_SHIFT },
  73. { OMAP4430_VDD_IVA_VOLT_MGR_RST_SHIFT,
  74. OMAP_VDD_IVA_VM_RST_SRC_ID_SHIFT },
  75. { OMAP4430_VDD_CORE_VOLT_MGR_RST_SHIFT,
  76. OMAP_VDD_CORE_VM_RST_SRC_ID_SHIFT },
  77. { OMAP4430_ICEPICK_RST_SHIFT, OMAP_ICEPICK_RST_SRC_ID_SHIFT },
  78. { OMAP4430_C2C_RST_SHIFT, OMAP_C2C_RST_SRC_ID_SHIFT },
  79. { -1, -1 },
  80. };
  81. /* PRM low-level functions */
  82. /* Read a register in a CM/PRM instance in the PRM module */
  83. static u32 omap4_prm_read_inst_reg(s16 inst, u16 reg)
  84. {
  85. return readl_relaxed(prm_base + inst + reg);
  86. }
  87. /* Write into a register in a CM/PRM instance in the PRM module */
  88. static void omap4_prm_write_inst_reg(u32 val, s16 inst, u16 reg)
  89. {
  90. writel_relaxed(val, prm_base + inst + reg);
  91. }
  92. /* Read-modify-write a register in a PRM module. Caller must lock */
  93. static u32 omap4_prm_rmw_inst_reg_bits(u32 mask, u32 bits, s16 inst, s16 reg)
  94. {
  95. u32 v;
  96. v = omap4_prm_read_inst_reg(inst, reg);
  97. v &= ~mask;
  98. v |= bits;
  99. omap4_prm_write_inst_reg(v, inst, reg);
  100. return v;
  101. }
  102. /* PRM VP */
  103. /*
  104. * struct omap4_vp - OMAP4 VP register access description.
  105. * @irqstatus_mpu: offset to IRQSTATUS_MPU register for VP
  106. * @tranxdone_status: VP_TRANXDONE_ST bitmask in PRM_IRQSTATUS_MPU reg
  107. */
  108. struct omap4_vp {
  109. u32 irqstatus_mpu;
  110. u32 tranxdone_status;
  111. };
  112. static struct omap4_vp omap4_vp[] = {
  113. [OMAP4_VP_VDD_MPU_ID] = {
  114. .irqstatus_mpu = OMAP4_PRM_IRQSTATUS_MPU_2_OFFSET,
  115. .tranxdone_status = OMAP4430_VP_MPU_TRANXDONE_ST_MASK,
  116. },
  117. [OMAP4_VP_VDD_IVA_ID] = {
  118. .irqstatus_mpu = OMAP4_PRM_IRQSTATUS_MPU_OFFSET,
  119. .tranxdone_status = OMAP4430_VP_IVA_TRANXDONE_ST_MASK,
  120. },
  121. [OMAP4_VP_VDD_CORE_ID] = {
  122. .irqstatus_mpu = OMAP4_PRM_IRQSTATUS_MPU_OFFSET,
  123. .tranxdone_status = OMAP4430_VP_CORE_TRANXDONE_ST_MASK,
  124. },
  125. };
  126. static u32 omap4_prm_vp_check_txdone(u8 vp_id)
  127. {
  128. struct omap4_vp *vp = &omap4_vp[vp_id];
  129. u32 irqstatus;
  130. irqstatus = omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
  131. OMAP4430_PRM_OCP_SOCKET_INST,
  132. vp->irqstatus_mpu);
  133. return irqstatus & vp->tranxdone_status;
  134. }
  135. static void omap4_prm_vp_clear_txdone(u8 vp_id)
  136. {
  137. struct omap4_vp *vp = &omap4_vp[vp_id];
  138. omap4_prminst_write_inst_reg(vp->tranxdone_status,
  139. OMAP4430_PRM_PARTITION,
  140. OMAP4430_PRM_OCP_SOCKET_INST,
  141. vp->irqstatus_mpu);
  142. };
  143. u32 omap4_prm_vcvp_read(u8 offset)
  144. {
  145. s32 inst = omap4_prmst_get_prm_dev_inst();
  146. if (inst == PRM_INSTANCE_UNKNOWN)
  147. return 0;
  148. return omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
  149. inst, offset);
  150. }
  151. void omap4_prm_vcvp_write(u32 val, u8 offset)
  152. {
  153. s32 inst = omap4_prmst_get_prm_dev_inst();
  154. if (inst == PRM_INSTANCE_UNKNOWN)
  155. return;
  156. omap4_prminst_write_inst_reg(val, OMAP4430_PRM_PARTITION,
  157. inst, offset);
  158. }
  159. u32 omap4_prm_vcvp_rmw(u32 mask, u32 bits, u8 offset)
  160. {
  161. s32 inst = omap4_prmst_get_prm_dev_inst();
  162. if (inst == PRM_INSTANCE_UNKNOWN)
  163. return 0;
  164. return omap4_prminst_rmw_inst_reg_bits(mask, bits,
  165. OMAP4430_PRM_PARTITION,
  166. inst,
  167. offset);
  168. }
  169. static inline u32 _read_pending_irq_reg(u16 irqen_offs, u16 irqst_offs)
  170. {
  171. u32 mask, st;
  172. /* XXX read mask from RAM? */
  173. mask = omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
  174. irqen_offs);
  175. st = omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST, irqst_offs);
  176. return mask & st;
  177. }
  178. /**
  179. * omap44xx_prm_read_pending_irqs - read pending PRM MPU IRQs into @events
  180. * @events: ptr to two consecutive u32s, preallocated by caller
  181. *
  182. * Read PRM_IRQSTATUS_MPU* bits, AND'ed with the currently-enabled PRM
  183. * MPU IRQs, and store the result into the two u32s pointed to by @events.
  184. * No return value.
  185. */
  186. static void omap44xx_prm_read_pending_irqs(unsigned long *events)
  187. {
  188. int i;
  189. for (i = 0; i < omap4_prcm_irq_setup.nr_regs; i++)
  190. events[i] = _read_pending_irq_reg(omap4_prcm_irq_setup.mask +
  191. i * 4, omap4_prcm_irq_setup.ack + i * 4);
  192. }
  193. /**
  194. * omap44xx_prm_ocp_barrier - force buffered MPU writes to the PRM to complete
  195. *
  196. * Force any buffered writes to the PRM IP block to complete. Needed
  197. * by the PRM IRQ handler, which reads and writes directly to the IP
  198. * block, to avoid race conditions after acknowledging or clearing IRQ
  199. * bits. No return value.
  200. */
  201. static void omap44xx_prm_ocp_barrier(void)
  202. {
  203. omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
  204. OMAP4_REVISION_PRM_OFFSET);
  205. }
  206. /**
  207. * omap44xx_prm_save_and_clear_irqen - save/clear PRM_IRQENABLE_MPU* regs
  208. * @saved_mask: ptr to a u32 array to save IRQENABLE bits
  209. *
  210. * Save the PRM_IRQENABLE_MPU and PRM_IRQENABLE_MPU_2 registers to
  211. * @saved_mask. @saved_mask must be allocated by the caller.
  212. * Intended to be used in the PRM interrupt handler suspend callback.
  213. * The OCP barrier is needed to ensure the write to disable PRM
  214. * interrupts reaches the PRM before returning; otherwise, spurious
  215. * interrupts might occur. No return value.
  216. */
  217. static void omap44xx_prm_save_and_clear_irqen(u32 *saved_mask)
  218. {
  219. int i;
  220. u16 reg;
  221. for (i = 0; i < omap4_prcm_irq_setup.nr_regs; i++) {
  222. reg = omap4_prcm_irq_setup.mask + i * 4;
  223. saved_mask[i] =
  224. omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
  225. reg);
  226. omap4_prm_write_inst_reg(0, OMAP4430_PRM_OCP_SOCKET_INST, reg);
  227. }
  228. /* OCP barrier */
  229. omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
  230. OMAP4_REVISION_PRM_OFFSET);
  231. }
  232. /**
  233. * omap44xx_prm_restore_irqen - set PRM_IRQENABLE_MPU* registers from args
  234. * @saved_mask: ptr to a u32 array of IRQENABLE bits saved previously
  235. *
  236. * Restore the PRM_IRQENABLE_MPU and PRM_IRQENABLE_MPU_2 registers from
  237. * @saved_mask. Intended to be used in the PRM interrupt handler resume
  238. * callback to restore values saved by omap44xx_prm_save_and_clear_irqen().
  239. * No OCP barrier should be needed here; any pending PRM interrupts will fire
  240. * once the writes reach the PRM. No return value.
  241. */
  242. static void omap44xx_prm_restore_irqen(u32 *saved_mask)
  243. {
  244. int i;
  245. for (i = 0; i < omap4_prcm_irq_setup.nr_regs; i++)
  246. omap4_prm_write_inst_reg(saved_mask[i],
  247. OMAP4430_PRM_OCP_SOCKET_INST,
  248. omap4_prcm_irq_setup.mask + i * 4);
  249. }
  250. /**
  251. * omap44xx_prm_reconfigure_io_chain - clear latches and reconfigure I/O chain
  252. *
  253. * Clear any previously-latched I/O wakeup events and ensure that the
  254. * I/O wakeup gates are aligned with the current mux settings. Works
  255. * by asserting WUCLKIN, waiting for WUCLKOUT to be asserted, and then
  256. * deasserting WUCLKIN and waiting for WUCLKOUT to be deasserted.
  257. * No return value. XXX Are the final two steps necessary?
  258. */
  259. static void omap44xx_prm_reconfigure_io_chain(void)
  260. {
  261. int i = 0;
  262. s32 inst = omap4_prmst_get_prm_dev_inst();
  263. if (inst == PRM_INSTANCE_UNKNOWN)
  264. return;
  265. /* Trigger WUCLKIN enable */
  266. omap4_prm_rmw_inst_reg_bits(OMAP4430_WUCLK_CTRL_MASK,
  267. OMAP4430_WUCLK_CTRL_MASK,
  268. inst,
  269. omap4_prcm_irq_setup.pm_ctrl);
  270. omap_test_timeout(
  271. (((omap4_prm_read_inst_reg(inst,
  272. omap4_prcm_irq_setup.pm_ctrl) &
  273. OMAP4430_WUCLK_STATUS_MASK) >>
  274. OMAP4430_WUCLK_STATUS_SHIFT) == 1),
  275. MAX_IOPAD_LATCH_TIME, i);
  276. if (i == MAX_IOPAD_LATCH_TIME)
  277. pr_warn("PRM: I/O chain clock line assertion timed out\n");
  278. /* Trigger WUCLKIN disable */
  279. omap4_prm_rmw_inst_reg_bits(OMAP4430_WUCLK_CTRL_MASK, 0x0,
  280. inst,
  281. omap4_prcm_irq_setup.pm_ctrl);
  282. omap_test_timeout(
  283. (((omap4_prm_read_inst_reg(inst,
  284. omap4_prcm_irq_setup.pm_ctrl) &
  285. OMAP4430_WUCLK_STATUS_MASK) >>
  286. OMAP4430_WUCLK_STATUS_SHIFT) == 0),
  287. MAX_IOPAD_LATCH_TIME, i);
  288. if (i == MAX_IOPAD_LATCH_TIME)
  289. pr_warn("PRM: I/O chain clock line deassertion timed out\n");
  290. return;
  291. }
  292. /**
  293. * omap44xx_prm_enable_io_wakeup - enable wakeup events from I/O wakeup latches
  294. *
  295. * Activates the I/O wakeup event latches and allows events logged by
  296. * those latches to signal a wakeup event to the PRCM. For I/O wakeups
  297. * to occur, WAKEUPENABLE bits must be set in the pad mux registers, and
  298. * omap44xx_prm_reconfigure_io_chain() must be called. No return value.
  299. */
  300. static void __init omap44xx_prm_enable_io_wakeup(void)
  301. {
  302. s32 inst = omap4_prmst_get_prm_dev_inst();
  303. if (inst == PRM_INSTANCE_UNKNOWN)
  304. return;
  305. omap4_prm_rmw_inst_reg_bits(OMAP4430_GLOBAL_WUEN_MASK,
  306. OMAP4430_GLOBAL_WUEN_MASK,
  307. inst,
  308. omap4_prcm_irq_setup.pm_ctrl);
  309. }
  310. /**
  311. * omap44xx_prm_read_reset_sources - return the last SoC reset source
  312. *
  313. * Return a u32 representing the last reset sources of the SoC. The
  314. * returned reset source bits are standardized across OMAP SoCs.
  315. */
  316. static u32 omap44xx_prm_read_reset_sources(void)
  317. {
  318. struct prm_reset_src_map *p;
  319. u32 r = 0;
  320. u32 v;
  321. s32 inst = omap4_prmst_get_prm_dev_inst();
  322. if (inst == PRM_INSTANCE_UNKNOWN)
  323. return 0;
  324. v = omap4_prm_read_inst_reg(inst,
  325. OMAP4_RM_RSTST);
  326. p = omap44xx_prm_reset_src_map;
  327. while (p->reg_shift >= 0 && p->std_shift >= 0) {
  328. if (v & (1 << p->reg_shift))
  329. r |= 1 << p->std_shift;
  330. p++;
  331. }
  332. return r;
  333. }
  334. /**
  335. * omap44xx_prm_was_any_context_lost_old - was module hardware context lost?
  336. * @part: PRM partition ID (e.g., OMAP4430_PRM_PARTITION)
  337. * @inst: PRM instance offset (e.g., OMAP4430_PRM_MPU_INST)
  338. * @idx: CONTEXT register offset
  339. *
  340. * Return 1 if any bits were set in the *_CONTEXT_* register
  341. * identified by (@part, @inst, @idx), which means that some context
  342. * was lost for that module; otherwise, return 0.
  343. */
  344. static bool omap44xx_prm_was_any_context_lost_old(u8 part, s16 inst, u16 idx)
  345. {
  346. return (omap4_prminst_read_inst_reg(part, inst, idx)) ? 1 : 0;
  347. }
  348. /**
  349. * omap44xx_prm_clear_context_lost_flags_old - clear context loss flags
  350. * @part: PRM partition ID (e.g., OMAP4430_PRM_PARTITION)
  351. * @inst: PRM instance offset (e.g., OMAP4430_PRM_MPU_INST)
  352. * @idx: CONTEXT register offset
  353. *
  354. * Clear hardware context loss bits for the module identified by
  355. * (@part, @inst, @idx). No return value. XXX Writes to reserved bits;
  356. * is there a way to avoid this?
  357. */
  358. static void omap44xx_prm_clear_context_loss_flags_old(u8 part, s16 inst,
  359. u16 idx)
  360. {
  361. omap4_prminst_write_inst_reg(0xffffffff, part, inst, idx);
  362. }
  363. /* Powerdomain low-level functions */
  364. static int omap4_pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst)
  365. {
  366. omap4_prminst_rmw_inst_reg_bits(OMAP_POWERSTATE_MASK,
  367. (pwrst << OMAP_POWERSTATE_SHIFT),
  368. pwrdm->prcm_partition,
  369. pwrdm->prcm_offs, OMAP4_PM_PWSTCTRL);
  370. return 0;
  371. }
  372. static int omap4_pwrdm_read_next_pwrst(struct powerdomain *pwrdm)
  373. {
  374. u32 v;
  375. v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
  376. OMAP4_PM_PWSTCTRL);
  377. v &= OMAP_POWERSTATE_MASK;
  378. v >>= OMAP_POWERSTATE_SHIFT;
  379. return v;
  380. }
  381. static int omap4_pwrdm_read_pwrst(struct powerdomain *pwrdm)
  382. {
  383. u32 v;
  384. v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
  385. OMAP4_PM_PWSTST);
  386. v &= OMAP_POWERSTATEST_MASK;
  387. v >>= OMAP_POWERSTATEST_SHIFT;
  388. return v;
  389. }
  390. static int omap4_pwrdm_read_prev_pwrst(struct powerdomain *pwrdm)
  391. {
  392. u32 v;
  393. v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
  394. OMAP4_PM_PWSTST);
  395. v &= OMAP4430_LASTPOWERSTATEENTERED_MASK;
  396. v >>= OMAP4430_LASTPOWERSTATEENTERED_SHIFT;
  397. return v;
  398. }
  399. static int omap4_pwrdm_set_lowpwrstchange(struct powerdomain *pwrdm)
  400. {
  401. omap4_prminst_rmw_inst_reg_bits(OMAP4430_LOWPOWERSTATECHANGE_MASK,
  402. (1 << OMAP4430_LOWPOWERSTATECHANGE_SHIFT),
  403. pwrdm->prcm_partition,
  404. pwrdm->prcm_offs, OMAP4_PM_PWSTCTRL);
  405. return 0;
  406. }
  407. static int omap4_pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm)
  408. {
  409. omap4_prminst_rmw_inst_reg_bits(OMAP4430_LASTPOWERSTATEENTERED_MASK,
  410. OMAP4430_LASTPOWERSTATEENTERED_MASK,
  411. pwrdm->prcm_partition,
  412. pwrdm->prcm_offs, OMAP4_PM_PWSTST);
  413. return 0;
  414. }
  415. static int omap4_pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst)
  416. {
  417. u32 v;
  418. v = pwrst << __ffs(OMAP4430_LOGICRETSTATE_MASK);
  419. omap4_prminst_rmw_inst_reg_bits(OMAP4430_LOGICRETSTATE_MASK, v,
  420. pwrdm->prcm_partition, pwrdm->prcm_offs,
  421. OMAP4_PM_PWSTCTRL);
  422. return 0;
  423. }
  424. static int omap4_pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank,
  425. u8 pwrst)
  426. {
  427. u32 m;
  428. m = omap2_pwrdm_get_mem_bank_onstate_mask(bank);
  429. omap4_prminst_rmw_inst_reg_bits(m, (pwrst << __ffs(m)),
  430. pwrdm->prcm_partition, pwrdm->prcm_offs,
  431. OMAP4_PM_PWSTCTRL);
  432. return 0;
  433. }
  434. static int omap4_pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank,
  435. u8 pwrst)
  436. {
  437. u32 m;
  438. m = omap2_pwrdm_get_mem_bank_retst_mask(bank);
  439. omap4_prminst_rmw_inst_reg_bits(m, (pwrst << __ffs(m)),
  440. pwrdm->prcm_partition, pwrdm->prcm_offs,
  441. OMAP4_PM_PWSTCTRL);
  442. return 0;
  443. }
  444. static int omap4_pwrdm_read_logic_pwrst(struct powerdomain *pwrdm)
  445. {
  446. u32 v;
  447. v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
  448. OMAP4_PM_PWSTST);
  449. v &= OMAP4430_LOGICSTATEST_MASK;
  450. v >>= OMAP4430_LOGICSTATEST_SHIFT;
  451. return v;
  452. }
  453. static int omap4_pwrdm_read_logic_retst(struct powerdomain *pwrdm)
  454. {
  455. u32 v;
  456. v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
  457. OMAP4_PM_PWSTCTRL);
  458. v &= OMAP4430_LOGICRETSTATE_MASK;
  459. v >>= OMAP4430_LOGICRETSTATE_SHIFT;
  460. return v;
  461. }
  462. /**
  463. * omap4_pwrdm_read_prev_logic_pwrst - read the previous logic powerstate
  464. * @pwrdm: struct powerdomain * to read the state for
  465. *
  466. * Reads the previous logic powerstate for a powerdomain. This
  467. * function must determine the previous logic powerstate by first
  468. * checking the previous powerstate for the domain. If that was OFF,
  469. * then logic has been lost. If previous state was RETENTION, the
  470. * function reads the setting for the next retention logic state to
  471. * see the actual value. In every other case, the logic is
  472. * retained. Returns either PWRDM_POWER_OFF or PWRDM_POWER_RET
  473. * depending whether the logic was retained or not.
  474. */
  475. static int omap4_pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm)
  476. {
  477. int state;
  478. state = omap4_pwrdm_read_prev_pwrst(pwrdm);
  479. if (state == PWRDM_POWER_OFF)
  480. return PWRDM_POWER_OFF;
  481. if (state != PWRDM_POWER_RET)
  482. return PWRDM_POWER_RET;
  483. return omap4_pwrdm_read_logic_retst(pwrdm);
  484. }
  485. static int omap4_pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
  486. {
  487. u32 m, v;
  488. m = omap2_pwrdm_get_mem_bank_stst_mask(bank);
  489. v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
  490. OMAP4_PM_PWSTST);
  491. v &= m;
  492. v >>= __ffs(m);
  493. return v;
  494. }
  495. static int omap4_pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank)
  496. {
  497. u32 m, v;
  498. m = omap2_pwrdm_get_mem_bank_retst_mask(bank);
  499. v = omap4_prminst_read_inst_reg(pwrdm->prcm_partition, pwrdm->prcm_offs,
  500. OMAP4_PM_PWSTCTRL);
  501. v &= m;
  502. v >>= __ffs(m);
  503. return v;
  504. }
  505. /**
  506. * omap4_pwrdm_read_prev_mem_pwrst - reads the previous memory powerstate
  507. * @pwrdm: struct powerdomain * to read mem powerstate for
  508. * @bank: memory bank index
  509. *
  510. * Reads the previous memory powerstate for a powerdomain. This
  511. * function must determine the previous memory powerstate by first
  512. * checking the previous powerstate for the domain. If that was OFF,
  513. * then logic has been lost. If previous state was RETENTION, the
  514. * function reads the setting for the next memory retention state to
  515. * see the actual value. In every other case, the logic is
  516. * retained. Returns either PWRDM_POWER_OFF or PWRDM_POWER_RET
  517. * depending whether logic was retained or not.
  518. */
  519. static int omap4_pwrdm_read_prev_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
  520. {
  521. int state;
  522. state = omap4_pwrdm_read_prev_pwrst(pwrdm);
  523. if (state == PWRDM_POWER_OFF)
  524. return PWRDM_POWER_OFF;
  525. if (state != PWRDM_POWER_RET)
  526. return PWRDM_POWER_RET;
  527. return omap4_pwrdm_read_mem_retst(pwrdm, bank);
  528. }
  529. static int omap4_pwrdm_wait_transition(struct powerdomain *pwrdm)
  530. {
  531. u32 c = 0;
  532. /*
  533. * REVISIT: pwrdm_wait_transition() may be better implemented
  534. * via a callback and a periodic timer check -- how long do we expect
  535. * powerdomain transitions to take?
  536. */
  537. /* XXX Is this udelay() value meaningful? */
  538. while ((omap4_prminst_read_inst_reg(pwrdm->prcm_partition,
  539. pwrdm->prcm_offs,
  540. OMAP4_PM_PWSTST) &
  541. OMAP_INTRANSITION_MASK) &&
  542. (c++ < PWRDM_TRANSITION_BAILOUT))
  543. udelay(1);
  544. if (c > PWRDM_TRANSITION_BAILOUT) {
  545. pr_err("powerdomain: %s: waited too long to complete transition\n",
  546. pwrdm->name);
  547. return -EAGAIN;
  548. }
  549. pr_debug("powerdomain: completed transition in %d loops\n", c);
  550. return 0;
  551. }
  552. static int omap4_check_vcvp(void)
  553. {
  554. if (prm_features & PRM_HAS_VOLTAGE)
  555. return 1;
  556. return 0;
  557. }
  558. struct pwrdm_ops omap4_pwrdm_operations = {
  559. .pwrdm_set_next_pwrst = omap4_pwrdm_set_next_pwrst,
  560. .pwrdm_read_next_pwrst = omap4_pwrdm_read_next_pwrst,
  561. .pwrdm_read_pwrst = omap4_pwrdm_read_pwrst,
  562. .pwrdm_read_prev_pwrst = omap4_pwrdm_read_prev_pwrst,
  563. .pwrdm_set_lowpwrstchange = omap4_pwrdm_set_lowpwrstchange,
  564. .pwrdm_clear_all_prev_pwrst = omap4_pwrdm_clear_all_prev_pwrst,
  565. .pwrdm_set_logic_retst = omap4_pwrdm_set_logic_retst,
  566. .pwrdm_read_logic_pwrst = omap4_pwrdm_read_logic_pwrst,
  567. .pwrdm_read_prev_logic_pwrst = omap4_pwrdm_read_prev_logic_pwrst,
  568. .pwrdm_read_logic_retst = omap4_pwrdm_read_logic_retst,
  569. .pwrdm_read_mem_pwrst = omap4_pwrdm_read_mem_pwrst,
  570. .pwrdm_read_mem_retst = omap4_pwrdm_read_mem_retst,
  571. .pwrdm_read_prev_mem_pwrst = omap4_pwrdm_read_prev_mem_pwrst,
  572. .pwrdm_set_mem_onst = omap4_pwrdm_set_mem_onst,
  573. .pwrdm_set_mem_retst = omap4_pwrdm_set_mem_retst,
  574. .pwrdm_wait_transition = omap4_pwrdm_wait_transition,
  575. .pwrdm_has_voltdm = omap4_check_vcvp,
  576. };
  577. static int omap44xx_prm_late_init(void);
  578. /*
  579. * XXX document
  580. */
  581. static struct prm_ll_data omap44xx_prm_ll_data = {
  582. .read_reset_sources = &omap44xx_prm_read_reset_sources,
  583. .was_any_context_lost_old = &omap44xx_prm_was_any_context_lost_old,
  584. .clear_context_loss_flags_old = &omap44xx_prm_clear_context_loss_flags_old,
  585. .late_init = &omap44xx_prm_late_init,
  586. .assert_hardreset = omap4_prminst_assert_hardreset,
  587. .deassert_hardreset = omap4_prminst_deassert_hardreset,
  588. .is_hardreset_asserted = omap4_prminst_is_hardreset_asserted,
  589. .reset_system = omap4_prminst_global_warm_sw_reset,
  590. .vp_check_txdone = omap4_prm_vp_check_txdone,
  591. .vp_clear_txdone = omap4_prm_vp_clear_txdone,
  592. };
  593. static const struct omap_prcm_init_data *prm_init_data;
  594. int __init omap44xx_prm_init(const struct omap_prcm_init_data *data)
  595. {
  596. omap_prm_base_init();
  597. prm_init_data = data;
  598. if (data->flags & PRM_HAS_IO_WAKEUP)
  599. prm_features |= PRM_HAS_IO_WAKEUP;
  600. if (data->flags & PRM_HAS_VOLTAGE)
  601. prm_features |= PRM_HAS_VOLTAGE;
  602. omap4_prminst_set_prm_dev_inst(data->device_inst_offset);
  603. /* Add AM437X specific differences */
  604. if (of_device_is_compatible(data->np, "ti,am4-prcm")) {
  605. omap4_prcm_irq_setup.nr_irqs = 1;
  606. omap4_prcm_irq_setup.nr_regs = 1;
  607. omap4_prcm_irq_setup.pm_ctrl = AM43XX_PRM_IO_PMCTRL_OFFSET;
  608. omap4_prcm_irq_setup.ack = AM43XX_PRM_IRQSTATUS_MPU_OFFSET;
  609. omap4_prcm_irq_setup.mask = AM43XX_PRM_IRQENABLE_MPU_OFFSET;
  610. }
  611. return prm_register(&omap44xx_prm_ll_data);
  612. }
  613. static int omap44xx_prm_late_init(void)
  614. {
  615. int irq_num;
  616. if (!(prm_features & PRM_HAS_IO_WAKEUP))
  617. return 0;
  618. /* OMAP4+ is DT only now */
  619. if (!of_have_populated_dt())
  620. return 0;
  621. irq_num = of_irq_get(prm_init_data->np, 0);
  622. /*
  623. * Already have OMAP4 IRQ num. For all other platforms, we need
  624. * IRQ numbers from DT
  625. */
  626. if (irq_num < 0 && !(prm_init_data->flags & PRM_IRQ_DEFAULT)) {
  627. if (irq_num == -EPROBE_DEFER)
  628. return irq_num;
  629. /* Have nothing to do */
  630. return 0;
  631. }
  632. /* Once OMAP4 DT is filled as well */
  633. if (irq_num >= 0) {
  634. omap4_prcm_irq_setup.irq = irq_num;
  635. omap4_prcm_irq_setup.xlate_irq = NULL;
  636. }
  637. omap44xx_prm_enable_io_wakeup();
  638. return omap_prcm_register_chain_handler(&omap4_prcm_irq_setup);
  639. }
  640. static void __exit omap44xx_prm_exit(void)
  641. {
  642. prm_unregister(&omap44xx_prm_ll_data);
  643. }
  644. __exitcall(omap44xx_prm_exit);