cm_common.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * OMAP2+ common Clock Management (CM) IP block functions
  3. *
  4. * Copyright (C) 2012 Texas Instruments, Inc.
  5. * Paul Walmsley
  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. * XXX This code should eventually be moved to a CM driver.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/errno.h>
  16. #include "cm2xxx.h"
  17. #include "cm3xxx.h"
  18. #include "cm44xx.h"
  19. #include "common.h"
  20. /*
  21. * cm_ll_data: function pointers to SoC-specific implementations of
  22. * common CM functions
  23. */
  24. static struct cm_ll_data null_cm_ll_data;
  25. static struct cm_ll_data *cm_ll_data = &null_cm_ll_data;
  26. /* cm_base: base virtual address of the CM IP block */
  27. void __iomem *cm_base;
  28. /* cm2_base: base virtual address of the CM2 IP block (OMAP44xx only) */
  29. void __iomem *cm2_base;
  30. /**
  31. * omap2_set_globals_cm - set the CM/CM2 base addresses (for early use)
  32. * @cm: CM base virtual address
  33. * @cm2: CM2 base virtual address (if present on the booted SoC)
  34. *
  35. * XXX Will be replaced when the PRM/CM drivers are completed.
  36. */
  37. void __init omap2_set_globals_cm(void __iomem *cm, void __iomem *cm2)
  38. {
  39. cm_base = cm;
  40. cm2_base = cm2;
  41. }
  42. /**
  43. * cm_split_idlest_reg - split CM_IDLEST reg addr into its components
  44. * @idlest_reg: CM_IDLEST* virtual address
  45. * @prcm_inst: pointer to an s16 to return the PRCM instance offset
  46. * @idlest_reg_id: pointer to a u8 to return the CM_IDLESTx register ID
  47. *
  48. * Given an absolute CM_IDLEST register address @idlest_reg, passes
  49. * the PRCM instance offset and IDLEST register ID back to the caller
  50. * via the @prcm_inst and @idlest_reg_id. Returns -EINVAL upon error,
  51. * or 0 upon success. XXX This function is only needed until absolute
  52. * register addresses are removed from the OMAP struct clk records.
  53. */
  54. int cm_split_idlest_reg(void __iomem *idlest_reg, s16 *prcm_inst,
  55. u8 *idlest_reg_id)
  56. {
  57. if (!cm_ll_data->split_idlest_reg) {
  58. WARN_ONCE(1, "cm: %s: no low-level function defined\n",
  59. __func__);
  60. return -EINVAL;
  61. }
  62. return cm_ll_data->split_idlest_reg(idlest_reg, prcm_inst,
  63. idlest_reg_id);
  64. }
  65. /**
  66. * cm_wait_module_ready - wait for a module to leave idle or standby
  67. * @prcm_mod: PRCM module offset
  68. * @idlest_id: CM_IDLESTx register ID (i.e., x = 1, 2, 3)
  69. * @idlest_shift: shift of the bit in the CM_IDLEST* register to check
  70. *
  71. * Wait for the PRCM to indicate that the module identified by
  72. * (@prcm_mod, @idlest_id, @idlest_shift) is clocked. Return 0 upon
  73. * success, -EBUSY if the module doesn't enable in time, or -EINVAL if
  74. * no per-SoC wait_module_ready() function pointer has been registered
  75. * or if the idlest register is unknown on the SoC.
  76. */
  77. int cm_wait_module_ready(s16 prcm_mod, u8 idlest_id, u8 idlest_shift)
  78. {
  79. if (!cm_ll_data->wait_module_ready) {
  80. WARN_ONCE(1, "cm: %s: no low-level function defined\n",
  81. __func__);
  82. return -EINVAL;
  83. }
  84. return cm_ll_data->wait_module_ready(prcm_mod, idlest_id, idlest_shift);
  85. }
  86. /**
  87. * cm_register - register per-SoC low-level data with the CM
  88. * @cld: low-level per-SoC OMAP CM data & function pointers to register
  89. *
  90. * Register per-SoC low-level OMAP CM data and function pointers with
  91. * the OMAP CM common interface. The caller must keep the data
  92. * pointed to by @cld valid until it calls cm_unregister() and
  93. * it returns successfully. Returns 0 upon success, -EINVAL if @cld
  94. * is NULL, or -EEXIST if cm_register() has already been called
  95. * without an intervening cm_unregister().
  96. */
  97. int cm_register(struct cm_ll_data *cld)
  98. {
  99. if (!cld)
  100. return -EINVAL;
  101. if (cm_ll_data != &null_cm_ll_data)
  102. return -EEXIST;
  103. cm_ll_data = cld;
  104. return 0;
  105. }
  106. /**
  107. * cm_unregister - unregister per-SoC low-level data & function pointers
  108. * @cld: low-level per-SoC OMAP CM data & function pointers to unregister
  109. *
  110. * Unregister per-SoC low-level OMAP CM data and function pointers
  111. * that were previously registered with cm_register(). The
  112. * caller may not destroy any of the data pointed to by @cld until
  113. * this function returns successfully. Returns 0 upon success, or
  114. * -EINVAL if @cld is NULL or if @cld does not match the struct
  115. * cm_ll_data * previously registered by cm_register().
  116. */
  117. int cm_unregister(struct cm_ll_data *cld)
  118. {
  119. if (!cld || cm_ll_data != cld)
  120. return -EINVAL;
  121. cm_ll_data = &null_cm_ll_data;
  122. return 0;
  123. }