prm_common.c 21 KB

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