cm_common.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * OMAP2+ common Clock Management (CM) IP block functions
  3. *
  4. * Copyright (C) 2012 Texas Instruments, Inc.
  5. * Paul Walmsley <paul@pwsan.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. * XXX This code should eventually be moved to a CM driver.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include "cm2xxx.h"
  16. #include "cm3xxx.h"
  17. #include "cm44xx.h"
  18. /*
  19. * cm_ll_data: function pointers to SoC-specific implementations of
  20. * common CM functions
  21. */
  22. static struct cm_ll_data null_cm_ll_data;
  23. static struct cm_ll_data *cm_ll_data = &null_cm_ll_data;
  24. /**
  25. * cm_register - register per-SoC low-level data with the CM
  26. * @cld: low-level per-SoC OMAP CM data & function pointers to register
  27. *
  28. * Register per-SoC low-level OMAP CM data and function pointers with
  29. * the OMAP CM common interface. The caller must keep the data
  30. * pointed to by @cld valid until it calls cm_unregister() and
  31. * it returns successfully. Returns 0 upon success, -EINVAL if @cld
  32. * is NULL, or -EEXIST if cm_register() has already been called
  33. * without an intervening cm_unregister().
  34. */
  35. int cm_register(struct cm_ll_data *cld)
  36. {
  37. if (!cld)
  38. return -EINVAL;
  39. if (cm_ll_data != &null_cm_ll_data)
  40. return -EEXIST;
  41. cm_ll_data = cld;
  42. return 0;
  43. }
  44. /**
  45. * cm_unregister - unregister per-SoC low-level data & function pointers
  46. * @cld: low-level per-SoC OMAP CM data & function pointers to unregister
  47. *
  48. * Unregister per-SoC low-level OMAP CM data and function pointers
  49. * that were previously registered with cm_register(). The
  50. * caller may not destroy any of the data pointed to by @cld until
  51. * this function returns successfully. Returns 0 upon success, or
  52. * -EINVAL if @cld is NULL or if @cld does not match the struct
  53. * cm_ll_data * previously registered by cm_register().
  54. */
  55. int cm_unregister(struct cm_ll_data *cld)
  56. {
  57. if (!cld || cm_ll_data != cld)
  58. return -EINVAL;
  59. cm_ll_data = &null_cm_ll_data;
  60. return 0;
  61. }