prm_common.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * OMAP2+ common Power & Reset Management (PRM) IP block functions
  4. *
  5. * Copyright (C) 2011 Texas Instruments, Inc.
  6. * Tero Kristo <[email protected]>
  7. *
  8. * For historical purposes, the API used to configure the PRM
  9. * interrupt handler refers to it as the "PRCM interrupt." The
  10. * underlying registers are located in the PRM on OMAP3/4.
  11. *
  12. * XXX This code should eventually be moved to a PRM driver.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/io.h>
  18. #include <linux/irq.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/slab.h>
  21. #include <linux/of.h>
  22. #include <linux/of_address.h>
  23. #include <linux/clk-provider.h>
  24. #include <linux/clk/ti.h>
  25. #include "soc.h"
  26. #include "prm2xxx_3xxx.h"
  27. #include "prm2xxx.h"
  28. #include "prm3xxx.h"
  29. #include "prm33xx.h"
  30. #include "prm44xx.h"
  31. #include "prm54xx.h"
  32. #include "prm7xx.h"
  33. #include "prcm43xx.h"
  34. #include "common.h"
  35. #include "clock.h"
  36. #include "cm.h"
  37. #include "control.h"
  38. /*
  39. * OMAP_PRCM_MAX_NR_PENDING_REG: maximum number of PRM_IRQ*_MPU regs
  40. * XXX this is technically not needed, since
  41. * omap_prcm_register_chain_handler() could allocate this based on the
  42. * actual amount of memory needed for the SoC
  43. */
  44. #define OMAP_PRCM_MAX_NR_PENDING_REG 2
  45. /*
  46. * prcm_irq_chips: an array of all of the "generic IRQ chips" in use
  47. * by the PRCM interrupt handler code. There will be one 'chip' per
  48. * PRM_{IRQSTATUS,IRQENABLE}_MPU register pair. (So OMAP3 will have
  49. * one "chip" and OMAP4 will have two.)
  50. */
  51. static struct irq_chip_generic **prcm_irq_chips;
  52. /*
  53. * prcm_irq_setup: the PRCM IRQ parameters for the hardware the code
  54. * is currently running on. Defined and passed by initialization code
  55. * that calls omap_prcm_register_chain_handler().
  56. */
  57. static struct omap_prcm_irq_setup *prcm_irq_setup;
  58. /* prm_base: base virtual address of the PRM IP block */
  59. struct omap_domain_base prm_base;
  60. u16 prm_features;
  61. /*
  62. * prm_ll_data: function pointers to SoC-specific implementations of
  63. * common PRM functions
  64. */
  65. static struct prm_ll_data null_prm_ll_data;
  66. static struct prm_ll_data *prm_ll_data = &null_prm_ll_data;
  67. /* Private functions */
  68. /*
  69. * Move priority events from events to priority_events array
  70. */
  71. static void omap_prcm_events_filter_priority(unsigned long *events,
  72. unsigned long *priority_events)
  73. {
  74. int i;
  75. for (i = 0; i < prcm_irq_setup->nr_regs; i++) {
  76. priority_events[i] =
  77. events[i] & prcm_irq_setup->priority_mask[i];
  78. events[i] ^= priority_events[i];
  79. }
  80. }
  81. /*
  82. * PRCM Interrupt Handler
  83. *
  84. * This is a common handler for the OMAP PRCM interrupts. Pending
  85. * interrupts are detected by a call to prcm_pending_events and
  86. * dispatched accordingly. Clearing of the wakeup events should be
  87. * done by the SoC specific individual handlers.
  88. */
  89. static void omap_prcm_irq_handler(struct irq_desc *desc)
  90. {
  91. unsigned long pending[OMAP_PRCM_MAX_NR_PENDING_REG];
  92. unsigned long priority_pending[OMAP_PRCM_MAX_NR_PENDING_REG];
  93. struct irq_chip *chip = irq_desc_get_chip(desc);
  94. unsigned int virtirq;
  95. int nr_irq = prcm_irq_setup->nr_regs * 32;
  96. /*
  97. * If we are suspended, mask all interrupts from PRCM level,
  98. * this does not ack them, and they will be pending until we
  99. * re-enable the interrupts, at which point the
  100. * omap_prcm_irq_handler will be executed again. The
  101. * _save_and_clear_irqen() function must ensure that the PRM
  102. * write to disable all IRQs has reached the PRM before
  103. * returning, or spurious PRCM interrupts may occur during
  104. * suspend.
  105. */
  106. if (prcm_irq_setup->suspended) {
  107. prcm_irq_setup->save_and_clear_irqen(prcm_irq_setup->saved_mask);
  108. prcm_irq_setup->suspend_save_flag = true;
  109. }
  110. /*
  111. * Loop until all pending irqs are handled, since
  112. * generic_handle_irq() can cause new irqs to come
  113. */
  114. while (!prcm_irq_setup->suspended) {
  115. prcm_irq_setup->read_pending_irqs(pending);
  116. /* No bit set, then all IRQs are handled */
  117. if (find_first_bit(pending, nr_irq) >= nr_irq)
  118. break;
  119. omap_prcm_events_filter_priority(pending, priority_pending);
  120. /*
  121. * Loop on all currently pending irqs so that new irqs
  122. * cannot starve previously pending irqs
  123. */
  124. /* Serve priority events first */
  125. for_each_set_bit(virtirq, priority_pending, nr_irq)
  126. generic_handle_irq(prcm_irq_setup->base_irq + virtirq);
  127. /* Serve normal events next */
  128. for_each_set_bit(virtirq, pending, nr_irq)
  129. generic_handle_irq(prcm_irq_setup->base_irq + virtirq);
  130. }
  131. if (chip->irq_ack)
  132. chip->irq_ack(&desc->irq_data);
  133. if (chip->irq_eoi)
  134. chip->irq_eoi(&desc->irq_data);
  135. chip->irq_unmask(&desc->irq_data);
  136. prcm_irq_setup->ocp_barrier(); /* avoid spurious IRQs */
  137. }
  138. /* Public functions */
  139. /**
  140. * omap_prcm_event_to_irq - given a PRCM event name, returns the
  141. * corresponding IRQ on which the handler should be registered
  142. * @name: name of the PRCM interrupt bit to look up - see struct omap_prcm_irq
  143. *
  144. * Returns the Linux internal IRQ ID corresponding to @name upon success,
  145. * or -ENOENT upon failure.
  146. */
  147. int omap_prcm_event_to_irq(const char *name)
  148. {
  149. int i;
  150. if (!prcm_irq_setup || !name)
  151. return -ENOENT;
  152. for (i = 0; i < prcm_irq_setup->nr_irqs; i++)
  153. if (!strcmp(prcm_irq_setup->irqs[i].name, name))
  154. return prcm_irq_setup->base_irq +
  155. prcm_irq_setup->irqs[i].offset;
  156. return -ENOENT;
  157. }
  158. /**
  159. * omap_prcm_irq_cleanup - reverses memory allocated and other steps
  160. * done by omap_prcm_register_chain_handler()
  161. *
  162. * No return value.
  163. */
  164. void omap_prcm_irq_cleanup(void)
  165. {
  166. unsigned int irq;
  167. int i;
  168. if (!prcm_irq_setup) {
  169. pr_err("PRCM: IRQ handler not initialized; cannot cleanup\n");
  170. return;
  171. }
  172. if (prcm_irq_chips) {
  173. for (i = 0; i < prcm_irq_setup->nr_regs; i++) {
  174. if (prcm_irq_chips[i])
  175. irq_remove_generic_chip(prcm_irq_chips[i],
  176. 0xffffffff, 0, 0);
  177. prcm_irq_chips[i] = NULL;
  178. }
  179. kfree(prcm_irq_chips);
  180. prcm_irq_chips = NULL;
  181. }
  182. kfree(prcm_irq_setup->saved_mask);
  183. prcm_irq_setup->saved_mask = NULL;
  184. kfree(prcm_irq_setup->priority_mask);
  185. prcm_irq_setup->priority_mask = NULL;
  186. irq = prcm_irq_setup->irq;
  187. irq_set_chained_handler(irq, NULL);
  188. if (prcm_irq_setup->base_irq > 0)
  189. irq_free_descs(prcm_irq_setup->base_irq,
  190. prcm_irq_setup->nr_regs * 32);
  191. prcm_irq_setup->base_irq = 0;
  192. }
  193. void omap_prcm_irq_prepare(void)
  194. {
  195. prcm_irq_setup->suspended = true;
  196. }
  197. void omap_prcm_irq_complete(void)
  198. {
  199. prcm_irq_setup->suspended = false;
  200. /* If we have not saved the masks, do not attempt to restore */
  201. if (!prcm_irq_setup->suspend_save_flag)
  202. return;
  203. prcm_irq_setup->suspend_save_flag = false;
  204. /*
  205. * Re-enable all masked PRCM irq sources, this causes the PRCM
  206. * interrupt to fire immediately if the events were masked
  207. * previously in the chain handler
  208. */
  209. prcm_irq_setup->restore_irqen(prcm_irq_setup->saved_mask);
  210. }
  211. /**
  212. * omap_prcm_register_chain_handler - initializes the prcm chained interrupt
  213. * handler based on provided parameters
  214. * @irq_setup: hardware data about the underlying PRM/PRCM
  215. *
  216. * Set up the PRCM chained interrupt handler on the PRCM IRQ. Sets up
  217. * one generic IRQ chip per PRM interrupt status/enable register pair.
  218. * Returns 0 upon success, -EINVAL if called twice or if invalid
  219. * arguments are passed, or -ENOMEM on any other error.
  220. */
  221. int omap_prcm_register_chain_handler(struct omap_prcm_irq_setup *irq_setup)
  222. {
  223. int nr_regs;
  224. u32 mask[OMAP_PRCM_MAX_NR_PENDING_REG];
  225. int offset, i, irq;
  226. struct irq_chip_generic *gc;
  227. struct irq_chip_type *ct;
  228. if (!irq_setup)
  229. return -EINVAL;
  230. nr_regs = irq_setup->nr_regs;
  231. if (prcm_irq_setup) {
  232. pr_err("PRCM: already initialized; won't reinitialize\n");
  233. return -EINVAL;
  234. }
  235. if (nr_regs > OMAP_PRCM_MAX_NR_PENDING_REG) {
  236. pr_err("PRCM: nr_regs too large\n");
  237. return -EINVAL;
  238. }
  239. prcm_irq_setup = irq_setup;
  240. prcm_irq_chips = kcalloc(nr_regs, sizeof(void *), GFP_KERNEL);
  241. prcm_irq_setup->saved_mask = kcalloc(nr_regs, sizeof(u32),
  242. GFP_KERNEL);
  243. prcm_irq_setup->priority_mask = kcalloc(nr_regs, sizeof(u32),
  244. GFP_KERNEL);
  245. if (!prcm_irq_chips || !prcm_irq_setup->saved_mask ||
  246. !prcm_irq_setup->priority_mask)
  247. goto err;
  248. memset(mask, 0, sizeof(mask));
  249. for (i = 0; i < irq_setup->nr_irqs; i++) {
  250. offset = irq_setup->irqs[i].offset;
  251. mask[offset >> 5] |= 1 << (offset & 0x1f);
  252. if (irq_setup->irqs[i].priority)
  253. irq_setup->priority_mask[offset >> 5] |=
  254. 1 << (offset & 0x1f);
  255. }
  256. irq = irq_setup->irq;
  257. irq_set_chained_handler(irq, omap_prcm_irq_handler);
  258. irq_setup->base_irq = irq_alloc_descs(-1, 0, irq_setup->nr_regs * 32,
  259. 0);
  260. if (irq_setup->base_irq < 0) {
  261. pr_err("PRCM: failed to allocate irq descs: %d\n",
  262. irq_setup->base_irq);
  263. goto err;
  264. }
  265. for (i = 0; i < irq_setup->nr_regs; i++) {
  266. gc = irq_alloc_generic_chip("PRCM", 1,
  267. irq_setup->base_irq + i * 32, prm_base.va,
  268. handle_level_irq);
  269. if (!gc) {
  270. pr_err("PRCM: failed to allocate generic chip\n");
  271. goto err;
  272. }
  273. ct = gc->chip_types;
  274. ct->chip.irq_ack = irq_gc_ack_set_bit;
  275. ct->chip.irq_mask = irq_gc_mask_clr_bit;
  276. ct->chip.irq_unmask = irq_gc_mask_set_bit;
  277. ct->regs.ack = irq_setup->ack + i * 4;
  278. ct->regs.mask = irq_setup->mask + i * 4;
  279. irq_setup_generic_chip(gc, mask[i], 0, IRQ_NOREQUEST, 0);
  280. prcm_irq_chips[i] = gc;
  281. }
  282. irq = omap_prcm_event_to_irq("io");
  283. omap_pcs_legacy_init(irq, irq_setup->reconfigure_io_chain);
  284. return 0;
  285. err:
  286. omap_prcm_irq_cleanup();
  287. return -ENOMEM;
  288. }
  289. /**
  290. * omap2_set_globals_prm - set the PRM base address (for early use)
  291. * @prm: PRM base virtual address
  292. *
  293. * XXX Will be replaced when the PRM/CM drivers are completed.
  294. */
  295. void __init omap2_set_globals_prm(void __iomem *prm)
  296. {
  297. prm_base.va = prm;
  298. }
  299. /**
  300. * prm_read_reset_sources - return the sources of the SoC's last reset
  301. *
  302. * Return a u32 bitmask representing the reset sources that caused the
  303. * SoC to reset. The low-level per-SoC functions called by this
  304. * function remap the SoC-specific reset source bits into an
  305. * OMAP-common set of reset source bits, defined in
  306. * arch/arm/mach-omap2/prm.h. Returns the standardized reset source
  307. * u32 bitmask from the hardware upon success, or returns (1 <<
  308. * OMAP_UNKNOWN_RST_SRC_ID_SHIFT) if no low-level read_reset_sources()
  309. * function was registered.
  310. */
  311. u32 prm_read_reset_sources(void)
  312. {
  313. u32 ret = 1 << OMAP_UNKNOWN_RST_SRC_ID_SHIFT;
  314. if (prm_ll_data->read_reset_sources)
  315. ret = prm_ll_data->read_reset_sources();
  316. else
  317. WARN_ONCE(1, "prm: %s: no mapping function defined for reset sources\n", __func__);
  318. return ret;
  319. }
  320. /**
  321. * prm_was_any_context_lost_old - was device context lost? (old API)
  322. * @part: PRM partition ID (e.g., OMAP4430_PRM_PARTITION)
  323. * @inst: PRM instance offset (e.g., OMAP4430_PRM_MPU_INST)
  324. * @idx: CONTEXT register offset
  325. *
  326. * Return 1 if any bits were set in the *_CONTEXT_* register
  327. * identified by (@part, @inst, @idx), which means that some context
  328. * was lost for that module; otherwise, return 0. XXX Deprecated;
  329. * callers need to use a less-SoC-dependent way to identify hardware
  330. * IP blocks.
  331. */
  332. bool prm_was_any_context_lost_old(u8 part, s16 inst, u16 idx)
  333. {
  334. bool ret = true;
  335. if (prm_ll_data->was_any_context_lost_old)
  336. ret = prm_ll_data->was_any_context_lost_old(part, inst, idx);
  337. else
  338. WARN_ONCE(1, "prm: %s: no mapping function defined\n",
  339. __func__);
  340. return ret;
  341. }
  342. /**
  343. * prm_clear_context_lost_flags_old - clear context loss flags (old API)
  344. * @part: PRM partition ID (e.g., OMAP4430_PRM_PARTITION)
  345. * @inst: PRM instance offset (e.g., OMAP4430_PRM_MPU_INST)
  346. * @idx: CONTEXT register offset
  347. *
  348. * Clear hardware context loss bits for the module identified by
  349. * (@part, @inst, @idx). No return value. XXX Deprecated; callers
  350. * need to use a less-SoC-dependent way to identify hardware IP
  351. * blocks.
  352. */
  353. void prm_clear_context_loss_flags_old(u8 part, s16 inst, u16 idx)
  354. {
  355. if (prm_ll_data->clear_context_loss_flags_old)
  356. prm_ll_data->clear_context_loss_flags_old(part, inst, idx);
  357. else
  358. WARN_ONCE(1, "prm: %s: no mapping function defined\n",
  359. __func__);
  360. }
  361. /**
  362. * omap_prm_assert_hardreset - assert hardreset for an IP block
  363. * @shift: register bit shift corresponding to the reset line
  364. * @part: PRM partition
  365. * @prm_mod: PRM submodule base or instance offset
  366. * @offset: register offset
  367. *
  368. * Asserts a hardware reset line for an IP block.
  369. */
  370. int omap_prm_assert_hardreset(u8 shift, u8 part, s16 prm_mod, u16 offset)
  371. {
  372. if (!prm_ll_data->assert_hardreset) {
  373. WARN_ONCE(1, "prm: %s: no mapping function defined\n",
  374. __func__);
  375. return -EINVAL;
  376. }
  377. return prm_ll_data->assert_hardreset(shift, part, prm_mod, offset);
  378. }
  379. /**
  380. * omap_prm_deassert_hardreset - deassert hardreset for an IP block
  381. * @shift: register bit shift corresponding to the reset line
  382. * @st_shift: reset status bit shift corresponding to the reset line
  383. * @part: PRM partition
  384. * @prm_mod: PRM submodule base or instance offset
  385. * @offset: register offset
  386. * @st_offset: status register offset
  387. *
  388. * Deasserts a hardware reset line for an IP block.
  389. */
  390. int omap_prm_deassert_hardreset(u8 shift, u8 st_shift, u8 part, s16 prm_mod,
  391. u16 offset, u16 st_offset)
  392. {
  393. if (!prm_ll_data->deassert_hardreset) {
  394. WARN_ONCE(1, "prm: %s: no mapping function defined\n",
  395. __func__);
  396. return -EINVAL;
  397. }
  398. return prm_ll_data->deassert_hardreset(shift, st_shift, part, prm_mod,
  399. offset, st_offset);
  400. }
  401. /**
  402. * omap_prm_is_hardreset_asserted - check the hardreset status for an IP block
  403. * @shift: register bit shift corresponding to the reset line
  404. * @part: PRM partition
  405. * @prm_mod: PRM submodule base or instance offset
  406. * @offset: register offset
  407. *
  408. * Checks if a hardware reset line for an IP block is enabled or not.
  409. */
  410. int omap_prm_is_hardreset_asserted(u8 shift, u8 part, s16 prm_mod, u16 offset)
  411. {
  412. if (!prm_ll_data->is_hardreset_asserted) {
  413. WARN_ONCE(1, "prm: %s: no mapping function defined\n",
  414. __func__);
  415. return -EINVAL;
  416. }
  417. return prm_ll_data->is_hardreset_asserted(shift, part, prm_mod, offset);
  418. }
  419. /**
  420. * omap_prm_reconfigure_io_chain - clear latches and reconfigure I/O chain
  421. *
  422. * Clear any previously-latched I/O wakeup events and ensure that the
  423. * I/O wakeup gates are aligned with the current mux settings.
  424. * Calls SoC specific I/O chain reconfigure function if available,
  425. * otherwise does nothing.
  426. */
  427. void omap_prm_reconfigure_io_chain(void)
  428. {
  429. if (!prcm_irq_setup || !prcm_irq_setup->reconfigure_io_chain)
  430. return;
  431. prcm_irq_setup->reconfigure_io_chain();
  432. }
  433. /**
  434. * omap_prm_reset_system - trigger global SW reset
  435. *
  436. * Triggers SoC specific global warm reset to reboot the device.
  437. */
  438. void omap_prm_reset_system(void)
  439. {
  440. if (!prm_ll_data->reset_system) {
  441. WARN_ONCE(1, "prm: %s: no mapping function defined\n",
  442. __func__);
  443. return;
  444. }
  445. prm_ll_data->reset_system();
  446. while (1) {
  447. cpu_relax();
  448. wfe();
  449. }
  450. }
  451. /**
  452. * omap_prm_clear_mod_irqs - clear wake-up events from PRCM interrupt
  453. * @module: PRM module to clear wakeups from
  454. * @regs: register to clear
  455. * @wkst_mask: wkst bits to clear
  456. *
  457. * Clears any wakeup events for the module and register set defined.
  458. * Uses SoC specific implementation to do the actual wakeup status
  459. * clearing.
  460. */
  461. int omap_prm_clear_mod_irqs(s16 module, u8 regs, u32 wkst_mask)
  462. {
  463. if (!prm_ll_data->clear_mod_irqs) {
  464. WARN_ONCE(1, "prm: %s: no mapping function defined\n",
  465. __func__);
  466. return -EINVAL;
  467. }
  468. return prm_ll_data->clear_mod_irqs(module, regs, wkst_mask);
  469. }
  470. /**
  471. * omap_prm_vp_check_txdone - check voltage processor TX done status
  472. *
  473. * Checks if voltage processor transmission has been completed.
  474. * Returns non-zero if a transmission has completed, 0 otherwise.
  475. */
  476. u32 omap_prm_vp_check_txdone(u8 vp_id)
  477. {
  478. if (!prm_ll_data->vp_check_txdone) {
  479. WARN_ONCE(1, "prm: %s: no mapping function defined\n",
  480. __func__);
  481. return 0;
  482. }
  483. return prm_ll_data->vp_check_txdone(vp_id);
  484. }
  485. /**
  486. * omap_prm_vp_clear_txdone - clears voltage processor TX done status
  487. *
  488. * Clears the status bit for completed voltage processor transmission
  489. * returned by prm_vp_check_txdone.
  490. */
  491. void omap_prm_vp_clear_txdone(u8 vp_id)
  492. {
  493. if (!prm_ll_data->vp_clear_txdone) {
  494. WARN_ONCE(1, "prm: %s: no mapping function defined\n",
  495. __func__);
  496. return;
  497. }
  498. prm_ll_data->vp_clear_txdone(vp_id);
  499. }
  500. /**
  501. * prm_register - register per-SoC low-level data with the PRM
  502. * @pld: low-level per-SoC OMAP PRM data & function pointers to register
  503. *
  504. * Register per-SoC low-level OMAP PRM data and function pointers with
  505. * the OMAP PRM common interface. The caller must keep the data
  506. * pointed to by @pld valid until it calls prm_unregister() and
  507. * it returns successfully. Returns 0 upon success, -EINVAL if @pld
  508. * is NULL, or -EEXIST if prm_register() has already been called
  509. * without an intervening prm_unregister().
  510. */
  511. int prm_register(struct prm_ll_data *pld)
  512. {
  513. if (!pld)
  514. return -EINVAL;
  515. if (prm_ll_data != &null_prm_ll_data)
  516. return -EEXIST;
  517. prm_ll_data = pld;
  518. return 0;
  519. }
  520. /**
  521. * prm_unregister - unregister per-SoC low-level data & function pointers
  522. * @pld: low-level per-SoC OMAP PRM data & function pointers to unregister
  523. *
  524. * Unregister per-SoC low-level OMAP PRM data and function pointers
  525. * that were previously registered with prm_register(). The
  526. * caller may not destroy any of the data pointed to by @pld until
  527. * this function returns successfully. Returns 0 upon success, or
  528. * -EINVAL if @pld is NULL or if @pld does not match the struct
  529. * prm_ll_data * previously registered by prm_register().
  530. */
  531. int prm_unregister(struct prm_ll_data *pld)
  532. {
  533. if (!pld || prm_ll_data != pld)
  534. return -EINVAL;
  535. prm_ll_data = &null_prm_ll_data;
  536. return 0;
  537. }
  538. #ifdef CONFIG_ARCH_OMAP2
  539. static struct omap_prcm_init_data omap2_prm_data __initdata = {
  540. .index = TI_CLKM_PRM,
  541. .init = omap2xxx_prm_init,
  542. };
  543. #endif
  544. #ifdef CONFIG_ARCH_OMAP3
  545. static struct omap_prcm_init_data omap3_prm_data __initdata = {
  546. .index = TI_CLKM_PRM,
  547. .init = omap3xxx_prm_init,
  548. /*
  549. * IVA2 offset is a negative value, must offset the prm_base
  550. * address by this to get it to positive
  551. */
  552. .offset = -OMAP3430_IVA2_MOD,
  553. };
  554. #endif
  555. #if defined(CONFIG_SOC_AM33XX) || defined(CONFIG_SOC_TI81XX)
  556. static struct omap_prcm_init_data am3_prm_data __initdata = {
  557. .index = TI_CLKM_PRM,
  558. .init = am33xx_prm_init,
  559. };
  560. #endif
  561. #ifdef CONFIG_SOC_TI81XX
  562. static struct omap_prcm_init_data dm814_pllss_data __initdata = {
  563. .index = TI_CLKM_PLLSS,
  564. .init = am33xx_prm_init,
  565. };
  566. #endif
  567. #ifdef CONFIG_ARCH_OMAP4
  568. static struct omap_prcm_init_data omap4_prm_data __initdata = {
  569. .index = TI_CLKM_PRM,
  570. .init = omap44xx_prm_init,
  571. .device_inst_offset = OMAP4430_PRM_DEVICE_INST,
  572. .flags = PRM_HAS_IO_WAKEUP | PRM_HAS_VOLTAGE,
  573. };
  574. #endif
  575. #ifdef CONFIG_SOC_OMAP5
  576. static struct omap_prcm_init_data omap5_prm_data __initdata = {
  577. .index = TI_CLKM_PRM,
  578. .init = omap44xx_prm_init,
  579. .device_inst_offset = OMAP54XX_PRM_DEVICE_INST,
  580. .flags = PRM_HAS_IO_WAKEUP | PRM_HAS_VOLTAGE,
  581. };
  582. #endif
  583. #ifdef CONFIG_SOC_DRA7XX
  584. static struct omap_prcm_init_data dra7_prm_data __initdata = {
  585. .index = TI_CLKM_PRM,
  586. .init = omap44xx_prm_init,
  587. .device_inst_offset = DRA7XX_PRM_DEVICE_INST,
  588. .flags = PRM_HAS_IO_WAKEUP,
  589. };
  590. #endif
  591. #ifdef CONFIG_SOC_AM43XX
  592. static struct omap_prcm_init_data am4_prm_data __initdata = {
  593. .index = TI_CLKM_PRM,
  594. .init = omap44xx_prm_init,
  595. .device_inst_offset = AM43XX_PRM_DEVICE_INST,
  596. .flags = PRM_HAS_IO_WAKEUP,
  597. };
  598. #endif
  599. #if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5)
  600. static struct omap_prcm_init_data scrm_data __initdata = {
  601. .index = TI_CLKM_SCRM,
  602. };
  603. #endif
  604. static const struct of_device_id omap_prcm_dt_match_table[] __initconst = {
  605. #ifdef CONFIG_SOC_AM33XX
  606. { .compatible = "ti,am3-prcm", .data = &am3_prm_data },
  607. #endif
  608. #ifdef CONFIG_SOC_AM43XX
  609. { .compatible = "ti,am4-prcm", .data = &am4_prm_data },
  610. #endif
  611. #ifdef CONFIG_SOC_TI81XX
  612. { .compatible = "ti,dm814-prcm", .data = &am3_prm_data },
  613. { .compatible = "ti,dm814-pllss", .data = &dm814_pllss_data },
  614. { .compatible = "ti,dm816-prcm", .data = &am3_prm_data },
  615. #endif
  616. #ifdef CONFIG_ARCH_OMAP2
  617. { .compatible = "ti,omap2-prcm", .data = &omap2_prm_data },
  618. #endif
  619. #ifdef CONFIG_ARCH_OMAP3
  620. { .compatible = "ti,omap3-prm", .data = &omap3_prm_data },
  621. #endif
  622. #ifdef CONFIG_ARCH_OMAP4
  623. { .compatible = "ti,omap4-prm", .data = &omap4_prm_data },
  624. { .compatible = "ti,omap4-scrm", .data = &scrm_data },
  625. #endif
  626. #ifdef CONFIG_SOC_OMAP5
  627. { .compatible = "ti,omap5-prm", .data = &omap5_prm_data },
  628. { .compatible = "ti,omap5-scrm", .data = &scrm_data },
  629. #endif
  630. #ifdef CONFIG_SOC_DRA7XX
  631. { .compatible = "ti,dra7-prm", .data = &dra7_prm_data },
  632. #endif
  633. { }
  634. };
  635. /**
  636. * omap2_prm_base_init - initialize iomappings for the PRM driver
  637. *
  638. * Detects and initializes the iomappings for the PRM driver, based
  639. * on the DT data. Returns 0 in success, negative error value
  640. * otherwise.
  641. */
  642. int __init omap2_prm_base_init(void)
  643. {
  644. struct device_node *np;
  645. const struct of_device_id *match;
  646. struct omap_prcm_init_data *data;
  647. struct resource res;
  648. int ret;
  649. for_each_matching_node_and_match(np, omap_prcm_dt_match_table, &match) {
  650. data = (struct omap_prcm_init_data *)match->data;
  651. ret = of_address_to_resource(np, 0, &res);
  652. if (ret) {
  653. of_node_put(np);
  654. return ret;
  655. }
  656. data->mem = ioremap(res.start, resource_size(&res));
  657. if (data->index == TI_CLKM_PRM) {
  658. prm_base.va = data->mem + data->offset;
  659. prm_base.pa = res.start + data->offset;
  660. }
  661. data->np = np;
  662. if (data->init)
  663. data->init(data);
  664. }
  665. return 0;
  666. }
  667. int __init omap2_prcm_base_init(void)
  668. {
  669. int ret;
  670. ret = omap2_prm_base_init();
  671. if (ret)
  672. return ret;
  673. return omap2_cm_base_init();
  674. }
  675. /**
  676. * omap_prcm_init - low level init for the PRCM drivers
  677. *
  678. * Initializes the low level clock infrastructure for PRCM drivers.
  679. * Returns 0 in success, negative error value in failure.
  680. */
  681. int __init omap_prcm_init(void)
  682. {
  683. struct device_node *np;
  684. const struct of_device_id *match;
  685. const struct omap_prcm_init_data *data;
  686. int ret;
  687. for_each_matching_node_and_match(np, omap_prcm_dt_match_table, &match) {
  688. data = match->data;
  689. ret = omap2_clk_provider_init(np, data->index, NULL, data->mem);
  690. if (ret) {
  691. of_node_put(np);
  692. return ret;
  693. }
  694. }
  695. omap_cm_init();
  696. return 0;
  697. }
  698. static int __init prm_late_init(void)
  699. {
  700. if (prm_ll_data->late_init)
  701. return prm_ll_data->late_init();
  702. return 0;
  703. }
  704. subsys_initcall(prm_late_init);