prm_common.c 22 KB

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