prm_common.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  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. struct omap_domain_base 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. 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, irq;
  230. struct irq_chip_generic *gc;
  231. struct irq_chip_type *ct;
  232. if (!irq_setup)
  233. return -EINVAL;
  234. nr_regs = irq_setup->nr_regs;
  235. if (prcm_irq_setup) {
  236. pr_err("PRCM: already initialized; won't reinitialize\n");
  237. return -EINVAL;
  238. }
  239. if (nr_regs > OMAP_PRCM_MAX_NR_PENDING_REG) {
  240. pr_err("PRCM: nr_regs too large\n");
  241. return -EINVAL;
  242. }
  243. prcm_irq_setup = irq_setup;
  244. prcm_irq_chips = kcalloc(nr_regs, sizeof(void *), GFP_KERNEL);
  245. prcm_irq_setup->saved_mask = kcalloc(nr_regs, sizeof(u32),
  246. GFP_KERNEL);
  247. prcm_irq_setup->priority_mask = kcalloc(nr_regs, sizeof(u32),
  248. GFP_KERNEL);
  249. if (!prcm_irq_chips || !prcm_irq_setup->saved_mask ||
  250. !prcm_irq_setup->priority_mask)
  251. goto err;
  252. memset(mask, 0, sizeof(mask));
  253. for (i = 0; i < irq_setup->nr_irqs; i++) {
  254. offset = irq_setup->irqs[i].offset;
  255. mask[offset >> 5] |= 1 << (offset & 0x1f);
  256. if (irq_setup->irqs[i].priority)
  257. irq_setup->priority_mask[offset >> 5] |=
  258. 1 << (offset & 0x1f);
  259. }
  260. irq = irq_setup->irq;
  261. irq_set_chained_handler(irq, omap_prcm_irq_handler);
  262. irq_setup->base_irq = irq_alloc_descs(-1, 0, irq_setup->nr_regs * 32,
  263. 0);
  264. if (irq_setup->base_irq < 0) {
  265. pr_err("PRCM: failed to allocate irq descs: %d\n",
  266. irq_setup->base_irq);
  267. goto err;
  268. }
  269. for (i = 0; i < irq_setup->nr_regs; i++) {
  270. gc = irq_alloc_generic_chip("PRCM", 1,
  271. irq_setup->base_irq + i * 32, prm_base.va,
  272. handle_level_irq);
  273. if (!gc) {
  274. pr_err("PRCM: failed to allocate generic chip\n");
  275. goto err;
  276. }
  277. ct = gc->chip_types;
  278. ct->chip.irq_ack = irq_gc_ack_set_bit;
  279. ct->chip.irq_mask = irq_gc_mask_clr_bit;
  280. ct->chip.irq_unmask = irq_gc_mask_set_bit;
  281. ct->regs.ack = irq_setup->ack + i * 4;
  282. ct->regs.mask = irq_setup->mask + i * 4;
  283. irq_setup_generic_chip(gc, mask[i], 0, IRQ_NOREQUEST, 0);
  284. prcm_irq_chips[i] = gc;
  285. }
  286. irq = omap_prcm_event_to_irq("io");
  287. omap_pcs_legacy_init(irq, irq_setup->reconfigure_io_chain);
  288. return 0;
  289. err:
  290. omap_prcm_irq_cleanup();
  291. return -ENOMEM;
  292. }
  293. /**
  294. * omap2_set_globals_prm - set the PRM base address (for early use)
  295. * @prm: PRM base virtual address
  296. *
  297. * XXX Will be replaced when the PRM/CM drivers are completed.
  298. */
  299. void __init omap2_set_globals_prm(void __iomem *prm)
  300. {
  301. prm_base.va = prm;
  302. }
  303. /**
  304. * prm_read_reset_sources - return the sources of the SoC's last reset
  305. *
  306. * Return a u32 bitmask representing the reset sources that caused the
  307. * SoC to reset. The low-level per-SoC functions called by this
  308. * function remap the SoC-specific reset source bits into an
  309. * OMAP-common set of reset source bits, defined in
  310. * arch/arm/mach-omap2/prm.h. Returns the standardized reset source
  311. * u32 bitmask from the hardware upon success, or returns (1 <<
  312. * OMAP_UNKNOWN_RST_SRC_ID_SHIFT) if no low-level read_reset_sources()
  313. * function was registered.
  314. */
  315. u32 prm_read_reset_sources(void)
  316. {
  317. u32 ret = 1 << OMAP_UNKNOWN_RST_SRC_ID_SHIFT;
  318. if (prm_ll_data->read_reset_sources)
  319. ret = prm_ll_data->read_reset_sources();
  320. else
  321. WARN_ONCE(1, "prm: %s: no mapping function defined for reset sources\n", __func__);
  322. return ret;
  323. }
  324. /**
  325. * prm_was_any_context_lost_old - was device context lost? (old API)
  326. * @part: PRM partition ID (e.g., OMAP4430_PRM_PARTITION)
  327. * @inst: PRM instance offset (e.g., OMAP4430_PRM_MPU_INST)
  328. * @idx: CONTEXT register offset
  329. *
  330. * Return 1 if any bits were set in the *_CONTEXT_* register
  331. * identified by (@part, @inst, @idx), which means that some context
  332. * was lost for that module; otherwise, return 0. XXX Deprecated;
  333. * callers need to use a less-SoC-dependent way to identify hardware
  334. * IP blocks.
  335. */
  336. bool prm_was_any_context_lost_old(u8 part, s16 inst, u16 idx)
  337. {
  338. bool ret = true;
  339. if (prm_ll_data->was_any_context_lost_old)
  340. ret = prm_ll_data->was_any_context_lost_old(part, inst, idx);
  341. else
  342. WARN_ONCE(1, "prm: %s: no mapping function defined\n",
  343. __func__);
  344. return ret;
  345. }
  346. /**
  347. * prm_clear_context_lost_flags_old - clear context loss flags (old API)
  348. * @part: PRM partition ID (e.g., OMAP4430_PRM_PARTITION)
  349. * @inst: PRM instance offset (e.g., OMAP4430_PRM_MPU_INST)
  350. * @idx: CONTEXT register offset
  351. *
  352. * Clear hardware context loss bits for the module identified by
  353. * (@part, @inst, @idx). No return value. XXX Deprecated; callers
  354. * need to use a less-SoC-dependent way to identify hardware IP
  355. * blocks.
  356. */
  357. void prm_clear_context_loss_flags_old(u8 part, s16 inst, u16 idx)
  358. {
  359. if (prm_ll_data->clear_context_loss_flags_old)
  360. prm_ll_data->clear_context_loss_flags_old(part, inst, idx);
  361. else
  362. WARN_ONCE(1, "prm: %s: no mapping function defined\n",
  363. __func__);
  364. }
  365. /**
  366. * omap_prm_assert_hardreset - assert hardreset for an IP block
  367. * @shift: register bit shift corresponding to the reset line
  368. * @part: PRM partition
  369. * @prm_mod: PRM submodule base or instance offset
  370. * @offset: register offset
  371. *
  372. * Asserts a hardware reset line for an IP block.
  373. */
  374. int omap_prm_assert_hardreset(u8 shift, u8 part, s16 prm_mod, u16 offset)
  375. {
  376. if (!prm_ll_data->assert_hardreset) {
  377. WARN_ONCE(1, "prm: %s: no mapping function defined\n",
  378. __func__);
  379. return -EINVAL;
  380. }
  381. return prm_ll_data->assert_hardreset(shift, part, prm_mod, offset);
  382. }
  383. /**
  384. * omap_prm_deassert_hardreset - deassert hardreset for an IP block
  385. * @shift: register bit shift corresponding to the reset line
  386. * @st_shift: reset status bit shift corresponding to the reset line
  387. * @part: PRM partition
  388. * @prm_mod: PRM submodule base or instance offset
  389. * @offset: register offset
  390. * @st_offset: status register offset
  391. *
  392. * Deasserts a hardware reset line for an IP block.
  393. */
  394. int omap_prm_deassert_hardreset(u8 shift, u8 st_shift, u8 part, s16 prm_mod,
  395. u16 offset, u16 st_offset)
  396. {
  397. if (!prm_ll_data->deassert_hardreset) {
  398. WARN_ONCE(1, "prm: %s: no mapping function defined\n",
  399. __func__);
  400. return -EINVAL;
  401. }
  402. return prm_ll_data->deassert_hardreset(shift, st_shift, part, prm_mod,
  403. offset, st_offset);
  404. }
  405. /**
  406. * omap_prm_is_hardreset_asserted - check the hardreset status for an IP block
  407. * @shift: register bit shift corresponding to the reset line
  408. * @part: PRM partition
  409. * @prm_mod: PRM submodule base or instance offset
  410. * @offset: register offset
  411. *
  412. * Checks if a hardware reset line for an IP block is enabled or not.
  413. */
  414. int omap_prm_is_hardreset_asserted(u8 shift, u8 part, s16 prm_mod, u16 offset)
  415. {
  416. if (!prm_ll_data->is_hardreset_asserted) {
  417. WARN_ONCE(1, "prm: %s: no mapping function defined\n",
  418. __func__);
  419. return -EINVAL;
  420. }
  421. return prm_ll_data->is_hardreset_asserted(shift, part, prm_mod, offset);
  422. }
  423. /**
  424. * omap_prm_reconfigure_io_chain - clear latches and reconfigure I/O chain
  425. *
  426. * Clear any previously-latched I/O wakeup events and ensure that the
  427. * I/O wakeup gates are aligned with the current mux settings.
  428. * Calls SoC specific I/O chain reconfigure function if available,
  429. * otherwise does nothing.
  430. */
  431. void omap_prm_reconfigure_io_chain(void)
  432. {
  433. if (!prcm_irq_setup || !prcm_irq_setup->reconfigure_io_chain)
  434. return;
  435. prcm_irq_setup->reconfigure_io_chain();
  436. }
  437. /**
  438. * omap_prm_reset_system - trigger global SW reset
  439. *
  440. * Triggers SoC specific global warm reset to reboot the device.
  441. */
  442. void omap_prm_reset_system(void)
  443. {
  444. if (!prm_ll_data->reset_system) {
  445. WARN_ONCE(1, "prm: %s: no mapping function defined\n",
  446. __func__);
  447. return;
  448. }
  449. prm_ll_data->reset_system();
  450. while (1) {
  451. cpu_relax();
  452. wfe();
  453. }
  454. }
  455. /**
  456. * omap_prm_clear_mod_irqs - clear wake-up events from PRCM interrupt
  457. * @module: PRM module to clear wakeups from
  458. * @regs: register to clear
  459. * @wkst_mask: wkst bits to clear
  460. *
  461. * Clears any wakeup events for the module and register set defined.
  462. * Uses SoC specific implementation to do the actual wakeup status
  463. * clearing.
  464. */
  465. int omap_prm_clear_mod_irqs(s16 module, u8 regs, u32 wkst_mask)
  466. {
  467. if (!prm_ll_data->clear_mod_irqs) {
  468. WARN_ONCE(1, "prm: %s: no mapping function defined\n",
  469. __func__);
  470. return -EINVAL;
  471. }
  472. return prm_ll_data->clear_mod_irqs(module, regs, wkst_mask);
  473. }
  474. /**
  475. * omap_prm_vp_check_txdone - check voltage processor TX done status
  476. *
  477. * Checks if voltage processor transmission has been completed.
  478. * Returns non-zero if a transmission has completed, 0 otherwise.
  479. */
  480. u32 omap_prm_vp_check_txdone(u8 vp_id)
  481. {
  482. if (!prm_ll_data->vp_check_txdone) {
  483. WARN_ONCE(1, "prm: %s: no mapping function defined\n",
  484. __func__);
  485. return 0;
  486. }
  487. return prm_ll_data->vp_check_txdone(vp_id);
  488. }
  489. /**
  490. * omap_prm_vp_clear_txdone - clears voltage processor TX done status
  491. *
  492. * Clears the status bit for completed voltage processor transmission
  493. * returned by prm_vp_check_txdone.
  494. */
  495. void omap_prm_vp_clear_txdone(u8 vp_id)
  496. {
  497. if (!prm_ll_data->vp_clear_txdone) {
  498. WARN_ONCE(1, "prm: %s: no mapping function defined\n",
  499. __func__);
  500. return;
  501. }
  502. prm_ll_data->vp_clear_txdone(vp_id);
  503. }
  504. /**
  505. * prm_register - register per-SoC low-level data with the PRM
  506. * @pld: low-level per-SoC OMAP PRM data & function pointers to register
  507. *
  508. * Register per-SoC low-level OMAP PRM data and function pointers with
  509. * the OMAP PRM common interface. The caller must keep the data
  510. * pointed to by @pld valid until it calls prm_unregister() and
  511. * it returns successfully. Returns 0 upon success, -EINVAL if @pld
  512. * is NULL, or -EEXIST if prm_register() has already been called
  513. * without an intervening prm_unregister().
  514. */
  515. int prm_register(struct prm_ll_data *pld)
  516. {
  517. if (!pld)
  518. return -EINVAL;
  519. if (prm_ll_data != &null_prm_ll_data)
  520. return -EEXIST;
  521. prm_ll_data = pld;
  522. return 0;
  523. }
  524. /**
  525. * prm_unregister - unregister per-SoC low-level data & function pointers
  526. * @pld: low-level per-SoC OMAP PRM data & function pointers to unregister
  527. *
  528. * Unregister per-SoC low-level OMAP PRM data and function pointers
  529. * that were previously registered with prm_register(). The
  530. * caller may not destroy any of the data pointed to by @pld until
  531. * this function returns successfully. Returns 0 upon success, or
  532. * -EINVAL if @pld is NULL or if @pld does not match the struct
  533. * prm_ll_data * previously registered by prm_register().
  534. */
  535. int prm_unregister(struct prm_ll_data *pld)
  536. {
  537. if (!pld || prm_ll_data != pld)
  538. return -EINVAL;
  539. prm_ll_data = &null_prm_ll_data;
  540. return 0;
  541. }
  542. #ifdef CONFIG_ARCH_OMAP2
  543. static struct omap_prcm_init_data omap2_prm_data __initdata = {
  544. .index = TI_CLKM_PRM,
  545. .init = omap2xxx_prm_init,
  546. };
  547. #endif
  548. #ifdef CONFIG_ARCH_OMAP3
  549. static struct omap_prcm_init_data omap3_prm_data __initdata = {
  550. .index = TI_CLKM_PRM,
  551. .init = omap3xxx_prm_init,
  552. /*
  553. * IVA2 offset is a negative value, must offset the prm_base
  554. * address by this to get it to positive
  555. */
  556. .offset = -OMAP3430_IVA2_MOD,
  557. };
  558. #endif
  559. #if defined(CONFIG_SOC_AM33XX) || defined(CONFIG_SOC_TI81XX)
  560. static struct omap_prcm_init_data am3_prm_data __initdata = {
  561. .index = TI_CLKM_PRM,
  562. .init = am33xx_prm_init,
  563. };
  564. #endif
  565. #ifdef CONFIG_SOC_TI81XX
  566. static struct omap_prcm_init_data dm814_pllss_data __initdata = {
  567. .index = TI_CLKM_PLLSS,
  568. .init = am33xx_prm_init,
  569. };
  570. #endif
  571. #ifdef CONFIG_ARCH_OMAP4
  572. static struct omap_prcm_init_data omap4_prm_data __initdata = {
  573. .index = TI_CLKM_PRM,
  574. .init = omap44xx_prm_init,
  575. .device_inst_offset = OMAP4430_PRM_DEVICE_INST,
  576. .flags = PRM_HAS_IO_WAKEUP | PRM_HAS_VOLTAGE,
  577. };
  578. #endif
  579. #ifdef CONFIG_SOC_OMAP5
  580. static struct omap_prcm_init_data omap5_prm_data __initdata = {
  581. .index = TI_CLKM_PRM,
  582. .init = omap44xx_prm_init,
  583. .device_inst_offset = OMAP54XX_PRM_DEVICE_INST,
  584. .flags = PRM_HAS_IO_WAKEUP | PRM_HAS_VOLTAGE,
  585. };
  586. #endif
  587. #ifdef CONFIG_SOC_DRA7XX
  588. static struct omap_prcm_init_data dra7_prm_data __initdata = {
  589. .index = TI_CLKM_PRM,
  590. .init = omap44xx_prm_init,
  591. .device_inst_offset = DRA7XX_PRM_DEVICE_INST,
  592. .flags = PRM_HAS_IO_WAKEUP,
  593. };
  594. #endif
  595. #ifdef CONFIG_SOC_AM43XX
  596. static struct omap_prcm_init_data am4_prm_data __initdata = {
  597. .index = TI_CLKM_PRM,
  598. .init = omap44xx_prm_init,
  599. .device_inst_offset = AM43XX_PRM_DEVICE_INST,
  600. .flags = PRM_HAS_IO_WAKEUP,
  601. };
  602. #endif
  603. #if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5)
  604. static struct omap_prcm_init_data scrm_data __initdata = {
  605. .index = TI_CLKM_SCRM,
  606. };
  607. #endif
  608. static const struct of_device_id omap_prcm_dt_match_table[] __initconst = {
  609. #ifdef CONFIG_SOC_AM33XX
  610. { .compatible = "ti,am3-prcm", .data = &am3_prm_data },
  611. #endif
  612. #ifdef CONFIG_SOC_AM43XX
  613. { .compatible = "ti,am4-prcm", .data = &am4_prm_data },
  614. #endif
  615. #ifdef CONFIG_SOC_TI81XX
  616. { .compatible = "ti,dm814-prcm", .data = &am3_prm_data },
  617. { .compatible = "ti,dm814-pllss", .data = &dm814_pllss_data },
  618. { .compatible = "ti,dm816-prcm", .data = &am3_prm_data },
  619. #endif
  620. #ifdef CONFIG_ARCH_OMAP2
  621. { .compatible = "ti,omap2-prcm", .data = &omap2_prm_data },
  622. #endif
  623. #ifdef CONFIG_ARCH_OMAP3
  624. { .compatible = "ti,omap3-prm", .data = &omap3_prm_data },
  625. #endif
  626. #ifdef CONFIG_ARCH_OMAP4
  627. { .compatible = "ti,omap4-prm", .data = &omap4_prm_data },
  628. { .compatible = "ti,omap4-scrm", .data = &scrm_data },
  629. #endif
  630. #ifdef CONFIG_SOC_OMAP5
  631. { .compatible = "ti,omap5-prm", .data = &omap5_prm_data },
  632. { .compatible = "ti,omap5-scrm", .data = &scrm_data },
  633. #endif
  634. #ifdef CONFIG_SOC_DRA7XX
  635. { .compatible = "ti,dra7-prm", .data = &dra7_prm_data },
  636. #endif
  637. { }
  638. };
  639. /**
  640. * omap2_prm_base_init - initialize iomappings for the PRM driver
  641. *
  642. * Detects and initializes the iomappings for the PRM driver, based
  643. * on the DT data. Returns 0 in success, negative error value
  644. * otherwise.
  645. */
  646. int __init omap2_prm_base_init(void)
  647. {
  648. struct device_node *np;
  649. const struct of_device_id *match;
  650. struct omap_prcm_init_data *data;
  651. struct resource res;
  652. int ret;
  653. for_each_matching_node_and_match(np, omap_prcm_dt_match_table, &match) {
  654. data = (struct omap_prcm_init_data *)match->data;
  655. ret = of_address_to_resource(np, 0, &res);
  656. if (ret)
  657. return ret;
  658. data->mem = ioremap(res.start, resource_size(&res));
  659. if (data->index == TI_CLKM_PRM) {
  660. prm_base.va = data->mem + data->offset;
  661. prm_base.pa = res.start + data->offset;
  662. }
  663. data->np = np;
  664. if (data->init)
  665. data->init(data);
  666. }
  667. return 0;
  668. }
  669. int __init omap2_prcm_base_init(void)
  670. {
  671. int ret;
  672. ret = omap2_prm_base_init();
  673. if (ret)
  674. return ret;
  675. return omap2_cm_base_init();
  676. }
  677. /**
  678. * omap_prcm_init - low level init for the PRCM drivers
  679. *
  680. * Initializes the low level clock infrastructure for PRCM drivers.
  681. * Returns 0 in success, negative error value in failure.
  682. */
  683. int __init omap_prcm_init(void)
  684. {
  685. struct device_node *np;
  686. const struct of_device_id *match;
  687. const struct omap_prcm_init_data *data;
  688. int ret;
  689. for_each_matching_node_and_match(np, omap_prcm_dt_match_table, &match) {
  690. data = match->data;
  691. ret = omap2_clk_provider_init(np, data->index, NULL, data->mem);
  692. if (ret)
  693. return ret;
  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);